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 > Stored Procedure Fetch first parameter dont work

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-14-10, 12:57
ZeroQool ZeroQool is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
Question Stored Procedure Fetch first parameter dont work

hello, i would like to use a parameter to control the fetch first rows. But the db2 system doesnt accept the command.

Code:
	CREATE PROCEDURE MOVEPGM.GETLIST(
IN PMAXRESULTS INTEGER
	) 
RESULT SETS 1                                
LANGUAGE SQL                                 
BEGIN                                        
DECLARE c1 CURSOR WITH RETURN FOR            
select * from table1 FETCH FIRST PMAXRESULTS ROWS ONLY; 
OPEN C1;
END ;

thanks

Last edited by ZeroQool; 08-14-10 at 13:08. Reason: forget quote
Reply With Quote
  #2 (permalink)  
Old 08-14-10, 13:04
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
And the question is?
Reply With Quote
  #3 (permalink)  
Old 08-14-10, 13:07
ZeroQool ZeroQool is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
Quote:
Originally Posted by n_i View Post
And the question is?
the create sp command doesnt work

exception: "PMAXRESULTS" isnt a valid parm

Quote:
SQL-Status: 42601
Vendorencode: -104
Nachricht: [SQL0104] Token PMAXRESULTS ungültig. Gültige Token: ROW ROWS. Ursache . . . . : Bei Token PMAXRESULTS wurde ein Syntaxfehler entdeckt. Token PMAXRESULTS ist kein gültiges Token. ROW ROWS ist eine Teilliste gültiger Token. Diese Liste geht davon aus, dass die Anweisung bis zu diesem Token korrekt ist. Es kann eine frühere Stelle in der Anweisung fehlerhaft sein, aber bis zu dieser Stelle scheint die Syntax gültig zu sein. Fehlerbeseitigung: Einen der folgenden Schritte durchführen und die Anforderung wiederholen: - SQL-Anweisung im Bereich des Token PMAXRESULTS überprüfen. Anweisung korrigieren. Der Fehler kann ein fehlendes Komma oder Anführungszeichen sein, er kann in einem falsch geschriebenen Wort oder in der Anordnung der Klauseln begründet sein. - Ist das fehlerhafte Token <ANWEISUNGSENDE>, die Anweisung korrigieren, da sie mit einer ungültigen Klausel endet.
Reply With Quote
  #4 (permalink)  
Old 08-14-10, 13:55
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
The fetch first clause cannot contain a variable when using static (embedded) SQL. You could create the entire cursor with dynamic SQL in order to use a variable.
__________________
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 08-14-10, 14:25
ZeroQool ZeroQool is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
Quote:
Originally Posted by Marcus_A View Post
The fetch first clause cannot contain a variable when using static (embedded) SQL. You could create the entire cursor with dynamic SQL in order to use a variable.
thanks! exist a performance different between dynamic and static?
Reply With Quote
  #6 (permalink)  
Old 08-14-10, 15:26
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by ZeroQool View Post
thanks! exist a performance different between dynamic and static?
There is some performance difference because you have to prepare the statement and then execute it. Also, I beleive that you will need to make all the other statements (open, fetch, etc) that refer to the cursor also be dynamic (unless there is some enhancement in a recent release of DB2 that I don't know about).

However, since most dynamic statements should already be in package cache from previous executions (if they are identical), a dynamic statement may not need to be re-compiled (to determine access plan) each time it is executed. Static (embedded) SQL statements are always compiled ahead of time when the SP is created (there is a package that is created along with the SP that contains the compiled SQL).

Overall, static SQL is usually faster, but the difference may not be significant. You should do testing to determine the difference if the transaction is critical.
__________________
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
  #7 (permalink)  
Old 08-14-10, 16:23
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ZeroQool View Post
the create sp command doesnt work

exception: "PMAXRESULTS" isnt a valid parm
This is not a question; this is a statement. What is your question?
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