dbTalk Databases Forums  

UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
wfs
 
Posts: n/a

Default UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-19-2012 , 02:41 PM






Hi All,

has anyone got a working example of a SQL-PL dynamic cursor.

TIA

Bill

An unexpected token "FOR" was found following "c5')". Expected tokens
may include: "
OPEN c5".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
________________________________________
Doesn't Compile - UDB Linux v9.7
________________________________________
DECLARE v5_dyn_sql VARCHAR(254) DEFAULT '';
DECLARE c5 SYS_REFCURSOR;

SET v5_dyn_sql = 'select table_schem, table_name, column_name '
CONCAT ' from sysibm.sqlcolumns '
CONCAT ' where table_schem like 1 '
CONCAT ' and table_name like 2 '
CONCAT ' order by 1, 2, 3 '
CONCAT ' fetch first 500 rows only ';

OPEN c5 FOR v5_dyn_sql USING ip_schema_name, ip_table_name;
(the ip’s are INPUT PARAMETERS)

CLOSE c5;

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-20-2012 , 01:50 AM






On 2012-01-19 21:41, wfs wrote:
Quote:
Hi All,

has anyone got a working example of a SQL-PL dynamic cursor.

TIA

Bill

An unexpected token "FOR" was found following "c5')". Expected tokens
may include: "
OPEN c5".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
________________________________________
Doesn't Compile - UDB Linux v9.7
________________________________________
DECLARE v5_dyn_sql VARCHAR(254) DEFAULT '';
DECLARE c5 SYS_REFCURSOR;

SET v5_dyn_sql = 'select table_schem, table_name, column_name '
CONCAT ' from sysibm.sqlcolumns '
CONCAT ' where table_schem like 1 '
CONCAT ' and table_name like 2 '
CONCAT ' order by 1, 2, 3 '
CONCAT ' fetch first 500 rows only ';

OPEN c5 FOR v5_dyn_sql USING ip_schema_name, ip_table_name;
(the ip’s are INPUT PARAMETERS)

CLOSE c5;

Have you successfully compiled an example from the docs? (such as:

CREATE OR REPLACE PROCEDURE dept_query
IS
emp_refcur SYS_REFCURSOR;
v_empno emp.empno%TYPE;
v_ename emp.ename%TYPE;
BEGIN
OPEN emp_refcur FOR 'SELECT empno, ename FROM emp WHERE deptno = 30' ||
' AND sal >= 1500';
DBMS_OUTPUT.PUT_LINE('EMPNO ENAME');
DBMS_OUTPUT.PUT_LINE('----- -------');
LOOP
FETCH emp_refcur INTO v_empno, v_ename;
EXIT WHEN emp_refcur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_empno || ' ' || v_ename);
END LOOP;
CLOSE emp_refcur;
END

)

Reason I ask is that I could not make that compile out of the box, so I
assume that one need to do some configuration (enable some compability
mode?). I don't have time to look into it now, but I would focus on
getting one of the examples to work.


/Lennart

Reply With Quote
  #3  
Old   
Frederik Engelen
 
Posts: n/a

Default Re: UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-20-2012 , 05:30 AM



On Jan 20, 8:50*am, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com>
wrote:
Quote:
On 2012-01-19 21:41, wfs wrote:





Hi All,

has anyone got a working example of a SQL-PL dynamic cursor.

TIA

Bill

An unexpected token "FOR" was found following "c5')". Expected tokens
may include: "
OPEN c5".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
________________________________________
Doesn't Compile - UDB Linux v9.7
________________________________________
DECLARE v5_dyn_sql * * * * VARCHAR(254) * * * * * *DEFAULT '';
DECLARE c5 * * * * * * * * SYS_REFCURSOR;

SET v5_dyn_sql = 'select table_schem, table_name, column_name '
CONCAT ' from sysibm.sqlcolumns '
CONCAT ' where table_schem like 1 '
CONCAT ' and table_name like 2 '
CONCAT ' order by 1, 2, 3 '
CONCAT ' fetch first 500 rows only ';

