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 > Informix > Informix 10 with stored procedure with dynamic sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-11, 08:44
pgerbaux pgerbaux is offline
Registered User
 
Join Date: Oct 2005
Posts: 4
Informix 10 with stored procedure with dynamic sql

Hi, i am a new bee in Informix SQL.

I have an error when i try to run my stored procedure : it give me a syntax error but i don't see why!

CREATE PROCEDURE recupmaxdate (db_srv char(14), stationnumber char(2))
RETURNING char(15);
DEFINE resultdate char(15);
DEFINE form_sql CHAR(250);
LET form_sql= "select max(datearrival) into resultdate FROM " ||db_srv|| ";
prepare xsql from form_sql;
declare xcur cursor for xsql;
OPEN xcur;
FETCH xcur into resultdate;
CLOSE xcur;
FREE xcur;
FREE xsql;
RETURN resultdate;
END PROCEDURE;


Does anyone has any idea?
Help Please !!!
Reply With Quote
  #2 (permalink)  
Old 03-30-11, 09:17
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
The following is wrong:
LET form_sql= "select max(datearrival) into resultdate FROM " ||db_srv|| ";
It should be:
LET form_sql= "select max(datearrival) into resultdate FROM " ||db_srv;
or
LET form_sql= "select max(datearrival) into resultdate FROM " ||db_srv|| "";

If you run the query in dbaccess you get error:
282: Found a quote for which there is no matching quote.
and if you press "modify", the cursor jumps to the position of the error.
__________________
WilhelmW
IBM Certified Database Associate

wilhelmw.de - www.isr.de
Reply With Quote
  #3 (permalink)  
Old 03-30-11, 09:45
pgerbaux pgerbaux is offline
Registered User
 
Join Date: Oct 2005
Posts: 4
Hi informixWilli.
Thanks for your help but the problem is not resolved.
i have replaced the line :

LET form_sql= "select max(datearrival) into resultdate FROM " ||db_srv|| ";

by this one :

LET form_sql= "select max(datearrival) FROM " ||db_srv;

So :

CREATE PROCEDURE recupmaxdate (db_srv char(14), stationnumber char(2))
RETURNING char(15);
DEFINE resultdate char(15);
DEFINE form_sql CHAR(250);
LET form_sql= "select max(datearrival) FROM " ||db_srv;
prepare xsql from form_sql;
declare xcur cursor for xsql;
OPEN xcur;
FETCH xcur into resultdate;
CLOSE xcur;
FREE xcur;
FREE xsql;
RETURN resultdate;
END PROCEDURE;

But i always have the following error : 201 A syntax error has occurred et the cursor jumps to the line :

prepare xsql from form_sql;
Reply With Quote
  #4 (permalink)  
Old 03-30-11, 09:51
pgerbaux pgerbaux is offline
Registered User
 
Join Date: Oct 2005
Posts: 4
I think that "PREPARE xxx FROM xxx" is not authorized!
Is it possible?
I have IDS10.0.
Reply With Quote
  #5 (permalink)  
Old 03-31-11, 01:06
pgerbaux pgerbaux is offline
Registered User
 
Join Date: Oct 2005
Posts: 4
POST CLOSED without success!

For information :

"Dynamic SQL in SP is introduced in IDS 11.5; and looks like you are trying using 10.0. That explains why your syntax is not recognized. "

It's a response from a expert of IBM.
Reply With Quote
  #6 (permalink)  
Old 03-31-11, 02:35
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
Thats right!

You should think about migration to 11.50/11.70 because there are a lot of new features and 10.00 is out of support!
__________________
WilhelmW
IBM Certified Database Associate

wilhelmw.de - www.isr.de
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