Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
plsql_static_dynamic_sql [2020/06/04 15:35] – andonovj | plsql_static_dynamic_sql [2020/06/04 15:41] (current) – [Differences] andonovj | ||
---|---|---|---|
Line 162: | Line 162: | ||
</ | </ | ||
- | ====Describe Unknown No of Column==== | + | ====Describe Unknown No. of Columns==== |
One advantage of the DBMS_SQL over the Native Dynamic SQL is the ability to work with: | One advantage of the DBMS_SQL over the Native Dynamic SQL is the ability to work with: | ||
Line 170: | Line 170: | ||
So let's see how we can work with unknown number of columns. Oracle provided couple APIs for that: | So let's see how we can work with unknown number of columns. Oracle provided couple APIs for that: | ||
- | * DBMS_SQL.DESC_COLUMNS(2)(3) | + | * DBMS_SQL.DESC_COLUMNS(x) |
* DBMS_SQL.DESC_TAB | * DBMS_SQL.DESC_TAB | ||
* DBMS_SQL.DESC_REC | * DBMS_SQL.DESC_REC | ||
+ | X - being: ,2 or 3 | ||
Let's go through each of them. | Let's go through each of them. | ||
Line 179: | Line 180: | ||
It has the following syntax: | It has the following syntax: | ||
- | < | + | < |
- | | + | ( |
- | | + | c |
- | | + | col_cnt OUT INTEGER, <- Returns the count of the columns in that Cursor |
- | X - 1,2 or 3 (Different versions) | + | desc_t |
+ | ); | ||
< | < | ||
===DESC_TAB=== | ===DESC_TAB=== | ||
- | That array we saw above and it has the following structure: | + | That array which we saw above and it has the following structure: |
< | < | ||
TYPE desc_tab IS TABLE OF desc_rec(x) INDEX BY BINARY_INTEGER; | TYPE desc_tab IS TABLE OF desc_rec(x) INDEX BY BINARY_INTEGER; | ||
</ | </ | ||
+ | |||
+ | More info about this record, below: | ||
===DESC_REC=== | ===DESC_REC=== | ||
Line 222: | Line 226: | ||
</ | </ | ||
- | With the new tables, there is different | + | With the new versions, there is slightly |
Phew, gosh, that was a long walk, let's see example finally: | Phew, gosh, that was a long walk, let's see example finally: | ||
Line 295: | Line 299: | ||
* Used for: Dynamic Queries and Sorts (Queries which can change depending on the user's preferences) | * Used for: Dynamic Queries and Sorts (Queries which can change depending on the user's preferences) | ||
* DDL can be used, unlike Static SQL | * DDL can be used, unlike Static SQL | ||
+ | |||
+ | In general, you should use DBMS_SQL dynamic SQL, only when you don't know the number of columns or bind variables which will be used in a select, for every other occasion, use the Native Dynamic SQL. |