OPEN c5 FOR v5_dyn_sql USING ip_schema_name, ip_table_name;
(the ip’s are INPUT PARAMETERS)

CLOSE c5;

Have you successfully compiled an example from the docs? (such as:

CREATE OR REPLACE PROCEDURE dept_query
IS
* * emp_refcur * * *SYS_REFCURSOR;
* * v_empno * * * * emp.empno%TYPE;
* * v_ename * * * * emp.ename%TYPE;
BEGIN
* * OPEN emp_refcur FOR 'SELECT empno, ename FROM emp WHERE deptno = 30' ||
* * * * ' AND sal >= 1500';
* * DBMS_OUTPUT.PUT_LINE('EMPNO * *ENAME');
* * DBMS_OUTPUT.PUT_LINE('----- * *-------');
* * LOOP
* * * * FETCH emp_refcur INTO v_empno, v_ename;
* * * * EXIT WHEN emp_refcur%NOTFOUND;
* * * * DBMS_OUTPUT.PUT_LINE(v_empno || ' * * ' || v_ename);
* * END LOOP;
* * CLOSE emp_refcur;
END

)

Reason I ask is that I could not make that compile out of the box, so I
assume that one need to do some configuration (enable some compability
mode?). I don't have time to look into it now, but I would focus on
getting one of the examples to work.

/Lennart- Hide quoted text -

- Show quoted text -
You probably need to take a look at the DB2_COMPATIBILITY_VECTOR
register variable.

--
Frederik Engelen

Reply With Quote
  #4  
Old   
wfs
 
Posts: n/a

Default Re: UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-20-2012 , 06:09 AM



On Jan 20, 2:50*am, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com>
wrote:
Quote:
On 2012-01-19 21:41, wfs wrote:





Hi All,

has anyone got a working example of a SQL-PL dynamic cursor.

TIA

Bill

An unexpected token "FOR" was found following "c5')". Expected tokens
may include: "
OPEN c5".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
________________________________________
Doesn't Compile - UDB Linux v9.7
________________________________________
DECLARE v5_dyn_sql * * * * VARCHAR(254) * * * * * *DEFAULT '';
DECLARE c5 * * * * * * * * SYS_REFCURSOR;

SET v5_dyn_sql = 'select table_schem, table_name, column_name '
CONCAT ' from sysibm.sqlcolumns '
CONCAT ' where table_schem like 1 '
CONCAT ' and table_name like 2 '
CONCAT ' order by 1, 2, 3 '
CONCAT ' fetch first 500 rows only ';

OPEN c5 FOR v5_dyn_sql USING ip_schema_name, ip_table_name;
(the ip’s are INPUT PARAMETERS)

CLOSE c5;

Have you successfully compiled an example from the docs? (such as:

CREATE OR REPLACE PROCEDURE dept_query
IS
* * emp_refcur * * *SYS_REFCURSOR;
* * v_empno * * * * emp.empno%TYPE;
* * v_ename * * * * emp.ename%TYPE;
BEGIN
* * OPEN emp_refcur FOR 'SELECT empno, ename FROM emp WHERE deptno = 30' ||
* * * * ' AND sal >= 1500';
* * DBMS_OUTPUT.PUT_LINE('EMPNO * *ENAME');
* * DBMS_OUTPUT.PUT_LINE('----- * *-------');
* * LOOP
* * * * FETCH emp_refcur INTO v_empno, v_ename;
* * * * EXIT WHEN emp_refcur%NOTFOUND;
* * * * DBMS_OUTPUT.PUT_LINE(v_empno || ' * * ' || v_ename);
* * END LOOP;
* * CLOSE emp_refcur;
END

)

Reason I ask is that I could not make that compile out of the box, so I
assume that one need to do some configuration (enable some compability
mode?). I don't have time to look into it now, but I would focus on
getting one of the examples to work.

/Lennart- Hide quoted text -

- Show quoted text -
No, I couldn't get the example in the manual to compile either, using
the 'OPEN xx FOR' syntax,

