If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > What's problem with the stored proc?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-05-04, 09:45
hiolgc hiolgc is offline
Registered User
 
Join Date: Mar 2004
Posts: 61
What's problem with the stored proc?

Hi there,

A stored proc as the following is created, but error is occured:

ADMIN.TEMP_TABLE_TEST: 17: [IBM][CLI Driver][DB2/6000] SQL0206N "A.RL_ID" is not valid in the context where it is used. LINE NUMBER=17. SQLSTATE=42703

What's problem with it?

Thanks,

Stored proc:

CREATE PROCEDURE ADMIN.TEMP_TABLE_TEST (IN wk_end_date timestamp)
DYNAMIC RESULT SETS 1
LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN


INSERT INTO ADMIN.TEMP_SARS
SELECT location_id, CONCAT (CONCAT (first_name, ' '), last_name) AS sar_name
FROM ADMIN.LOCATION_CONTACT rlc , ADMIN.CONTACT c
WHERE title_code = 'SAR' AND rlc.contact_id = c.contact_id;

DECLARE cursor1 CURSOR FOR

SELECT a.rl_id, a.sar_name
FROM ADMIN.TEMP_SARS a;

OPEN cursor1;

END P1
Reply With Quote
  #2 (permalink)  
Old 05-05-04, 10:08
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Try moving the declare cursor to right after the BEGIN statement.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 05-05-04, 10:23
hiolgc hiolgc is offline
Registered User
 
Join Date: Mar 2004
Posts: 61
I tried your suggestion and get the following error:

ADMIN.TEMP_TABLE_TEST: 10: [IBM][CLI Driver][DB2/6000] SQL0104N An unexpected token "ADMIN" was found following " INSERT INTO". Expected tokens may include: "JOIN". LINE NUMBER=10. SQLSTATE=42601

The proc now looks like this:

CREATE PROCEDURE ADMIN.TEMP_TABLE_TEST (IN wk_end_date timestamp)
DYNAMIC RESULT SETS 1
LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
DECLARE cursor1 CURSOR FOR

INSERT INTO ADMIN.TEMP_SARS
SELECT location_id, CONCAT (CONCAT (first_name, ' '), last_name) AS sar_name
FROM ADMIN.LOCATION_CONTACT rlc , ADMIN.CONTACT c
WHERE title_code = 'SAR' AND rlc.contact_id = c.contact_id;

SELECT a.rl_id, a.sar_name
FROM ADMIN.TEMP_SARS a;

OPEN cursor1;

END P1
Reply With Quote
  #4 (permalink)  
Old 05-05-04, 10:41
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Sorry, I meant move the entire declare cursor statement.

CREATE PROCEDURE ADMIN.TEMP_TABLE_TEST (IN wk_end_date timestamp)
DYNAMIC RESULT SETS 1
LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN

DECLARE cursor1 CURSOR FOR
SELECT a.rl_id, a.sar_name
FROM ADMIN.TEMP_SARS a;

INSERT INTO ADMIN.TEMP_SARS
SELECT location_id, CONCAT (CONCAT (first_name, ' '), last_name) AS sar_name
FROM ADMIN.LOCATION_CONTACT rlc , ADMIN.CONTACT c
WHERE title_code = 'SAR' AND rlc.contact_id = c.contact_id;

OPEN cursor1;

END P1
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 05-05-04, 10:58
hiolgc hiolgc is offline
Registered User
 
Join Date: Mar 2004
Posts: 61
I did as you suggested and get the following error:

ADMIN.TEMP_TABLE_TEST: 9: [IBM][CLI Driver][DB2/6000] SQL0206N "A.RL_ID" is not valid in the context where it is used. LINE NUMBER=9. SQLSTATE=42703
Reply With Quote
  #6 (permalink)  
Old 05-05-04, 11:11
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Can you check if the column is in the table

describe table ADMIN.TEMP_SARS

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #7 (permalink)  
Old 05-05-04, 11:15
hiolgc hiolgc is offline
Registered User
 
Join Date: Mar 2004
Posts: 61
The table was created as follows and the column does exist.

CREATE TABLE TEMP_SARS(
rl_id INTEGER NOT NULL,
sar_name VARCHAR (65) NOT NULL
);
Reply With Quote
  #8 (permalink)  
Old 05-05-04, 12:12
bmujeeb bmujeeb is offline
Registered User
 
Join Date: Mar 2004
Posts: 448
Please check with the describe statement.

regards,

mujeeb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On