Friday, March 9, 2018

PL/SQL - BULK COLLECT INTO,SELECT MULTIPLE ROWS

DECLARE
  TYPE nt_fName IS TABLE OF VARCHAR2 (20);
  TYPE nt_lName IS TABLE OF VARCHAR2 (20);

  fname nt_fName;
  lName nt_lName;
 BEGIN
  SELECT first_name, last_name
   BULK COLLECT INTO fName, lName
  FROM employees;

   --Print values from the collection--
  FOR idx IN 1..fName.COUNT
  LOOP
   DBMS_OUTPUT.PUT_LINE (idx||' - '||fName (idx) ||' '||lName (idx));
  END LOOP;
 END;

USES :
  • BULK COLLECT: SELECT statements that retrieve multiple rows with a single fetch, improving the speed of data retrieval
  • FORALL: INSERTs, UPDATEs, and DELETEs that use collections to change multiple rows of data very quickly

No comments:

Post a Comment