Oracle SQL Developer
Oracle SQL Developer
Oracle SQL Developer
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Utilizing the Main Features of PL/<strong>SQL</strong>When using %ROWTYPE, the record type definition is implied and the TYPE keyword isnot necessary, as shown in Example 7–26.Example 7–26Using %ROWTYPE with a CursorDECLARE -- declare variablesCURSOR c1 ISSELECT * FROM employeesWHERE employee_id = 120; -- declare cursor-- declare record variable that represents a row fetched from the employees tableemployee_rec c1%ROWTYPE; -- declare variable with %ROWTYPE attributeBEGIN-- open the explicit cursor c1 and use it to fetch data into employee_recOPEN c1;FETCH c1 INTO employee_rec; -- retrieve recordDBMS_OUTPUT.PUT_LINE('Employee name: ' || employee_rec.last_name); -- displayEND;/See Also:■PL/<strong>SQL</strong> User's Guide and Reference for information on PL/<strong>SQL</strong>records.7.3.14 Processing Queries with PL/<strong>SQL</strong>Processing a <strong>SQL</strong> query with PL/<strong>SQL</strong> is like processing files with other languages.This process includes opening a file, reading the file contents, processing each line,then closing the file. In the same way, a PL/<strong>SQL</strong> program issues a query and processesthe rows from the result set as shown in Example 7–27.Example 7–27Processing Query Results in a LOOPBEGIN-- use values from SELECT for FOR LOOP processingFOR someone IN (SELECT * FROM employees WHERE employee_id < 120 )LOOPDBMS_OUTPUT.PUT_LINE('First name = ' || someone.first_name ||', Last name = ' || someone.last_name);END LOOP;END;/You can use a simple loop like the one shown here, or you can control the processprecisely by using individual statements to perform the query, retrieve data, and finishprocessing.7.3.15 Using Dynamic <strong>SQL</strong> in PL/<strong>SQL</strong>PL/<strong>SQL</strong> supports both dynamic and static <strong>SQL</strong>. Dynamic <strong>SQL</strong> enables you to build<strong>SQL</strong> statements dynamically at runtime while static <strong>SQL</strong> statements are known inadvance. You can create more general purpose, flexible applications by using dynamic<strong>SQL</strong> because the full text of a <strong>SQL</strong> statement may be unknown at compilation. Foradditional information about dynamic <strong>SQL</strong>, see <strong>Oracle</strong> Database Application <strong>Developer</strong>'sGuide - Fundamentals.To process most dynamic <strong>SQL</strong> statements, you use the EXECUTE IMMEDIATEstatement. To process a multi-row query (SELECT statement), you use the OPEN-FOR,FETCH, and CLOSE statements.PL/<strong>SQL</strong>: Usage Information 7-19