As someone else suggested, I'll check out the
DB2_COMPATABILITY_VECTOR, but at first glance, there appears to be no
options for SQL-PL, the nearest is for ORACLE PL/SQL compatability.

Thanks

Bill

Reply With Quote
  #5  
Old   
Frederik Engelen
 
Posts: n/a

Default Re: UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-20-2012 , 12:15 PM



On 20 jan, 13:09, wfs <wfs1... (AT) gmail (DOT) com> wrote:
Quote:
On Jan 20, 2:50*am, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com
wrote:









On 2012-01-19 21:41, wfs wrote:

Hi All,

has anyone got a working example of a SQL-PL dynamic cursor.

TIA

Bill

An unexpected token "FOR" was found following "c5')". Expected tokens
may include: "
OPEN c5".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
________________________________________
Doesn't Compile - UDB Linux v9.7
________________________________________
DECLARE v5_dyn_sql * * * * VARCHAR(254) * * * * * *DEFAULT '';
DECLARE c5 * * * * * * * * SYS_REFCURSOR;

SET v5_dyn_sql = 'select table_schem, table_name, column_name '
CONCAT ' from sysibm.sqlcolumns '
CONCAT ' where table_schem like 1 '
CONCAT ' and table_name like 2 '
CONCAT ' order by 1, 2, 3 '
CONCAT ' fetch first 500 rows only ';

OPEN c5 FOR v5_dyn_sql USING ip_schema_name, ip_table_name;
(the ip’s are INPUT PARAMETERS)

CLOSE c5;

Have you successfully compiled an example from the docs? (such as:

CREATE OR REPLACE PROCEDURE dept_query
IS
* * emp_refcur * * *SYS_REFCURSOR;
* * v_empno * * * * emp.empno%TYPE;
* * v_ename * * * * emp.ename%TYPE;
BEGIN
* * OPEN emp_refcur FOR 'SELECT empno, ename FROM emp WHERE deptno = 30' ||
* * * * ' AND sal >= 1500';
* * DBMS_OUTPUT.PUT_LINE('EMPNO * *ENAME');
* * DBMS_OUTPUT.PUT_LINE('----- * *-------');
* * LOOP
* * * * FETCH emp_refcur INTO v_empno, v_ename;
* * * * EXIT WHEN emp_refcur%NOTFOUND;
* * * * DBMS_OUTPUT.PUT_LINE(v_empno || ' * * ' || v_ename);
* * END LOOP;
* * CLOSE emp_refcur;
END

)

Reason I ask is that I could not make that compile out of the box, so I
assume that one need to do some configuration (enable some compability
mode?). I don't have time to look into it now, but I would focus on
getting one of the examples to work.

/Lennart- Hide quoted text -

- Show quoted text -

No, I couldn't get the example in the manual to compile either, using
the 'OPEN xx FOR' syntax,

As someone else suggested, I'll check out the
DB2_COMPATABILITY_VECTOR, but at first glance, there appears to be no
options for SQL-PL, the nearest is for ORACLE PL/SQL compatability.

Thanks

Bill
SYS_REFCURSOR looks to be PL/SQL, not SQL-PL, so I'd take a look at
that variable.

--
Frederik Engelen

Reply With Quote
  #6  
Old   
bill schofield
 
Posts: n/a

Default Re: UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-20-2012 , 12:27 PM



On Jan 20, 1:15*pm, Frederik Engelen <engelenfrede... (AT) gmail (DOT) com>
wrote:
Quote:
On 20 jan, 13:09, wfs <wfs1... (AT) gmail (DOT) com> wrote:





On Jan 20, 2:50*am, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com
wrote:

On 2012-01-19 21:41, wfs wrote:

Hi All,

has anyone got a working example of a SQL-PL dynamic cursor.

TIA

Bill

An unexpected token "FOR" was found following "c5')". Expected tokens
may include: "
OPEN c5".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79
________________________________________
Doesn't Compile - UDB Linux v9.7
________________________________________
DECLARE v5_dyn_sql * * * * VARCHAR(254) * * * * **DEFAULT '';
DECLARE c5 * * * * * * * * SYS_REFCURSOR;

