Skip to content

Commit

Permalink
Merge pull request #4832 from EnterpriseDB/docs/epas/v16-update-sql-t…
Browse files Browse the repository at this point in the history
…able

Added new subprograms to list of SQL subprograms
  • Loading branch information
nidhibhammar authored Sep 27, 2023
2 parents 7ab0f22 + d24d068 commit 168d411
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The `BIND_ARRAY` procedure binds a value or set of values to a variable in a cur

```sql
BIND_ARRAY (<c> IN NUMBER, <name> IN VARCHAR2,
<table_variable> IN { FLOAT | BLOB | |CLOB | VARCHAR2 | NUMBER | TIMESTAMP }
[,<index1> IN NUMBER, <index2> IN NUMBER)]);
<table_variable> IN { FLOAT_TABLE | BLOB_TABLE | CLOB_TABLE | VARCHAR2_TABLE | NUMBER_TABLE | TIMESTAMP_TABLE |
INTEGER_TABLE | ROWID_TABLE | TEXT_TABLE } [,<index1> IN NUMBER, <index2> IN NUMBER]);
```

## Parameters
Expand All @@ -24,23 +24,26 @@ BIND_ARRAY (<c> IN NUMBER, <name> IN VARCHAR2,

A local variable that is declared to be one of the following datatypes:

| Datatype | Description |
| Datatype | Description |
| ---------- | --------------- |
| <bflt_tab> | FLOAT_TABLE |
| <bl_tab> | BLOB_TABLE |
| <cl_tab> | CLOB_TABLE |
| <c_tab> | VARCHAR2_TABLE |
| <n_tab> | NUMBER_TABLE |
| <tms_tab> | TIMESTAMP_TABLE |
| <int_tab> | INTEGER_TABLE |
| <rid_tab> | ROWID_TABLE |
| <txt_tab> | TEXT_TABLE |


`index1`

Index for the table element that marks the lower bound of the range if you're binding a range. This value must be less than or equal to the value of `index2`. All elements between `index1` and `index2` are used in the bind.
Index for the table element that marks the lower bound of the range if you are binding a range. This value must be less than or equal to the value of `index2`. All elements between `index1` and `index2` are used in the bind. This is an optional parameter that can be used with three parameters or five parameters but not four.

`index2`

Index for the table element that marks the upper bound of the range.
Index for the table element that marks the upper bound of the range. This is an optional parameter that can be used with three parameters or five parameters but not four.


## Notes
Expand Down Expand Up @@ -77,12 +80,15 @@ BEGIN
END;
/

-- this will INSERT 3 rows in the table.
-- this inserts three rows using bind_array so verify them in the table.
SELECT * FROM tab_test;
col_int | col_charactervarying
---------+----------------------
10 | edb_user
11 | edb_user
12 | edb_user
-- For col_int we are passing bind_array with the size of 3 elements, and as col_charactervarying we are
-- passing bind_variable. So for all the insertions, we are using same bind_variable (edb_user).

(3 rows)
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The `BIND_VARIABLE` procedure associates a value with an `IN` or `IN OUT` bind v

```sql
BIND_VARIABLE(<c> NUMBER, <name> VARCHAR2,
<value> { BLOB | CLOB | DATE | FLOAT | INTEGER | NUMBER | TIMESTAMP | VARCHAR2 }
<value> { BLOB | CLOB | FLOAT | INTEGER | NUMBER | ROWID | TIMESTAMP | VARCHAR2 }
[, <out_value_size> NUMBER ])
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ BEGIN
DBMS_SQL.CLOSE_CURSOR(cur_id);
END;

Output:
col_long: Testing
value_length: 7

EDB-SPL Procedure successfully completed


-- Use positive offset
DECLARE
cur_id INTEGER;
Expand All @@ -86,4 +93,11 @@ BEGIN
DBMS_OUTPUT.PUT_LINE('value_length: ' || length);
DBMS_SQL.CLOSE_CURSOR(cur_id);
END;

Output:
col_long: DefineColumn
value_length: 12

EDB-SPL Procedure successfully completed

```
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ When you fetch rows, they are copied into DBMS_SQL buffers until you run a COLUM

```sql
DEFINE_ARRAY(<c> IN NUMBER, <position> IN NUMBER,
<table_variable> UN { CLOB | FLOAT | BLOB | NUMBER | VARCHAR2 | TIMESTAMP },
<cnt> IN NUMBER, <lower_bnd> IN NUMBER)
);
<table_variable> IN { FLOAT_TABLE | BLOB_TABLE | CLOB_TABLE | VARCHAR2_TABLE | NUMBER_TABLE | TIMESTAMP_TABLE |
INTEGER_TABLE | ROWID_TABLE | TEXT_TABLE }, <cnt> IN NUMBER, <lower_bnd> IN NUMBER);
```

## Parameters
Expand All @@ -27,14 +26,18 @@ Relative position of the column in the array being defined. The first column is

A datatype that can be any one of the following matching pairs:

| Datatype | Description |
| Datatype | Description |
| ---------- | --------------- |
| <cl_tab> | CLOB_TABLE |
| <bflt_tab> | FLOAT_TABLE |
| <bl_tab> | BLOB_TABLE |
| <n_tab> | NUMBER_TABLE |
| <cl_tab> | CLOB_TABLE |
| <c_tab> | VARCHAR2_TABLE |
| <n_tab> | NUMBER_TABLE |
| <tms_tab> | TIMESTAMP_TABLE |
| <int_tab> | INTEGER_TABLE |
| <rid_tab> | ROWID_TABLE |
| <txt_tab> | TEXT_TABLE |



`cnt`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ BEGIN
DBMS_SQL.CLOSE_CURSOR(cur_id);
END;

Output:
col_long: Testing
value_length: 7

EDB-SPL Procedure successfully completed

-- Use positive offset
DECLARE
cur_id INTEGER;
Expand All @@ -71,4 +77,11 @@ BEGIN
DBMS_OUTPUT.PUT_LINE('value_length: ' || length);
DBMS_SQL.CLOSE_CURSOR(cur_id);
END;

Output:
col_long: DefineColumn
value_length: 12

EDB-SPL Procedure successfully completed

```
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
title: "DESCRIBE_COLUMNS2"
---

The `DESCRIBE_COLUMNS2` procedure describes specified columns returned by a cursor. This procedure provides an alternative to 'DESCRIBE_COLUMN' and can be used for migration.
The `DESCRIBE_COLUMNS2` procedure describes specified columns returned by a cursor. This procedure provides an alternative to `DESCRIBE_COLUMN`.

```sql
DESCRIBE_COLUMNS2(<c> IN NUMBER, <col_cnt> OUT NUMBER, <desc_t> OUT
DESC_TAB);
DESCRIBE_COLUMNS2(<c> IN NUMBER, <col_cnt> OUT NUMBER, <desc_tab2> OUT
DESC_TAB2);
```

## Parameters
Expand All @@ -19,9 +19,9 @@ DESCRIBE_COLUMNS2(<c> IN NUMBER, <col_cnt> OUT NUMBER, <desc_t> OUT

The number of columns in the cursor result set.

`desc_tab`
`desc_tab2`

The table that contains a description of each column returned by the cursor. The descriptions are of type `DESC_REC` and contain the following values:
The table that contains a description of each column returned by the cursor. The descriptions are of type `DESC_REC2` and contain the following values:

| Column name | Type |
| --------------------- | --------------- |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
title: "DESCRIBE_COLUMNS3"
---

The `DESCRIBE_COLUMNS3` procedure describes specified columns returned by a cursor. This procedure provides an alternative to 'DESCRIBE_COLUMN' and can be used for migration.
The `DESCRIBE_COLUMNS3` procedure describes specified columns returned by a cursor. This procedure provides an alternative to `DESCRIBE_COLUMN`.


```sql
DESCRIBE_COLUMNS3(<c> IN NUMBER, <col_cnt> OUT NUMBER, <desc_t> OUT
DESC_TAB);
DESCRIBE_COLUMNS3(<c> IN NUMBER, <col_cnt> OUT NUMBER, <desc_tab3> OUT
DESC_TAB3);
```

## Parameters
Expand All @@ -19,23 +20,26 @@ DESCRIBE_COLUMNS3(<c> IN NUMBER, <col_cnt> OUT NUMBER, <desc_t> OUT

The number of columns in the cursor result set.

`desc_tab`
`desc_tab3`

The table that contains a description of each column returned by the cursor. The descriptions are of type `DESC_REC3` and contain the following values:

The table that contains a description of each column returned by the cursor. The descriptions are of type `DESC_REC` and contain the following values:
| Column name | Type |
| --------------------- | ----------------- |
| `col_type` | `INTEGER` |
| `col_max_len` | `INTEGER` |
| `col_name` | `VARCHAR2(128)` |
| `col_name_len` | `INTEGER` |
| `col_schema_name` | `VARCHAR2(128)` |
| `col_schema_name_len` | `INTEGER` |
| `col_precision` | `INTEGER` |
| `col_scale` | `INTEGER` |
| `col_charsetid` | `INTEGER` |
| `col_charsetform` | `INTEGER` |
| `col_null_ok` | `BOOLEAN` |
| `col_type_name` | `VARCHAR2(32767)` |
| `col_type_name_len` | `INTEGER` |

| Column name | Type |
| --------------------- | --------------- |
| `col_type` | `INTEGER` |
| `col_max_len` | `INTEGER` |
| `col_name` | `VARCHAR2(128)` |
| `col_name_len` | `INTEGER` |
| `col_schema_name` | `VARCHAR2(128)` |
| `col_schema_name_len` | `INTEGER` |
| `col_precision` | `INTEGER` |
| `col_scale` | `INTEGER` |
| `col_charsetid` | `INTEGER` |
| `col_charsetform` | `INTEGER` |
| `col_null_ok` | `BOOLEAN` |

### Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ TO_CURSOR_NUMBER (<rc> IN OUT SYS_REFCURSOR)

## Parameters

```sql
`rc`

The ref cursor to be transformed into a cursor number.
Expand All @@ -32,5 +31,17 @@ DECLARE
col2_data VARCHAR(30);
BEGIN
OPEN cur1 FOR 'SELECT * FROM test_tbl_tbl';
cur_id:= dbms_sql.TO_CURSOR_NUMBER
cur_id:= dbms_sql.to_cursor_number(cur1);

dbms_sql.define_column(cur_id, 1, tbl_desc.col1);
dbms_sql.define_column(cur_id, 2, tbl_desc.col2);

LOOP
ret := dbms_sql.FETCH_ROWS(cur_id);
EXIT WHEN ret = 0;
dbms_sql.column_value(cur_id, 1, tbl_desc.col1);
dbms_sql.column_value(cur_id, 2, tbl_desc.col2);
dbms_output.put_line('Col1: ' || tbl_desc.col1 || ' Col2: ' || tbl_desc.col2);
END LOOP;
END;
```
Loading

0 comments on commit 168d411

Please sign in to comment.