You are on page 1of 16

Data Blocks on Different Data Sources

Objectives

• Base a data block on FROM clause sub query


• Base a data block on a stored procedure
• Return a REF cursor from a stored procedure
• Return a table of records from a stored procedure
• Select the appropriate data source for a
data block
Data source Types
Query DML

Table Table
FROM clause A/C No:
query A/C No:
Branch:
Stored Branch: Stored
procedure Balance: procedure
Balance:
Transactional Transactional
trigger trigger
Basing Data Block on a From Clause Query

SELECT deptno, Total_salary


FROM (SELECT deptno,
sum(sal) Total_salary
FROM emp
GROUP BY deptno)
WHERE total_salary>=8000
Why Form Clause Query?

Perform joins, lookups, and calculations on the server (thus avoiding


multiple network trips) without having to define a view every time.

• Improves developer productivity


• Reduces the burden on the DBA
• Improves performance
Basing a Data block on Stored Procedure for
Query Operation
Return data by way of:
• REF cursor
• A Table of records

Querying
Data Block
Empno Ename Job
7369 SMITH CLERK
7499 ALLEN SALESMAN Emp No
Procedure 7521 WARD SALESMAN
Name
7566 JONES ANAGER
7654 MARTIN SALESMAN Job
7698 BLAKE MANAGER
7782 CLARK MANAGER
Basing a Data block on Stored Procedure for
DML Operations
• Return data by way of a table of records

Updating
Data Block
Empno Ename Job
7369 SMITH CLERK
7499 ALLEN SALESMAN Emp No
Procedure 7521 WARD SALESMAN
Name
7566 JONES ANAGER
7654 MARTIN SALESMAN Job
7698 BLAKE MANAGER
7782 CLARK MANAGER
REF Cursor Procedure for Query

Define a package specification with:


• The objects returned by the REF cursor
• The REF cursor
• The query procedure: Data returned
through the first argument (IN OUT)
Define a package body: Write the code for
the query procedure
Table of Records Procedure for Query

Define a package specification with:


• The structure of each row of the table
• The table of records
• The query procedure: Data returned through the first argument (IN
OUT)
Define a package body: Write the code for the
query procedure
Table of Records Procedure for DML

Define a package specification with:


• The structure of each row of the table
• The table of records
• A procedure to insert rows
• A procedure to update rows
• A procedure to delete rows
• A procedure to lock rows
Define a package body by writing the code for
each DML procedure
Returning a Ref Cursor
SQL
SELECT
Procedure
Query 1 2 REF cursor

REF cursor
3
Emp No

Fetched rows Name


Job
4
Returning Table of Records
Any
PL/SQL
Code
Procedure
Query 1 2 Cursor

Cursor
3
Emp No

Table of Records Name


Job
4
Data Block Wizard

Use the Data Block Wizard to specify the following:


• Data source type
• Query procedure
• Insert procedure
• Update procedure
• Delete procedure
• Lock procedure
Data Source Guidelines

Base a data block on a FROM clause query to:


• Create a “dynamic” view
Base a data block on a stored procedure to:
• Increase control and security
• Specify a SELECT statement at run time
• Query or update multiple tables
• Perform complex computations
• Perform validation and DML on the
server side
Data Source Guidelines

Data Source Query DML

Table YES YES

View YES YES

FROM Clause YES NO

Proc-Ref Cur YES NO

Proc-Table Rec YES YES

Transac. Trigger YES YES


Summary

• Base data blocks on new data sources:


– FROM clause query (query only)
– Stored procedure (query and DML)
• Exploit features of stored procedures :
– REF cursors
limited to a single SELECT statement
– Table of records
can be a complex procedure

You might also like