SET v5_dyn_sql = 'select table_schem, table_name, column_name '
CONCAT ' from sysibm.sqlcolumns '
CONCAT ' where table_schem like 1 '
CONCAT ' and table_name like 2 '
CONCAT ' order by 1, 2, 3 '
CONCAT ' fetch first 500 rows only ';

OPEN c5 FOR v5_dyn_sql USING ip_schema_name, ip_table_name;
(the ip’s are INPUT PARAMETERS)

CLOSE c5;

Have you successfully compiled an example from the docs? (such as:

CREATE OR REPLACE PROCEDURE dept_query
IS
* * emp_refcur * * *SYS_REFCURSOR;
* * v_empno * * * * emp.empno%TYPE;
* * v_ename * * * * emp.ename%TYPE;
BEGIN
* * OPEN emp_refcur FOR 'SELECT empno, ename FROM emp WHERE deptno = 30' ||
* * * * ' AND sal >= 1500';
* * DBMS_OUTPUT.PUT_LINE('EMPNO * *ENAME');
* * DBMS_OUTPUT.PUT_LINE('----- * *-------');
* * LOOP
* * * * FETCH emp_refcur INTO v_empno, v_ename;
* * * * EXIT WHEN emp_refcur%NOTFOUND;
* * * * DBMS_OUTPUT.PUT_LINE(v_empno || ' * * ' || v_ename);
* * END LOOP;
* * CLOSE emp_refcur;
END

)

Reason I ask is that I could not make that compile out of the box, soI
assume that one need to do some configuration (enable some compability
mode?). I don't have time to look into it now, but I would focus on
getting one of the examples to work.

/Lennart- Hide quoted text -

- Show quoted text -

No, I couldn't get the example in the manual to compile either, using
the 'OPEN xx FOR' syntax,

As someone else suggested, I'll check out the
DB2_COMPATABILITY_VECTOR, but at first glance, there appears to be no
options for SQL-PL, the nearest is for ORACLE PL/SQL compatability.

Thanks

Bill

SYS_REFCURSOR looks to be PL/SQL, not SQL-PL, so I'd take a look at
that variable.

--
Frederik Engelen- Hide quoted text -

- Show quoted text -
I'll check it out. All I want to do is create a dynamic SQL-PL cursor
using a parameterized query. Strange that only example in the IBM
manual(s) is for PL/SQL.

Reply With Quote
  #7  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-20-2012 , 02:34 PM



On 2012-01-20 19:27, bill schofield wrote:
[...]
Quote:
I'll check it out. All I want to do is create a dynamic SQL-PL cursor
using a parameterized query. Strange that only example in the IBM
manual(s) is for PL/SQL.
Bill, what version/fixpak are you running?

#> db2level
#> db2licm -l

/Lennart

Reply With Quote
  #8  
Old   
Frederik Engelen
 
Posts: n/a

Default Re: UDB v9.7 SQL-PL Dynamic Cursor Doesn't Compile - 01-20-2012 , 04:30 PM



On 20 jan, 21:34, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com>
wrote:
Quote:
On 2012-01-20 19:27, bill schofield wrote:
[...]

I'll check it out. All I want to do is create a dynamic SQL-PL cursor
using a parameterized query. Strange that only example in the IBM
manual(s) is for PL/SQL.

Bill, what version/fixpak are you running?

#> db2level
#> db2licm -l

/Lennart
Would this suit you? I would be hesitant to call it dynamic (that
would use EXECUTE IMMEDIATE) but given your example I think this might
be what you're looking for:

CREATE PROCEDURE TEST (tabpattern varchar(255))
LANGUAGE SQL
BEGIN
FOR t as select tabname as matchedtabname from syscat.tables where
tabname like tabpattern
DO
INSERT INTO TEST (TESTTABNAME)
VALUES (matchedtabname);
END FOR;
END@

CALL TEST('TAB%')@

--
Frederik Engelen

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.