sql >> Database teknologi >  >> RDS >> Oracle

BULK COLLECT LIMIT i UDFØR STRAKS

Det ser ud til, at EXECUTE IMMEDIATE-syntaksen ikke tillader LIMIT i bulk collect-klausul

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/executeimmediate_statement.htm#CJACGJJG


bulk_collect_into_clause
http://docs.oracle .com/cd/E11882_01/appdev.112/e25519/returninginto_clause.htm#CJAIAGHJ

Du kan bruge en markør og FETCH .. LIMIT-kommando sammen med OPEN..FOR-kommandoen
på denne måde:

DECLARE
  ....
  cur sys_refcursor;
BEGIN
  v_query := 'SELECT level AS x FROM dual CONNECT BY LEVEL <=10';
  OPEN cur FOR v_query;
  LOOP
     FETCH cur BULK COLLECT INTO collection LIMIT 3;
     EXIT WHEN collection.COUNT = 0;

     /* Process data from `collection` */

  END LOOP;
  CLOSE cur;
END;

Eksempel:

DECLARE
  TYPE col_typ IS table of NUMBER;
  collection col_typ;
  v_query varchar2(3000); 
  cur sys_refcursor;
  i int := 0;
  x int;
BEGIN
  v_query := 'SELECT level AS x FROM dual CONNECT BY LEVEL <=10';

  OPEN cur FOR v_query;
  LOOP
     FETCH cur BULK COLLECT INTO collection LIMIT 3;
     EXIT WHEN collection.COUNT = 0;

     /* Process data from `collection` */
     i := i + 1;
     DBMS_OUTPUT.PUT_LINE('==== Batch nbr #' || i );
     FOR x IN 1 .. collection.COUNT LOOP
       DBMS_OUTPUT.PUT_LINE( collection( x ) );
     END LOOP;
  END LOOP;
  CLOSE cur;
END;
/

Resultat:

==== Batch nbr #1
1
2
3
==== Batch nbr #2
4
5
6
==== Batch nbr #3
7
8
9
==== Batch nbr #4
10


  1. Hvordan opretter man LEFT JOIN med SELECT underforespørgsel ved hjælp af QueryBuilder i Doctrine 2?

  2. Python Login Multi Solution

  3. MySQL-vælg med CONCAT-tilstand

  4. Emulering af en transaktionssikker SEKVENS i MySQL