12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Utilizing the Main Features of PL/<strong>SQL</strong>determines its position in the collection. When declaring collections, you use a TYPEdefinition.To reference an element, use subscript notation with parentheses, as shown inExample 7–24.Example 7–24Using a PL/<strong>SQL</strong> Collection TypeDECLARE -- declare variablesTYPE jobids_array IS VARRAY(12) OF VARCHAR2(10); -- declare VARRAYjobids jobids_array; -- declare a variable of type jobids_arrayhowmany NUMBER; -- declare a variable to hold employee countBEGIN-- initialize the arrary with some job Id valuesjobids := jobids_array('AC_ACCOUNT', 'AC_MGR', 'AD_ASST', 'AD_PRES', 'AD_VP','FI_ACCOUNT', 'FI_MGR', 'HR_REP', 'IT_PROG', 'SH_CLERK','ST_CLERK', 'ST_MAN');FOR i IN jobids.FIRST..jobids.LAST LOOP -- loop through all the varray values-- determine the number of employees for each job Id in the arraySELECT COUNT(*) INTO howmany FROM employees WHERE job_id = jobids(i);DBMS_OUTPUT.PUT_LINE ( 'Job Id: ' || jobids(i) ||' Number of employees: ' || TO_CHAR(howmany));END LOOP;END;/Collections can be passed as parameters, so that subprograms can process arbitrarynumbers of elements.You can use collections to move data into and out of databasetables using high-performance language features known as bulk <strong>SQL</strong>.See Also:■PL/<strong>SQL</strong> User's Guide and Reference for information on PL/<strong>SQL</strong>collections.7.3.13.3 Using RecordsRecords are composite data structures whose fields can have different data types. Youcan use records to hold related items and pass them to subprograms with a singleparameter. When declaring records, you use the TYPE definition.Example 7–25 shows how are records are declared.Example 7–25Declaring a Record TypeDECLARE -- declare RECORD type variablesTYPE timerec IS RECORD (hours SMALLINT, minutes SMALLINT);TYPE meetin_typ IS RECORD (date_held DATE,duration timerec, -- nested recordlocation VARCHAR2(20),purpose VARCHAR2(50));BEGIN-- NULL does nothing but allows unit to be compiled and testedNULL;END;/You can use the %ROWTYPE attribute to declare a record that represents a row in a tableor a row from a query result set, without specifying the names and types for the fields.7-18 <strong>SQL</strong> <strong>Developer</strong> Online Help

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!