home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / orarex.zip / RXORA.INF (.txt) < prev    next >
OS/2 Help File  |  1995-07-11  |  34KB  |  1,435 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Oracle-REXX Interface ΓòÉΓòÉΓòÉ
  3.  
  4. Oracle-REXX Interface for OS/2 Users's Guide 
  5.  
  6. Beta Version 
  7.  
  8. Please send comments regarding this document or the Oracle-REXX Interface to 
  9.  
  10.     David Tom 
  11.     dtom@us.oracle.com 
  12.  
  13.  
  14. ΓòÉΓòÉΓòÉ 2. Getting Started ΓòÉΓòÉΓòÉ
  15.  
  16. This chapter describes how to get started using the Oracle-REXX Interface. 
  17. Topics include: 
  18.  
  19.     o Loading the Oracle-REXX Interface 
  20.  
  21.     o Calling the Oracle-REXX Interface 
  22.  
  23.     o Embedded SQL vs SQL 
  24.  
  25.     o Using REXX variables in Embedded SQL 
  26.  
  27.     o Connecting to Oracle 
  28.  
  29.     o Disconnecting from Oracle 
  30.  
  31.  
  32. ΓòÉΓòÉΓòÉ 2.1. Loading the Oracle-REXX Interface ΓòÉΓòÉΓòÉ
  33.  
  34. Before you can use the Oracle-REXX Interface in a REXX program, you must first 
  35. define the SQLEXEC function using the built-in REXX function RxFuncAdd. 
  36.  
  37. Use the following REXX statement to define the SQLEXEC function. 
  38.  
  39. CALL RXFUNCADD 'SQLEXEC', 'RXORA', 'SQLEXEC'
  40.  
  41.  
  42. ΓòÉΓòÉΓòÉ 2.2. Calling the Oracle-REXX Interface ΓòÉΓòÉΓòÉ
  43.  
  44. Calling the Oracle-REXX Interface uses the function SQLEXEC. The SQLEXEC 
  45. function takes a single argument which is a string containing an embedded SQL 
  46. statement. 
  47.  
  48. CALL SQLEXEC "embedded_SQL"
  49.  
  50. The call to SQLEXEC returns a return code in the variable result. The variable 
  51. result will be set to zero if the embedded SQL statement was valid and passed 
  52. to the Oracle database for execution. Any error from the Oracle database will 
  53. be returned in the SQL Communications Area (SQLCA). The variable sqlca.sqlcode 
  54. will contain the Oracle return code and the variable sqlca.sqlerrmc will 
  55. contain any error message text. 
  56.  
  57. The following sample code shows how to handle the return information from a 
  58. call to SQLEXEC. 
  59.  
  60. CALL SQLEXEC "embedded_SQL"
  61. IF result <> 0 THEN
  62.   SAY "Invalid embedded SQL statement"
  63. ELSE IF sqlca.sqlcode <> 0 THEN
  64.   SAY sqlca.sqlerrmc
  65.  
  66.  
  67. ΓòÉΓòÉΓòÉ 2.3. Embedded SQL vs SQL ΓòÉΓòÉΓòÉ
  68.  
  69. Embedded SQL statements are the commands used by the Oracle-REXX Interface to 
  70. control and process SQL statements. Embedded SQL statements allow the 
  71. Oracle-REXX Interface to: 
  72.  
  73.     o Connect to an Oracle database 
  74.     o Parse and prepare SQL statements 
  75.     o Execute SQL statements 
  76.     o Fetch the results of a query 
  77.     o Commit or rollback transactions 
  78.  
  79.  All of the commands passed to the Oracle-REXX Interface are embedded SQL 
  80.  statements. Embedded SQL statements should not be confused with standard SQL 
  81.  statements such as INSERT or SELECT. Embedded SQL statements may specify as 
  82.  part of the embedded SQL statement a standard SQL statement to be prepared or 
  83.  executed. 
  84.  
  85.  
  86. ΓòÉΓòÉΓòÉ 2.4. Using REXX variables in Embedded SQL ΓòÉΓòÉΓòÉ
  87.  
  88. Some embedded SQL statements allow REXX variables to be used to specify values 
  89. for the statement. For example, in the CONNECT statement, the user and password 
  90. values are specified by REXX variables. Generally, when a REXX variable is used 
  91. in an embedded SQL statement, the name of the REXX variable is preceded by a 
  92. colon. 
  93.  
  94. CONNECT :user IDENTIFIED BY :password
  95.  
  96. In the above example, user is the name of a REXX variable which contains the 
  97. user name, and password is the name of a REXX variable which contains the 
  98. user's password. 
  99.  
  100.  
  101. ΓòÉΓòÉΓòÉ 2.5. Connecting to Oracle ΓòÉΓòÉΓòÉ
  102.  
  103. Use the embedded SQL statement CONNECT, to connect to Oracle. The format of the 
  104. CONNECT statement is: 
  105.  
  106. CALL SQLEXEC "CONNECT :user IDENTIFIED BY :password USING :connect"
  107.  
  108. where 
  109.  
  110.     user        is the name of a REXX variable containing the user name 
  111.  
  112.     password    is the name of a REXX variable containing the user's password 
  113.  
  114.     connect     is the name of a REXX variable containing the Oracle connect 
  115.                 string 
  116.  
  117.  If user contains both the user and password in the form user/password then the 
  118.  IDENTIFIED BY :password clause may be omitted. The USING :connect clause is 
  119.  optional and the default connect string will be used if not specified. 
  120.  
  121.  
  122. ΓòÉΓòÉΓòÉ 2.6. Disconnecting from Oracle ΓòÉΓòÉΓòÉ
  123.  
  124. To disconnect from Oracle, use the RELEASE option on the COMMIT or ROLLBACK 
  125. embedded SQL statements. The COMMIT statement will commit the current changes 
  126. before disconnecting from Oracle and the ROLLBACK statement will roll back the 
  127. current changes before disconnecting from Oracle. 
  128.  
  129. CALL SQLEXEC "COMMIT RELEASE"
  130. CALL SQLEXEC "ROLLBACK RELEASE"
  131.  
  132.  
  133. ΓòÉΓòÉΓòÉ 3. Processing SQL Statements ΓòÉΓòÉΓòÉ
  134.  
  135. This chapter describes how to process SQL statements using the Oracle-REXX 
  136. Interface. The Oracle-REXX Interface processes SQL statements in a manor 
  137. similar to the other Oracle Precompilers, such as Pro*C and Pro*COBOL. There is 
  138. one major difference. Since REXX is an interpreted language, there is no 
  139. precompile step. The Oracle-REXX Interface uses dynamic SQL to process SQL 
  140. statements. Dynamic SQL allows SQL statements to be processed without requiring 
  141. a precompile step. 
  142.  
  143. Dynamic SQL has four methods for processing SQL statements depending upon the 
  144. type of SQL statement. This chapter describes which of the four methods to use 
  145. and how to use each of the four methods. Topics include: 
  146.  
  147.     o Statement Names and Cursor Names 
  148.  
  149.     o Variable Placeholders in SQL Statements 
  150.  
  151.     o Indicator Variables 
  152.  
  153.     o Which Method to Use 
  154.  
  155.     o Using Method 1 
  156.  
  157.     o Using Method 2 
  158.  
  159.     o Using Method 3 
  160.  
  161.     o Using Method 4 
  162.  
  163.  
  164. ΓòÉΓòÉΓòÉ 3.1. Statement Names and Cursor Names ΓòÉΓòÉΓòÉ
  165.  
  166. Statement names are identifiers used by the Oracle-REXX Interface to refer to 
  167. the SQL statements that are being processed. Cursor names are identifiers used 
  168. by the Oracle-REXX Interface to refer to cursors. Cursors are used for query 
  169. statements and are used to identify the current row in the query results. 
  170.  
  171. Statement and cursor names are identifiers used only by the Oracle-REXX 
  172. Interface. Statement and cursor names are not REXX variables. The DECLARE 
  173. statement is used to declare identifiers as statement or cursor names. Once 
  174. declared, statement and cursor names are defined for the REXX procedure in 
  175. which they were declared and may not be re-defined. 
  176.  
  177.  
  178. ΓòÉΓòÉΓòÉ 3.2. Variable Placeholders in SQL Statements ΓòÉΓòÉΓòÉ
  179.  
  180. Variable placeholders are used in dynamic SQL to represent values in a SQL 
  181. statement that will be replaced by REXX variables when the SQL statement is 
  182. executed. A variable placeholder is a name preceded by a colon. For example, 
  183. the following is a valid variable placeholder. 
  184.  
  185. :empno_val
  186.  
  187. A SQL statement will contain a variable placeholder where ever the value of a 
  188. REXX variable is to be substituted. In the following example, the insert 
  189. statement will insert the values for three columns into the emp table. The 
  190. values to be inserted will be specified by REXX variables when the statement is 
  191. executed. Therefore, the statement uses three variable placeholders to 
  192. represent those values. 
  193.  
  194. insert into emp(empno,ename,dept) values(:empno_val,:ename_val,:dept_val)
  195.  
  196. The names of the variable placeholders do not represent the names of REXX 
  197. variables. The variable placeholders merely represent places in the SQL 
  198. statement where the value of a REXX variable will be substituted. REXX 
  199. variables are substituted for the variable placeholders according to position. 
  200. The first REXX variable specified will be substituted for the first variable 
  201. placeholder and the second REXX variable will be substituted for the second 
  202. variable placeholder. Each variable placeholder represents a different place in 
  203. the SQL statement where a REXX variable may be substituted, even if the 
  204. variable placeholder names are the same. 
  205.  
  206. For example, the following insert statement is equivalent to the previous 
  207. example. The insert statement contains three variable placeholders where the 
  208. values of three different REXX variables may be substituted even though the 
  209. variable placeholders all have the same name. 
  210.  
  211. insert into emp(empno,ename,dept) values(:a,:a,:a)
  212.  
  213.  
  214. ΓòÉΓòÉΓòÉ 3.3. Indicator Variables ΓòÉΓòÉΓòÉ
  215.  
  216. Indicator variables are used in an embedded SQL statement to indicate a null 
  217. value. An indicator variable is a REXX variable which is assigned a value to 
  218. indicate whether an associated variable contains a null value. 
  219.  
  220. An Indicator variable is associated with a REXX variable by appending the name 
  221. of the indicator variable to the REXX variable. Remember that when REXX 
  222. variables are used in an embedded SQL statement, the REXX variable name is 
  223. preceded by a colon. In the following example, empno is a REXX variable 
  224. containing the value and empno_ind is a REXX variable used as the indicator 
  225. variable for empno. 
  226.  
  227. :empno:empno_ind
  228.  
  229. When used as an input variable, the indicator variable is interpreted as: 
  230.  
  231.     -1        The input is a null value. 
  232.  
  233.     0 or >0   The input is the value of the associated REXX variable. 
  234.  
  235.  When used as an output variable, the indicator variable is assigned: 
  236.  
  237.     -1        The output is a null value. 
  238.  
  239.     0         The output has been assigned to the associated REXX variable. 
  240.  
  241.     >0        The output has been assigned to the associated REXX variable but 
  242.               was truncated during the assignment. The value is the original 
  243.               length of the output value. 
  244.  
  245.  
  246. ΓòÉΓòÉΓòÉ 3.4. Which Method to Use ΓòÉΓòÉΓòÉ
  247.  
  248. Dynamic SQL provides four methods for processing a SQL statement. Which method 
  249. to use depends upon the type of SQL statement being processed and whether or 
  250. not the SQL statement contains any variable placeholders. Method 1 is the 
  251. simplest method to use and method 4 is the most complex. Use the following to 
  252. determine which method is appropriate. 
  253.  
  254.   1. Is the type of SQL statement unknown or the number of variable 
  255.      placeholders unknown? 
  256.  
  257.     Yes:  Use method 4 for non-query statements, or 
  258.           Use method 4 for query statements 
  259.  
  260.   2. Is the SQL statement a SELECT statement? 
  261.  
  262.     Yes:  Use method 3 
  263.  
  264.   3. Does the SQL statement have any variable placeholders? 
  265.  
  266.     Yes:  Use method 2 
  267.  
  268.     No:   Use method 1 
  269.  
  270.  
  271. ΓòÉΓòÉΓòÉ 3.5. Using Method 1 ΓòÉΓòÉΓòÉ
  272.  
  273. Dynamic SQL method 1 is used to execute SQL statements which are not query 
  274. statements and which do not use any variable placeholders. Method 1 is 
  275. generally used for SQL statements which are data control statements or data 
  276. definition statements such as GRANT and CREATE. 
  277.  
  278. Dynamic SQL method 1 is the simplest way to execute an SQL statement and 
  279. requires only an EXECUTE IMMEDIATE statement. 
  280.  
  281. Syntax 
  282.  
  283. CALL SQLEXEC "EXECUTE IMMEDIATE SQL_stmt"
  284.  
  285. Description 
  286.  
  287. The EXECUTE IMMEDIATE statement parses and executes the SQL statement. The SQL 
  288. statement can not contain any variable placeholders. 
  289.  
  290. Example 
  291.  
  292.  
  293. ΓòÉΓòÉΓòÉ <hidden> Method 1 Example ΓòÉΓòÉΓòÉ
  294.  
  295. This is an example for using dynamic SQL method 1. 
  296.  
  297. CALL SQLEXEC "EXECUTE IMMEDIATE create table temp (empno number(4), ename varchar2(40), dept number(4))"
  298.  
  299.  
  300. ΓòÉΓòÉΓòÉ 3.6. Using Method 2 ΓòÉΓòÉΓòÉ
  301.  
  302. Dynamic SQL method 2 is used to execute SQL statements which are not query 
  303. statements and which contain a known number of variable placeholders. Method 2 
  304. is generally used for SQL statements which are data manipulation statements 
  305. such as INSERT and DELETE. 
  306.  
  307. Dynamic SQL method 2 requires separate statement preparation and statement 
  308. execution steps. The preparation step parses the SQL statement and prepares it 
  309. for execution. The execution step executes the SQL statement with a given set 
  310. of values for the variable placeholders. Once the SQL statement has been 
  311. prepared, it may be executed several times using different values for the 
  312. variable placeholders. 
  313.  
  314. Syntax 
  315.  
  316. CALL SQLEXEC "DECLARE stmt_name STATEMENT"
  317. CALL SQLEXEC "PREPARE stmt_name FROM SQL_stmt"
  318. CALL SQLEXEC "EXECUTE stmt_name USING variable_list"
  319.  
  320. Description 
  321.  
  322. The DECLARE statement declares the identifier as a statement name. The 
  323. statement name is used to identify the SQL statement in the PREPARE and EXECUTE 
  324. statements. 
  325.  
  326. The PREPARE statement parses the SQL statement and prepares it for execution. 
  327.  
  328. The EXECUTE statement executes the SQL statement substituting the values from 
  329. the variable list for the variable placeholders in the SQL statement. 
  330.  
  331. Example 
  332.  
  333.  
  334. ΓòÉΓòÉΓòÉ <hidden> Method 2 Example ΓòÉΓòÉΓòÉ
  335.  
  336. This is an example for using dynamic SQL method 2. 
  337.  
  338. CALL SQLEXEC "DECLARE stmt STATEMENT"
  339. CALL SQLEXEC "PREPARE stmt FROM insert into temp(empno,ename,dept) values(:a,:b,:c)"
  340.  
  341. empno = 1021
  342. ename = 'David'
  343. dept  = 20
  344. CALL SQLEXEC "EXECUTE stmt USING :empno, :ename, :dept"
  345.  
  346. empno = 1021
  347. ename = 'Beverly'
  348. dept  = 20
  349. CALL SQLEXEC "EXECUTE stmt USING :empno, :ename, :dept"
  350.  
  351.  
  352. ΓòÉΓòÉΓòÉ 3.7. Using Method 3 ΓòÉΓòÉΓòÉ
  353.  
  354. Dynamic SQL method 3 is used to execute SQL statements which are query 
  355. statements and which contain a known number of variable placeholders. Method 3 
  356. is used for SELECT statements. 
  357.  
  358. Dynamic SQL method 3 requires separate statement preparation and statement 
  359. execution steps. Method 3 also requires the use of a cursor to return the rows 
  360. from the query results. The preparation step parses the SQL statement and 
  361. prepares it for execution. The execution step executes the SQL statement with a 
  362. given set of values for the variable placeholders and generates the query 
  363. results. The cursor is then used to return rows from the query results. Once 
  364. the SQL statement has been prepared, it may be executed several times using 
  365. different values for the variable placeholders and generating new query 
  366. results. 
  367.  
  368. Syntax 
  369.  
  370. CALL SQLEXEC "DECLARE stmt_name STATEMENT"
  371. CALL SQLEXEC "DECLARE cursor_name CURSOR FOR stmt_name"
  372.  
  373. CALL SQLEXEC "PREPARE stmt_name FROM SQL_stmt"
  374.  
  375. CALL SQLEXEC "OPEN cursor_name USING variable_list"
  376. CALL SQLEXEC "FETCH cursor_name INTO variable_list"
  377. CALL SQLEXEC "CLOSE cursor_name"
  378.  
  379. Description 
  380.  
  381. The DECLARE STATEMENT declares the identifier as a statement name. The 
  382. statement name is used to identify the SQL statement in the PREPARE statement 
  383. and in the declaration of the cursor. 
  384.  
  385. The DECLARE CURSOR declares the identifier as a cursor name and associates the 
  386. cursor name with the statement name. The cursor name is used to identify the 
  387. cursor and SQL statement in the OPEN, FETCH and CLOSE statements. 
  388.  
  389. The PREPARE statement parses the SQL statement and prepares it for execution. 
  390.  
  391. The OPEN statement executes the SQL statement substituting the values from the 
  392. variable list for the variable placeholders in the SQL statement and positions 
  393. the cursor before the first row of the query results. 
  394.  
  395. The FETCH statement moves the cursor to the next row of the query results and 
  396. returns the column values in the variable list. The FETCH statement is executed 
  397. repeatedly to return the rows of the query results. 
  398.  
  399. The CLOSE statement terminates the query and releases all resources associated 
  400. with the cursor and statement. After the cursor for a statement is closed, the 
  401. statement must be prepared again before being executed. 
  402.  
  403. Example 
  404.  
  405.  
  406. ΓòÉΓòÉΓòÉ <hidden> Method 3 Example ΓòÉΓòÉΓòÉ
  407.  
  408. This is an example for using dynamic SQL method 3. 
  409.  
  410. CALL SQLEXEC "DECLARE stmt STATEMENT"
  411. CALL SQLEXEC "DECLARE csr CURSOR FOR stmt"
  412.  
  413. CALL SQLEXEC "PREPARE stmt FROM select empno, ename from temp where dept=:a"
  414.  
  415. dept = 20
  416. CALL SQLEXEC "OPEN csr USING :dept"
  417.  
  418. CALL SQLEXEC "FETCH csr INTO :empno, :ename"
  419. DO WHILE (result = 0) & (sqlca.sqlcode = 0)
  420.   SAY empno ename
  421.   CALL SQLEXEC "FETCH csr INTO :empno, :ename"
  422. END
  423.  
  424. CALL SQLEXEC "CLOSE csr"
  425.  
  426.  
  427. ΓòÉΓòÉΓòÉ 3.8. Using Method 4 ΓòÉΓòÉΓòÉ
  428.  
  429. Dynamic SQL method 4 is used when the SQL statement and the number of variable 
  430. placeholders is not known in advance. 
  431.  
  432.     o Using Method 4 for Non-Query Statements 
  433.  
  434.     o Using Method 4 for Query Statements 
  435.  
  436.     o Bind Descriptor Variables 
  437.  
  438.     o Select Descriptor Variables 
  439.  
  440.  
  441. ΓòÉΓòÉΓòÉ 3.8.1. Using Method 4 for Non-Query Statements ΓòÉΓòÉΓòÉ
  442.  
  443. Dynamic SQL method 4 for non-query statements is used to execute SQL statements 
  444. which are not query statements and which have an unknown number of variable 
  445. placeholders. Method 4 is generally used when the SQL statement and the number 
  446. of variable placeholders is not known in advance. 
  447.  
  448. Determining if a SQL statement is a query statement. 
  449.  
  450. Syntax 
  451.  
  452. CALL SQLEXEC "DECLARE stmt_name STATEMENT"
  453.  
  454. CALL SQLEXEC "PREPARE stmt_name FROM :stmt_var"
  455. CALL SQLEXEC "DESCRIBE BIND VARIABLES FOR stmt_name INTO bind_desc"
  456.  
  457. CALL SQLEXEC "EXECUTE stmt_name USING DESCRIPTOR bind_desc"
  458.  
  459. Description 
  460.  
  461. The DECLARE statement declares the identifier as a statement name. The 
  462. statement name is used to identify the SQL statement in the PREPARE, DESCRIBE 
  463. and EXECUTE statements. 
  464.  
  465. The PREPARE statement parses the SQL statement and prepares it for execution. 
  466.  
  467. The DESCRIBE BIND statement returns information about the variable placeholders 
  468. in the SQL statement into the bind descriptor variable. The bind descriptor 
  469. variable is a compound REXX variable which will contain information about each 
  470. of the variable placeholders. After doing the DESCRIBE BIND and before the 
  471. EXECUTE statement, a value should be assigned for each of the variable 
  472. placeholders in the bind descriptor variable. 
  473.  
  474. The EXECUTE statement executes the SQL statement substituting the values from 
  475. the bind descriptor variable for the variable placeholders in the SQL 
  476. statement. 
  477.  
  478. Example 
  479.  
  480.  
  481. ΓòÉΓòÉΓòÉ <hidden> Method 4 Non-Query Example ΓòÉΓòÉΓòÉ
  482.  
  483. This is an example for using dynamic SQL method 4 for non-query statements. 
  484.  
  485. CALL SQLEXEC "DECLARE stmt STATEMENT"
  486.  
  487. SAY "Enter a non-query SQL statement"
  488. PULL sql
  489.  
  490. DO WHILE sql <> ""
  491.   CALL SQLEXEC "PREPARE stmt FROM :sql"
  492.   CALL SQLEXEC "DESCRIBE BIND VARIABLES FOR stmt INTO bind_desc"
  493.  
  494.   DO i = 1 TO bind_desc.sqld
  495.     SAY "Enter value for" bind_desc.i.sqlname
  496.     PULL bind_desc.i.sqldata
  497.     bind_desc.i.sqltype = 5
  498.     bind_desc.i.sqllen  = 0
  499.     bind_desc.i.sqlind  = 0
  500.   END
  501.  
  502.   CALL SQLEXEC "EXECUTE stmt USING DESCRIPTOR bind_desc"
  503.  
  504.   SAY "Enter a non-query SQL statement"
  505.   PULL sql
  506. END
  507.  
  508.  
  509. ΓòÉΓòÉΓòÉ 3.8.2. Using Method 4 for Query Statements ΓòÉΓòÉΓòÉ
  510.  
  511. Dynamic SQL method 4 for query statements is used to execute SQL statements 
  512. which are query statements and which have an unknown number of variable 
  513. placeholders. Method 4 is generally used when the SQL statement and the number 
  514. of variable placeholders is not known in advance. 
  515.  
  516. Determining if a SQL statement is a query statement. 
  517.  
  518. Syntax 
  519.  
  520. CALL SQLEXEC "DECLARE stmt_name STATEMENT"
  521. CALL SQLEXEC "DECLARE cursor_name CURSOR FOR stmt_name"
  522.  
  523. CALL SQLEXEC "PREPARE stmt_name FROM :stmt_var"
  524. CALL SQLEXEC "DESCRIBE BIND VARIABLES FOR stmt_name INTO bind_desc"
  525. CALL SQLEXEC "DESCRIBE SELECT LIST FOR stmt_name INTO select_desc"
  526.  
  527. CALL SQLEXEC "OPEN cursor_name USING DESCRIPTOR bind_desc"
  528. CALL SQLEXEC "FETCH cursor_name USING DESCRIPTOR select_desc"
  529. CALL SQLEXEC "CLOSE cursor_name"
  530.  
  531. Description 
  532.  
  533. The DECLARE STATEMENT declares the identifier as a statement name. The 
  534. statement name is used to identify the SQL statement in the PREPARE statement, 
  535. DESCRIBE statement and in the declaration of the cursor. 
  536.  
  537. The DECLARE CURSOR declares the identifier as a cursor name and associates the 
  538. cursor name with the statement name. The cursor name is used to identify the 
  539. cursor and SQL statement in the OPEN, FETCH and CLOSE statements. 
  540.  
  541. The PREPARE statement parses the SQL statement and prepares it for execution. 
  542.  
  543. The DESCRIBE BIND statement returns information about the variable placeholders 
  544. in the SQL statement into the bind descriptor variable. The bind descriptor 
  545. variable is a compound REXX variable which will contain information about each 
  546. of the variable placeholders. After doing the DESCRIBE BIND and before the OPEN 
  547. statement, a value should be assigned for each of the variable placeholders in 
  548. the bind descriptor variable. 
  549.  
  550. The DESCRIBE SELECT statement returns information about the columns being 
  551. returned by the query into the select descriptor variable. The select 
  552. descriptor variable is a compound REXX variable which will contain information 
  553. about each of the columns being returned. 
  554.  
  555. The OPEN statement executes the SQL statement substituting the values from the 
  556. bind descriptor variable for the variable placeholders in the SQL statement and 
  557. positions the cursor before the first row of the query results. 
  558.  
  559. The FETCH statement moves the cursor to the next row of the query results and 
  560. returns the column values in the select descriptor variable. The FETCH 
  561. statement is executed repeatedly to return the rows of the query results. 
  562.  
  563. The CLOSE statement terminates the query and releases all resources associated 
  564. with the cursor and statement. After the cursor for a statement is closed, the 
  565. statement must be prepared again before being executed. 
  566.  
  567. Example 
  568.  
  569.  
  570. ΓòÉΓòÉΓòÉ <hidden> Method 4 Query Example ΓòÉΓòÉΓòÉ
  571.  
  572. This is an example for using dynamic SQL method 4 for query statements. 
  573.  
  574. CALL SQLEXEC "DECLARE stmt STATEMENT"
  575. CALL SQLEXEC "DECLARE csr CURSOR FOR stmt"
  576.  
  577. SAY "Enter a query SQL statement"
  578. PULL sql
  579.  
  580. DO WHILE sql <> ""
  581.   CALL SQLEXEC "PREPARE stmt FROM :sql"
  582.   CALL SQLEXEC "DESCRIBE BIND VARIABLES FOR stmt INTO bind_desc"
  583.   CALL SQLEXEC "DESCRIBE SELECT LIST FOR stmt INTO sel_desc"
  584.  
  585.   DO i = 1 TO bind_desc.sqld
  586.     SAY "Enter value for" bind_desc.i.sqlname
  587.     PULL bind_desc.i.sqldata
  588.     bind_desc.i.sqltype = 5
  589.     bind_desc.i.sqllen  = 0
  590.     bind_desc.i.sqlind  = 0
  591.   END
  592.  
  593.   DO i = 1 TO sel_desc.sqld
  594.     sel_desc.i.sqltype = 5
  595.     sel_desc.i.sqllen  = 0
  596.   END
  597.  
  598.   CALL SQLEXEC "OPEN csr USING DESCRIPTOR bind_desc"
  599.  
  600.   CALL SQLEXEC "FETCH csr USING DESCRIPTOR sel_desc"
  601.   DO WHILE (result = 0) & (sqlca.sqlcode = 0)
  602.     DO i = 1 TO sel_desc.sqld
  603.       SAY sel_desc.i.sqlname "is" sel_desc.i.sqldata
  604.     END
  605.     CALL SQLEXEC "FETCH csr USING DESCRIPTOR sel_desc"
  606.   END
  607.  
  608.   CALL SQLEXEC "CLOSE csr"
  609.  
  610.   SAY "Enter a query SQL statement"
  611.   PULL sql
  612. END
  613.  
  614.  
  615. ΓòÉΓòÉΓòÉ 3.8.3. Bind Descriptor Variables ΓòÉΓòÉΓòÉ
  616.  
  617. Bind descriptor variables are used in dynamic SQL method 4 to get information 
  618. about the variable placeholders in a SQL statement and to provide values to be 
  619. bound to the variable placeholders. A bind descriptor variable is a compound 
  620. REXX variable representing a SQLDA structure. 
  621.  
  622. Used in DESCRIBE BIND 
  623.  
  624. When used in a DESCRIBE BIND statement to obtain information about the variable 
  625. placeholders in a SQL statement, the following fields of the bind descriptor 
  626. variable are set. 
  627.  
  628.     xx.SQLD           Set to the number of variable placeholders. Each of the 
  629.                       variable placeholders is described by xx.1 to xx.n. 
  630.  
  631.     xx.n.SQLNAME      Set to the name of the variable placeholder. 
  632.  
  633.     xx.n.SQLINAME     Set to the name of the variable placeholder indicator 
  634.                       variable. 
  635.  
  636.  Used in EXECUTE or OPEN 
  637.  
  638.  When used in an EXECUTE or OPEN statement to bind values to the variable 
  639.  placeholders in a SQL statement, the following fields of the bind descriptor 
  640.  variable are used. 
  641.  
  642.     xx.SQLD           The number of values to bind to the variable 
  643.                       placeholders. Each of the values are specified in xx.1 to 
  644.                       xx.n. 
  645.  
  646.     xx.n.SQLTYPE      The type of the value. 
  647.  
  648.     xx.n.SQLLEN       The length of the value. 
  649.  
  650.     xx.n.SQLDATA      The value to be used. 
  651.  
  652.     xx.n.SQLIND       The indicator value to be used. 
  653.  
  654.  
  655. ΓòÉΓòÉΓòÉ 3.8.4. Select Descriptor Variables ΓòÉΓòÉΓòÉ
  656.  
  657. Select descriptor variables are used in dynamic SQL method 4 to get information 
  658. about the columns returned by a query and to receive the value of the columns 
  659. when a row is fetched. A select descriptor variable is a compound REXX variable 
  660. representing a SQLDA structure. 
  661.  
  662. Used in DESCRIBE SELECT 
  663.  
  664. When used in a DESCRIBE SELECT statement to obtain information about the 
  665. columns returned by a query, the following fields of the select descriptor 
  666. variable are set. 
  667.  
  668.     xx.SQLD           Set to the number of columns. Each of the columns is 
  669.                       described by in xx.1 to xx.n. 
  670.  
  671.     xx.n.SQLNAME      Set to the name of the column. 
  672.  
  673.     xx.n.SQLTYPE      Set to the type of the column. 
  674.  
  675.     xx.n.SQLLEN       Set to the length of the column. 
  676.  
  677.        xx.n.SQLLEN.PRECISION 
  678.        xx.n.SQLLEN.SCALE 
  679.  
  680.  Used in FETCH 
  681.  
  682.  When used in a FETCH statement to receive the values when a row is fetched, 
  683.  the following fields of the select descriptor variable are used or set. 
  684.  
  685.     xx.SQLD           The number of column to be returned. Each column is 
  686.                       returned in xx.1 to xx.n. 
  687.  
  688.     xx.n.SQLTYPE 
  689.  
  690.     xx.n.SQLLEN 
  691.  
  692.     xx.n.SQLDATA      Set the the value of the column. 
  693.  
  694.     xx.n.SQLIND       Set to the indicator value for the column. 
  695.  
  696.  
  697. ΓòÉΓòÉΓòÉ 4. Advanced Features ΓòÉΓòÉΓòÉ
  698.  
  699. This chapter describes using the advanced features of the Oracle-REXX 
  700. Interface. The advanced features are: 
  701.  
  702.     o Using Arrays 
  703.  
  704.     o Using Multiple Database Sessions 
  705.  
  706.     o PL/SQL 
  707.  
  708.     o CURRENT OF Clause 
  709.  
  710.  
  711. ΓòÉΓòÉΓòÉ 4.1. Using Arrays ΓòÉΓòÉΓòÉ
  712.  
  713. Arrays can be used to simplify the processing of a SQL statement by the 
  714. Oracle-REXX Interface. For example, an array can be used to simplify retrieving 
  715. query results by allowing multiple rows to be retrieved in a single FETCH 
  716. statement.  Arrays can also be used to simplify the processing of INSERT, 
  717. UPDATE and DELETE statements by allowing these statements to process an array 
  718. of data in a single statement. 
  719.  
  720. Arrays in REXX are represented as compound variables. A compound variable 
  721. consist of a stem followed by a tail delimited by a period. For example, an 
  722. array of employee numbers would be represented by the compound variables 
  723.  
  724.   empno.1
  725.   empno.2
  726.   empno.3
  727.   ...
  728.   empno.n
  729.  
  730.  
  731. ΓòÉΓòÉΓòÉ 4.1.1. Fetching With Arrays ΓòÉΓòÉΓòÉ
  732.  
  733. Arrays can be used to retrieve multiple rows in a single FETCH statement. A FOR 
  734. clause is required on the FETCH statement to retrieve multiple rows. The syntax 
  735. is as follows: 
  736.  
  737. CALL SQLEXEC "FOR :count FETCH cursor_name INTO variable_list"
  738.  
  739. or 
  740.  
  741. CALL SQLEXEC "FOR :count FETCH cursor_name USING DESCRIPTOR select_desc"
  742.  
  743. The FOR clause specifies the name of a REXX variable which contains the number 
  744. of rows to retrieve. When the FOR clause is specified, the values are returned 
  745. as arrays. If a variable list is used, each variable in the list will be a 
  746. compound variable representing an array from 1 to count. If a select descriptor 
  747. is used, each SQLDATA component of the select descriptor will be a compound 
  748. variable representing an array from 1 to count. 
  749.  
  750. Fewer than count rows may be returned if there is an error or there is no more 
  751. data to return. The cumulative number of rows that have been returned is set in 
  752. the SQL Communications Area (SQLCA). The variable sqlca.sqlerrd.3 will contain 
  753. the cumulative number of rows returned. To find the number of rows returned by 
  754. the current FETCH statement, it is necessary to subtract the number of rows 
  755. previously returned from sqlca.sqlerrd.3. 
  756.  
  757.  
  758. ΓòÉΓòÉΓòÉ 4.1.2. Executing With Arrays ΓòÉΓòÉΓòÉ
  759.  
  760. Arrays can be used to execute a SQL statement several times with different data 
  761. values. When using arrays, the SQL statement is executed once for each row of 
  762. the array. A FOR clause is required on the EXECUTE statement to do an array 
  763. execute. The syntax is as follows: 
  764.  
  765. CALL SQLEXEC "FOR :count EXECUTE stmt_name USING variable_list"
  766.  
  767. or 
  768.  
  769. CALL SQLEXEC "FOR :count EXECUTE stmt_name USING DESCRIPTOR bind_desc"
  770.  
  771. The FOR clause specifies the name of a REXX variable which contains the number 
  772. of times to execute the SQL statement. When the FOR clause is specified, the 
  773. values to be substituted for the variable placeholders must be arrays. If a 
  774. variable list is used, each variable in the list must be a compound variable 
  775. representing an array from 1 to count, If a bind descriptor is used, each 
  776. SQLDATA component of the bind descriptor must be a compound variable 
  777. representing an array from 1 to count. 
  778.  
  779. The SQL statement may be executed fewer than count times if an error occurs. 
  780. The number of times the statement has been executed is set in the SQL 
  781. Communications Area (SQLCA). The variable sqlca.sqlerrd.3 will contain the 
  782. number of times the SQL statement was executed. 
  783.  
  784.  
  785. ΓòÉΓòÉΓòÉ 4.2. Using Multiple Database Sessions ΓòÉΓòÉΓòÉ
  786.  
  787. Multiple database sessions allows you to simultaneously connect to several 
  788. different Oracle databases or to use multiple connections to a single Oracle 
  789. database. 
  790.  
  791. Each connection to an Oracle database is identified by a database session name. 
  792. Embedded SQL statements can be executed at different databases or using 
  793. different connections by using the AT clause to specify a database session for 
  794. the embedded SQL statement. 
  795.  
  796.  
  797. ΓòÉΓòÉΓòÉ 4.2.1. AT Clause ΓòÉΓòÉΓòÉ
  798.  
  799. The AT clause is used to specify the name of a database session. The syntax of 
  800. the AT clause is: 
  801.  
  802. AT db_name
  803.  
  804. or 
  805.  
  806. AT :db_var
  807.  
  808. If db_name is used, db_name must be a name that has been declared as a database 
  809. session by a DECLARE DATABASE statement. 
  810.  
  811. If db_var is used, db_var is the name of a REXX variable which contains the 
  812. name of the database session. In this case, the name of the database session 
  813. can be any valid name and does not need to be declared by a DECLARE DATABASE 
  814. statement. 
  815.  
  816.  
  817. ΓòÉΓòÉΓòÉ 4.2.2. Creating a Named Database Session ΓòÉΓòÉΓòÉ
  818.  
  819. To create a named database session, use the AT clause on the CONNECT statement. 
  820. Once connected, the database session identifier can be used to refer to this 
  821. database connection. 
  822.  
  823. CALL SQLEXEC "DECLARE session1 DATABASE"
  824. CALL SQLEXEC "CONNECT :user IDENTIFIED BY :password AT session1 USING :connect"
  825.  
  826. or 
  827.  
  828. session = "session2"
  829. CALL SQLEXEC "CONNECT :user IDENTIFIED BY :password AT :session USING :connect"
  830.  
  831.  
  832. ΓòÉΓòÉΓòÉ 4.2.3. Executing At a Named Database Session ΓòÉΓòÉΓòÉ
  833.  
  834. To execute an embedded SQL statement at a named database session, use the AT 
  835. clause to identify the database session where the statement is to be executed. 
  836.  
  837. Execute Immediate 
  838.  
  839. CALL SQLEXEC "AT db_name EXECUTE IMMEDIATE SQL_stmt"
  840.  
  841. Preparing and Executing 
  842.  
  843. CALL SQLEXEC "AT db_name DECLARE stmt_name STATEMENT"
  844. CALL SQLEXEC "PREPARE stmt_name FROM SQL_stmt"
  845. CALL SQLEXEC "EXECUTE stmt_name USING variable_list"
  846.  
  847. Preparing, Executing and Fetching 
  848.  
  849. CALL SQLEXEC "AT db_name DECLARE stmt_name STATEMENT"
  850. CALL SQLEXEC "DECLARE cursor_name CURSOR FOR stmt_name"
  851.  
  852. CALL SQLEXEC "PREPARE stmt_name FROM SQL_stmt"
  853.  
  854. CALL SQLEXEC "OPEN cursor_name USING variable_list"
  855. CALL SQLEXEC "FETCH cursor_name INTO variable_list"
  856. CALL SQLEXEC "CLOSE cursor_name"
  857.  
  858.  
  859. ΓòÉΓòÉΓòÉ 4.3. PL/SQL ΓòÉΓòÉΓòÉ
  860.  
  861. Use of PL/SQL is not implemented at this time. 
  862.  
  863.  
  864. ΓòÉΓòÉΓòÉ 4.4. CURRENT OF Clause ΓòÉΓòÉΓòÉ
  865.  
  866. The CURRENT OF clause is not implemented at this time. 
  867.  
  868.  
  869. ΓòÉΓòÉΓòÉ 5. Reference ΓòÉΓòÉΓòÉ
  870.  
  871. This chapter contains reference information for the Oracle-REXX Interface. 
  872.  
  873.  
  874. ΓòÉΓòÉΓòÉ 5.1. Data Structures ΓòÉΓòÉΓòÉ
  875.  
  876. This section describes the data structures used by the Oracle-REXX Interface. 
  877.  
  878.  
  879. ΓòÉΓòÉΓòÉ 5.1.1. SQLCA - SQL Communications Area ΓòÉΓòÉΓòÉ
  880.  
  881. SQLCA.SQLCODE      Oracle return code
  882.                      0   Oracle executed the statement without
  883.                          any errors
  884.                      >0  Oracle detected an exception when the
  885.                          statement was executed, such as no
  886.                          data found
  887.                      <0  An error occurred while executing the
  888.                          statement.
  889.  
  890. SQLCA.SQLERRMC     Error message text
  891. SQLCA.SQLERRML     Error message length
  892.  
  893. SQLCA.SQLERRD.1    Reserved
  894. SQLCA.SQLERRD.2    Reserved
  895. SQLCA.SQLERRD.3    Number of rows processed
  896. SQLCA.SQLERRD.4    Reserved
  897. SQLCA.SQLERRD.5    Offset of parse error
  898. SQLCA.SQLERRD.6    Reserved
  899.  
  900. The following are warning flags which are set to 'W' to indicate
  901. a warning.
  902.  
  903. SQLCA.SQLWARN.1    Set if any other flag is set
  904. SQLCA.SQLWARN.2    Set if a column value was truncated
  905. SQLCA.SQLWARN.3    Not used
  906. SQLCA.SQLWARN.4    Set if the number of columns exceeds the
  907.                    number of host variables specified
  908. SQLCA.SQLWARN.5    Set for UPDATE or DELETE without a WHERE clause
  909. SQLCA.SQLWARN.6    Set for a PL/SQL compilation error
  910. SQLCA.SQLWARN.7    Not used
  911. SQLCA.SQLWARN.8    Not used
  912.  
  913. SQLCA.SQLERRP      Reserved
  914. SQLCA.SQLEXT       Reserved
  915.  
  916.  
  917. ΓòÉΓòÉΓòÉ 5.1.2. SQLDA - SQL Descriptor ΓòÉΓòÉΓòÉ
  918.  
  919. xx.SQLD                Number of values in descriptor
  920. xx.n.SQLNAME           Name
  921. xx.n.SQLINAME          Indicator name
  922. xx.n.SQLTYPE           Data type
  923. xx.n.SQLLEN            Length
  924. xx.n.SQLLEN.PRECISION  Precision (if numeric data type)
  925. xx.n.SQLLEN.SCALE      Scale (if numeric data type)
  926. xx.n.SQLDATA           Data value
  927. xx.n.SQLIND            Indicator value
  928.  
  929.  
  930. ΓòÉΓòÉΓòÉ 5.2. Embedded SQL Statements ΓòÉΓòÉΓòÉ
  931.  
  932. This section provides a reference for the embedded SQL statements supported by 
  933. the Oracle-REXX Interface. 
  934.  
  935.  
  936. ΓòÉΓòÉΓòÉ 5.2.1. Variable List ΓòÉΓòÉΓòÉ
  937.  
  938. A variable list is used to provide a list of REXX variables and optionally the 
  939. associated REXX indicator variables. 
  940.  
  941. Syntax 
  942.  
  943.    ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ , ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  944.                                                   Γöé
  945. ΓöÇΓöÇΓöÇ :variable ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇ
  946.                  Γöé                               Γöé
  947.                  Γö£ΓöÇ :indicator_var ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  948.                  Γöé                               Γöé
  949.                  ΓööΓöÇ INDICATOR ΓöÇΓöÇ :indicator_var ΓöÇΓöÿ
  950.  
  951. Usage Notes 
  952.  
  953. The variable and indicator variables are preceded by a colon which is not part 
  954. of the REXX variable name. 
  955.  
  956. Variables in the list are separated by commas. Indicator variables can be 
  957. concatenated to their associated variable, separated by a blank, or the keyword 
  958. INDICATOR. 
  959.  
  960.  
  961. ΓòÉΓòÉΓòÉ 5.2.2. CLOSE ΓòÉΓòÉΓòÉ
  962.  
  963. The CLOSE statement closes a cursor and releases the resources associated with 
  964. the cursor. 
  965.  
  966. Syntax 
  967.  
  968. ΓöÇΓöÇ CLOSE ΓöÇΓöÇ cursor_name ΓöÇΓöÇ
  969.  
  970. Usage Notes 
  971.  
  972. Closing a cursor which is not open or which has not been declared generates an 
  973. error. 
  974.  
  975. A cursor may be re-opened without closing the cursor. Once a cursor has been 
  976. closed, the associated statement must be prepared again before the cursor can 
  977. be re-opened. 
  978.  
  979.  
  980. ΓòÉΓòÉΓòÉ 5.2.3. COMMIT ΓòÉΓòÉΓòÉ
  981.  
  982. The COMMIT statement ends the current transaction and makes changes to the 
  983. database permanent. 
  984.  
  985. Syntax 
  986.  
  987. ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ COMMIT ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  988.    Γöé                  Γöé          Γöé        Γöé Γöé           Γöé
  989.    ΓööΓöÇ AT ΓöÇΓö¼ΓöÇ db_name ΓöÇΓöñ          ΓööΓöÇ WORK ΓöÇΓöÿ ΓööΓöÇ RELEASE ΓöÇΓöÿ
  990.           Γöé           Γöé
  991.           ΓööΓöÇ :db_var ΓöÇΓöÿ
  992.  
  993. Usage Notes 
  994.  
  995. The RELEASE keyword is used to disconnect from Oracle after the transaction has 
  996. been committed. 
  997.  
  998. The AT clause specifies the name of the database session for the COMMIT. If the 
  999. AT clause is not specified, the default database session is used. 
  1000.  
  1001.  
  1002. ΓòÉΓòÉΓòÉ 5.2.4. CONNECT ΓòÉΓòÉΓòÉ
  1003.  
  1004. The CONNECT statement logs on to an Oracle database. 
  1005.  
  1006. Syntax 
  1007.  
  1008. ΓöÇΓöÇΓöÇ CONNECT ΓöÇΓö¼ΓöÇ :user_password ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  1009.                Γöé                                       Γöé
  1010.                ΓööΓöÇ :user ΓöÇΓöÇ IDENTIFIED BY ΓöÇΓöÇ :password ΓöÇΓöÿ
  1011.  
  1012.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  1013.    Γöé                  Γöé Γöé                            Γöé
  1014.    ΓööΓöÇ AT ΓöÇΓö¼ΓöÇ db_name ΓöÇΓöñ ΓööΓöÇ USING ΓöÇΓöÇ :connect_string ΓöÇΓöÿ
  1015.           Γöé           Γöé
  1016.           ΓööΓöÇ :db_var ΓöÇΓöÿ
  1017.  
  1018. Usage Notes 
  1019.  
  1020. The user and password can be specified by a single REXX variable which contains 
  1021. username/password or by a REXX variable containing the username and a separate 
  1022. REXX variable containing the password. 
  1023.  
  1024. The AT clause specifies the name of the database session and is used to create 
  1025. multiple connections.  If the AT clause is not specified, the default database 
  1026. session is used. 
  1027.  
  1028. The USING clause specifies the Oracle connect string which identifies the 
  1029. database to connect to. If not specified, the default database is used. 
  1030.  
  1031. If the database session is already connected, the CONNECT statement will 
  1032. disconnect the session before making the new connection. 
  1033.  
  1034.  
  1035. ΓòÉΓòÉΓòÉ 5.2.5. DECLARE CURSOR ΓòÉΓòÉΓòÉ
  1036.  
  1037. The DECLARE CURSOR statement declares a cursor and associates it with a 
  1038. specific query. 
  1039.  
  1040. Syntax 
  1041.  
  1042. ΓöÇΓöÇ DECLARE ΓöÇΓöÇ cursor_name ΓöÇΓöÇ CURSOR FOR ΓöÇΓöÇ stmt_name ΓöÇΓöÇ
  1043.  
  1044. Usage Notes 
  1045.  
  1046. The cursor name and statement name are identifiers used by the Oracle-REXX 
  1047. Interface and are not REXX variables. 
  1048.  
  1049. The cursor name must be declared before it is used. The scope of the cursor 
  1050. declaration is the REXX procedure in which the cursor is declared. Therefore, 
  1051. the cursor name must be unique within the REXX procedure in which it is 
  1052. declared and can not be referenced outside of the REXX procedure in which it is 
  1053. declared. 
  1054.  
  1055. The statement name must have been previously declared as a statement either 
  1056. explicitly by a DECLARE STATEMENT statement or implicitly by a PREPARE 
  1057. statement. 
  1058.  
  1059.  
  1060. ΓòÉΓòÉΓòÉ 5.2.6. DECLARE DATABASE ΓòÉΓòÉΓòÉ
  1061.  
  1062. The DECLARE DATABASE statement declares the name of a non-default database 
  1063. session for use in the AT clause. 
  1064.  
  1065. Syntax 
  1066.  
  1067. ΓöÇΓöÇ DECLARE ΓöÇΓöÇ db_name ΓöÇΓöÇ DATABASE ΓöÇΓöÇ
  1068.  
  1069. Usage Notes 
  1070.  
  1071. The database name is an identifier used by the Oracle-REXX Interface and is not 
  1072. a REXX variable. 
  1073.  
  1074. The database name must be declared before it is used. The scope of the database 
  1075. declaration is the REXX procedure in which the database is declared. Therefore, 
  1076. the database name must be unique within the REXX procedure in which it is 
  1077. declared. 
  1078.  
  1079. Unlike statement names and cursor names, if the same database name is declared 
  1080. in two different REXX procedures then the database name in both REXX procedures 
  1081. will refer to the same database session. This allows doing a connection using a 
  1082. database name in one REXX procedure and processing embedded SQL statement in 
  1083. another REXX procedure using the same database name to refer to the same 
  1084. session. 
  1085.  
  1086.  
  1087. ΓòÉΓòÉΓòÉ 5.2.7. DECLARE STATEMENT ΓòÉΓòÉΓòÉ
  1088.  
  1089. The DECLARE STATEMENT statement declares the name of a dynamic SQL statement. 
  1090.  
  1091. Syntax 
  1092.  
  1093. ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ DECLARE ΓöÇΓöÇ stmt_name ΓöÇΓöÇ STATEMENT ΓöÇΓöÇ
  1094.    Γöé                  Γöé
  1095.    ΓööΓöÇ AT ΓöÇΓö¼ΓöÇ db_name ΓöÇΓöñ
  1096.           Γöé           Γöé
  1097.           ΓööΓöÇ :db_var ΓöÇΓöÿ
  1098.  
  1099. Usage Notes 
  1100.  
  1101. The statement name is an identifier used by the Oracle-REXX Interface and is 
  1102. not a REXX variable. 
  1103.  
  1104. The statement name must be explicitly declared by a DECLARE STATEMENT statement 
  1105. or implicitly declared by a PREPARE statement before it is used. The scope of 
  1106. statement declaration is the REXX procedure in which the statement is declared. 
  1107. Therefore, the statement name must be unique within the REXX procedure in which 
  1108. it is declared and can not be referenced outside of the REXX procedure in which 
  1109. it is declared. 
  1110.  
  1111. The AT clause specifies the name of the database session to be used for the 
  1112. statement. If the AT clause is not specified, the default database session is 
  1113. used. If the statement is to be executed using a database session other than 
  1114. the default session, the statement must be explicitly declared and the AT 
  1115. clause must be specified on the DECLARE statement. 
  1116.  
  1117.  
  1118. ΓòÉΓòÉΓòÉ 5.2.8. DESCRIBE BIND ΓòÉΓòÉΓòÉ
  1119.  
  1120. The DESCRIBE BIND statement returns information in the descriptor variable 
  1121. about the variable placeholders in a prepared dynamic SQL statement. 
  1122.  
  1123. Syntax 
  1124.  
  1125. ΓöÇΓöÇ DESCRIBE BIND VARIABLES FOR ΓöÇΓöÇ stmt_name ΓöÇΓöÇ INTO ΓöÇΓöÇ descriptor ΓöÇΓöÇ
  1126.  
  1127. Usage Notes 
  1128.  
  1129. The statement name is an identifier associated with a prepared SQL statement. 
  1130. The statement name identifier is used by the Oracle-REXX Interface and is not a 
  1131. REXX variable. The SQL statement must be prepared using the PREPARE statement 
  1132. before it can be described with the DESCRIBE BIND statement. 
  1133.  
  1134. The REXX variable descriptor is a compound variable in which information about 
  1135. the variable placeholders in the SQL statement will be returned. 
  1136.  
  1137.  
  1138. ΓòÉΓòÉΓòÉ 5.2.9. DESCRIBE SELECT ΓòÉΓòÉΓòÉ
  1139.  
  1140. The DESCRIBE SELECT statement returns information in the descriptor variable 
  1141. about the columns in the select list in a prepared dynamic SQL statement. 
  1142.  
  1143. Syntax 
  1144.  
  1145. ΓöÇΓöÇ DESCRIBE ΓöÇΓö¼ΓöÇ SELECT LIST FOR ΓöÇΓö¼ΓöÇ stmt_name ΓöÇΓöÇ INTO ΓöÇΓöÇ descriptor ΓöÇΓöÇ
  1146.                Γöé                   Γöé
  1147.                ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1148.  
  1149. Usage Notes 
  1150.  
  1151. The statement name is an identifier associated with a prepared SQL statement. 
  1152. The statement name identifier is used by the Oracle-REXX Interface and is not a 
  1153. REXX variable. The SQL statement must be prepared using the PREPARE statement 
  1154. before it can be described with the DESCRIBE SELECT statement. 
  1155.  
  1156. The REXX variable descriptor is a compound variable in which information about 
  1157. the columns in the select list of a SQL statement will be returned. 
  1158.  
  1159.  
  1160. ΓòÉΓòÉΓòÉ 5.2.10. EXECUTE ΓòÉΓòÉΓòÉ
  1161.  
  1162. The EXECUTE statement executes a prepared dynamic SQL statement. 
  1163.  
  1164. Syntax 
  1165.  
  1166. ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ EXECUTE ΓöÇΓöÇ stmt_name ΓöÇΓöÇ
  1167.    Γöé                     Γöé
  1168.    ΓööΓöÇ FOR ΓöÇΓöÇ :count_var ΓöÇΓöÿ
  1169.  
  1170.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  1171.    Γöé                                        Γöé
  1172.    ΓööΓöÇ USING ΓöÇΓö¼ΓöÇ variable_list ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  1173.              Γöé                            Γöé
  1174.              ΓööΓöÇ DESCRIPTOR ΓöÇΓöÇ descriptor ΓöÇΓöÿ
  1175.  
  1176. Usage Notes 
  1177.  
  1178. The statement name is an identifier associated with a prepared SQL statement. 
  1179. The statement name identifier is used by the Oracle-REXX Interface and is not a 
  1180. REXX variable. The SQL statement must be prepared using the PREPARE statement 
  1181. before it can be executed with the EXECUTE statement. 
  1182.  
  1183. The USING clause specifies either a list of REXX variables or the name of a 
  1184. REXX descriptor variable. The variable list or descriptor variable contains the 
  1185. values to be substituted for the variable placeholders in the SQL statement 
  1186. when the SQL statement is executed. The number of values must match the number 
  1187. of variable placeholders in the SQL statement. 
  1188.  
  1189. The FOR clause is used for executing with arrays. When executing with arrays, 
  1190. the variable list or descriptor variable contains arrays of values to be 
  1191. substituted for the variable placeholders. The REXX variable count_var contains 
  1192. the size of the arrays. The SQL statement is executed count_var times, each 
  1193. time substituting the next row from the arrays for the variable placeholders. 
  1194.  
  1195.  
  1196. ΓòÉΓòÉΓòÉ 5.2.11. EXECUTE IMMEDIATE ΓòÉΓòÉΓòÉ
  1197.  
  1198. The EXECUTE IMMEDIATE statement prepares and executes a dynamic SQL statement. 
  1199.  
  1200. Syntax 
  1201.  
  1202. ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ EXECUTE IMMEDIATE ΓöÇΓö¼ΓöÇ sql_stmt  ΓöÇΓö¼ΓöÇ
  1203.    Γöé                  Γöé                     Γöé             Γöé
  1204.    ΓööΓöÇ AT ΓöÇΓö¼ΓöÇ db_name ΓöÇΓöñ                     ΓööΓöÇ :stmt_var ΓöÇΓöÿ
  1205.           Γöé           Γöé
  1206.           ΓööΓöÇ :db_var ΓöÇΓöÿ
  1207.  
  1208. Usage Notes 
  1209.  
  1210. The EXECUTE IMMEDIATE statement parses, prepares and executes a SQL statement. 
  1211. If the SQL statement is to be execute several times then the PREPARE statement 
  1212. should be used to prepare the statement after which it can be executed several 
  1213. times without preparing the statement for each execution. 
  1214.  
  1215. The AT clause specifies the name of the database session where the statement 
  1216. will be executed. If the AT clause is not specified, the default database 
  1217. session is used. 
  1218.  
  1219. The SQL statement may be specified either by a literal string or by a REXX 
  1220. variable which contains the SQL statement. 
  1221.  
  1222.  
  1223. ΓòÉΓòÉΓòÉ 5.2.12. FETCH ΓòÉΓòÉΓòÉ
  1224.  
  1225. The FETCH statement advances the cursor to the next row of the query results 
  1226. and retrieves the row. 
  1227.  
  1228. Syntax 
  1229.  
  1230. ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ FETCH ΓöÇΓöÇ csr_name ΓöÇΓöÇ
  1231.    Γöé                     Γöé
  1232.    ΓööΓöÇ FOR ΓöÇΓöÇ :count_var ΓöÇΓöÿ
  1233.  
  1234.  ΓöÇΓö¼ΓöÇ INTO ΓöÇΓöÇΓöÇ variable_list ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  1235.    Γöé                                  Γöé
  1236.    ΓööΓöÇ USING DESCRIPTOR ΓöÇΓöÇ descriptor ΓöÇΓöÿ
  1237.  
  1238. Usage Notes 
  1239.  
  1240. The cursor name is an identifier previously declared as a cursor. The cursor 
  1241. name identifier is used by the Oracle-REXX Interface and is not a REXX 
  1242. variable. 
  1243.  
  1244. The cursor must be opened using an OPEN statement before the results of a query 
  1245. can be fetched. Each FETCH returns the next row of the query results. 
  1246.  
  1247. The INTO clause specifies a list of REXX variable to receive the column values 
  1248. from the query results. The USING DESCRIPTOR specifies the name of a REXX 
  1249. descriptor variable to receive the column values from the query results. 
  1250.  
  1251. The FOR clause is used for fetching with arrays. When fetching with arrays, the 
  1252. variable list or descriptor variable will return arrays of values. The REXX 
  1253. variable count_var contains the size of the arrays. 
  1254.  
  1255.  
  1256. ΓòÉΓòÉΓòÉ 5.2.13. OPEN ΓòÉΓòÉΓòÉ
  1257.  
  1258. The OPEN statement executes the query associated with the cursor and positions 
  1259. the cursor before the first row of the query results. 
  1260.  
  1261. Syntax 
  1262.  
  1263. ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ OPEN ΓöÇΓöÇ csr_name ΓöÇΓöÇ
  1264.    Γöé                     Γöé
  1265.    ΓööΓöÇ FOR ΓöÇΓöÇ :count_var ΓöÇΓöÿ
  1266.  
  1267.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  1268.    Γöé                                        Γöé
  1269.    ΓööΓöÇ USING ΓöÇΓö¼ΓöÇ variable_list ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  1270.              Γöé                            Γöé
  1271.              ΓööΓöÇ DESCRIPTOR ΓöÇΓöÇ descriptor ΓöÇΓöÿ
  1272.  
  1273. Usage Notes 
  1274.  
  1275. The cursor name is an identifier previously declared as a cursor. The cursor 
  1276. name identifier is used by the Oracle-REXX Interface and is not a REXX 
  1277. variable. 
  1278.  
  1279. The statement associated with the cursor must be prepared using a PREPARE 
  1280. statement before the cursor can be opened. When the cursor is opened, the 
  1281. statement is executed and the query results are generated. The cursor is 
  1282. positioned before the first row of the query results. 
  1283.  
  1284. The USING clause specifies either a list of REXX variables or the name of REXX 
  1285. descriptor variable. The variable list or descriptor variable contains the 
  1286. values to be substituted for the variable placeholders in the SQL statement 
  1287. when the SQL statement is executed. The number of values must match the number 
  1288. of variable placeholders in the SQL statement. 
  1289.  
  1290. The FOR clause is used for executing with arrays. When executing with arrays, 
  1291. the variable list or descriptor variable contains arrays of values to be 
  1292. substituted for the variable placeholders. The REXX variable count_var contains 
  1293. the size of the arrays. The SQL statement is executed count_var times, each 
  1294. time substituting the next row from the arrays for the variable placeholders. 
  1295.  
  1296.  
  1297. ΓòÉΓòÉΓòÉ 5.2.14. PREPARE ΓòÉΓòÉΓòÉ
  1298.  
  1299. The PREPARE statement parses and prepares a dynamic SQL statement. 
  1300.  
  1301. Syntax 
  1302.  
  1303. ΓöÇΓöÇ PREPARE ΓöÇΓöÇ stmt_name ΓöÇΓöÇ FROM ΓöÇΓö¼ΓöÇ sql_stmt  ΓöÇΓö¼ΓöÇ
  1304.                                    Γöé             Γöé
  1305.                                    ΓööΓöÇ :stmt_var ΓöÇΓöÿ
  1306.  
  1307. Usage Notes 
  1308.  
  1309. The PREPARE statement parses and prepares a SQL statement and associates a 
  1310. statement name with the SQL statement. The statement name is used to refer to 
  1311. the SQL statement after it has been prepared. The statement name is an 
  1312. identifier used by the Oracle-REXX Interface and is not a REXX variable. 
  1313.  
  1314. The statement name may have been previously declared as a statement name by a 
  1315. DECLARE STATEMENT statement. Otherwise the statement name must be an undeclared 
  1316. identifier which will be implicitly declared as a statement name. If the 
  1317. statement is to be executed using a database session other than the default 
  1318. database session, the statement name must be explicitly declared using the 
  1319. DECLARE STATEMENT statement and the AT clause must be specified. 
  1320.  
  1321. The SQL statement may be specified either by a literal string or by a REXX 
  1322. variable which contains the SQL statement. 
  1323.  
  1324. After a SQL statement has been prepared, it may be executed using an EXECUTE 
  1325. statement or an OPEN statement. The SQL statement may be executed several times 
  1326. without re-preparing the statement for each execution. 
  1327.  
  1328. SQL data definition statements, such as CREATE TABLE, are executed when they 
  1329. are prepared. Generally data definition statements should be executed using 
  1330. EXECUTE IMMEDIATE rather than PREPARE. 
  1331.  
  1332.  
  1333. ΓòÉΓòÉΓòÉ 5.2.15. ROLLBACK ΓòÉΓòÉΓòÉ
  1334.  
  1335. The ROLLBACK statement ends the current transaction and undoes the changes to 
  1336. the database. 
  1337.  
  1338. Syntax 
  1339.  
  1340. ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ ROLLBACK ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  1341.    Γöé                  Γöé            Γöé        Γöé Γöé           Γöé
  1342.    ΓööΓöÇ AT ΓöÇΓö¼ΓöÇ db_name ΓöÇΓöñ            ΓööΓöÇ WORK ΓöÇΓöÿ ΓööΓöÇ RELEASE ΓöÇΓöÿ
  1343.           Γöé           Γöé
  1344.           ΓööΓöÇ :db_var ΓöÇΓöÿ
  1345.  
  1346. Usage Notes 
  1347.  
  1348. The RELEASE keyword is used to disconnect from Oracle after the transaction has 
  1349. been rolled back. 
  1350.  
  1351. The AT clause specifies the name of the database session for the ROLLBACK. If 
  1352. the AT clause is not specified, the default database session is used. 
  1353.  
  1354.  
  1355. ΓòÉΓòÉΓòÉ 5.3. Return Codes ΓòÉΓòÉΓòÉ
  1356.  
  1357. SQLEXEC returns zero in the variable result if the embedded SQL statement was 
  1358. valid and passed to the Oracle database for execution. If the Oracle-REXX 
  1359. Interface detects an error a non-zero value will be returned in the variable 
  1360. result. 
  1361.  
  1362. Return codes 
  1363.  
  1364.     o 100-199 Syntax errors 
  1365.  
  1366.     o 200-299 Semantic errors 
  1367.  
  1368.     o 900-999 Fatal errors 
  1369.  
  1370.  
  1371. ΓòÉΓòÉΓòÉ 5.3.1. 100-199 Syntax Errors ΓòÉΓòÉΓòÉ
  1372.  
  1373. 101  ERR_KEYWORD_BY
  1374. 102  ERR_KEYWORD_FOR
  1375. 103  ERR_KEYWORD_VARIABLES
  1376. 104  ERR_KEYWORD_LIST
  1377. 105  ERR_KEYWORD_INTO
  1378. 106  ERR_KEYWORD_FROM
  1379. 107  ERR_KEYWORD_DESCRIPTOR
  1380. 108  ERR_KEYWORD_INTO_USING
  1381. 109  ERR_DESCNAME
  1382. 110  ERR_CURSOR_NAME
  1383. 111  ERR_STMT_NAME
  1384. 112  ERR_DECLARE_NAME
  1385. 113  ERR_VARLIST
  1386. 114  ERR_LITERAL
  1387. 115  ERR_SQL_STMT
  1388. 116  ERR_DECLARE_TYPE
  1389. 117  ERR_DESCRIPTOR_VARLIST
  1390. 118  ERR_IMMED_STMTNAME
  1391. 119  ERR_ATCLAUSE_DBNAME
  1392. 120  ERR_FORCLAUSE_VAR
  1393. 121  ERR_CONNECT_USER
  1394. 122  ERR_CONNECT_PWD
  1395. 123  ERR_CONNECT_USING
  1396. 124  ERR_REXX_NAME_TOO_LONG
  1397. 125  ERR_MISSING_ENDING_QUOTE
  1398. 126  ERR_STMT_KEYWORD
  1399. 127  ERR_END_OF_STMT
  1400.  
  1401.  
  1402. ΓòÉΓòÉΓòÉ 5.3.2. 200-299 Semantic Errors ΓòÉΓòÉΓòÉ
  1403.  
  1404. 201  ERR_AT_NOT_ALLOWED
  1405. 202  ERR_FOR_NOT_ALLOWED
  1406. 203  ERR_FOR_VALUE_INVALID
  1407. 204  ERR_SQLD_INVALID
  1408. 205  ERR_COMPOUND_NAME_TOO_LONG
  1409. 206  ERR_NAME_NOT_DECLARED
  1410. 207  ERR_DBNAME_NOT_DECLARED
  1411. 208  ERR_STMT_NOT_DECLARED
  1412. 209  ERR_NAME_ALREADY_DECLARED
  1413. 210  ERR_NAME_NOT_CURSOR
  1414. 211  ERR_NAME_NOT_STMT
  1415. 212  ERR_NAME_NOT_DB
  1416. 213  ERR_STMT_NOT_PREPARED
  1417. 214  ERR_CURSOR_NOT_OPENED
  1418. 215  ERR_DBNAME_INVALID
  1419. 216  ERR_SELECT_NOT_ALLOWED
  1420. 217  ERR_NOT_SELECT_STMT
  1421. 218  ERR_BIND_VARS_NOT_ALLOWED
  1422. 219  ERR_INTO_VARS_NOT_ALLOWED
  1423. 220  ERR_FETCH_LIST_TOO_LONG
  1424. 221  ERR_WRONG_NUM_BIND_VALUES
  1425. 222  ERR_CURSOR_OPEN
  1426.  
  1427.  
  1428. ΓòÉΓòÉΓòÉ 5.3.3. 900-999 Fatal Errors ΓòÉΓòÉΓòÉ
  1429.  
  1430. 901  ERR_NO_MEMORY
  1431. 902  ERR_SESSION_NOT_FOUND
  1432. 903  ERR_STMTBLK_NOT_FOUND
  1433. 904  ERR_BAD_REXX_NAME
  1434. 905  ERR_REXXVAR_ERROR
  1435.