[Solved] Can somebody explain dbms_sql.number_table [closed]


Better to understand DBMS_SQL itself to some extent, before understanding NUMBER_TABLE.

( I do this for My Learning!)

NUMBER_TABLE

is Actually,

TYPE number_table IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;

So, only numbers are allowed!

FlowChart on How DBMS_SQL Works! :

Your interested area comes in bind variable box


--                    | open_cursor |
--                      -----------
--                           |
--                           |
--                           v
--                         -----
--          ------------>| parse |
--          |              -----
--          |                |
--          |                | ---------
--          |                v          |
--          |           --------------  |
--          |-------->| bind_variable | |
--          |     ^     -------------   |
--          |     |           |         |
--          |      -----------|         |
--          |                 |<--------
--          |                 v
--          |               query?---------- yes ---------
--          |                 |                           |
--          |                no                           |
--          |                 |                           |
--          |                 v                           v
--          |              -------                  -------------
--          |----------->| execute |            ->| define_column |
--          |              -------             |    -------------
--          |                 |------------    |          |
--          |                 |            |    ----------|
--          |                 v            |              v
--          |           --------------     |           -------
--          |       ->| variable_value |   |  ------>| execute |
--          |      |    --------------     | |         -------
--          |      |          |            | |            |
--          |       ----------|            | |            |
--          |                 |            | |            v
--          |                 |            | |        ----------
--          |                 |<-----------  |----->| fetch_rows |
--          |                 |              |        ----------
--          |                 |              |            |
--          |                 |              |            v
--          |                 |              |  -----------------
--          |                 |              | | column_value    |
--          |                 |              | | variable_value  |
--          |                 |              |  -----------------
--          |                 |              |            |
--          |                 |<--------------------------
--          |                 |
--           -----------------|
--                            |
--                            v
--                       ------------
--                     | close_cursor |
--      

             ------------

Example:
In a DELETE statement, for example, you could bind in an array in the WHERE clause and have the statement be run for each element in the array:

DECLARE
  stmt VARCHAR2(200);
  dept_no_array DBMS_SQL.NUMBER_TABLE;
  c NUMBER;
  dummy NUMBER;
begin
  dept_no_array(1) := 10; dept_no_array(2) := 20; /* Put some values into the array */
  dept_no_array(3) := 30; dept_no_array(4) := 40;
  dept_no_array(5) := 30; dept_no_array(6) := 40;
  stmt := 'delete from emp where deptno = :dept_array'; /* A Dynamic SQL String with a bind variable */
  c := DBMS_SQL.OPEN_CURSOR; /* Open a Cursor! */
  DBMS_SQL.PARSE(c, stmt, DBMS_SQL.NATIVE); /* Parse the Dynamic SQL , making it happen on the native database to which is connected! */

  DBMS_SQL.BIND_ARRAY(c, ':dept_array', dept_no_array, 1, 4);
  /* Bind only elements 1 through 4 to the cursor Happens 4 times */

  dummy := DBMS_SQL.EXECUTE(c);
  /* Execute the Query, and return number of rows deleted! */

  DBMS_SQL.CLOSE_CURSOR(c); 

  EXCEPTION WHEN OTHERS THEN
    IF DBMS_SQL.IS_OPEN(c) THEN
      DBMS_SQL.CLOSE_CURSOR(c);
    END IF;
    RAISE;
END;
/ 

P.S. Pure rip-off, with some more commments ,from Oracle

0

solved Can somebody explain dbms_sql.number_table [closed]