Kent,
Thanks for the response. I'll give it a shot today and then post back.
H
Main Topics
Browse All TopicsI'm familiar with how to write Oracle stored procedures. Would someone be willing to write an equivilant DB2 stored procedure for the following:
CREATE OR REPLACE PROCEDURE simple_usp(
p_DlrNumber NUMBER(4)) AS
--declare variables
v_DlrName VARCHAR2(45);
BEGIN
SELECT Dlr_Nme
INTO v_DlrName
FROM DealerTable
WHERE Dlr_Num = p_DlrNumber;
END;
/
This is a very simple procedure I realize but being visual and not being able to find a similar example in all of the DB2/stored proc documentation I've looked at I just need someone to break it down for me.
Thanks,
H
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Kent, I changed the table that I'm using because I know that the SELECT will result in only one record being returned. Here is what I tried as well as the error messages I'm getting. Any help on resolving would be great.
DROP PROCEDURE Crys_Pgm.Simple_usp;
CREATE PROCEDURE Crys_Pgm.Simple_usp
(IN p_OpNbr INTEGER,
OUT p_OpDescription VARCHAR(40))
LANGUAGE SQL
NOT DETERMINISTIC
INHERIT SPECIAL REGISTERS
P1: BEGIN
SELECT SESCSPL.OPS.OPSNAM
INTO p_OpDescription
FROM SESCSPL.OPS
WHERE SESCSPL.OPS.OPSID = p_OpNbr;
END P1
---Error Messages
END P1
[SQL0104] Token P1 was not valid. Valid tokens: DECLARE. Cause . . . . . : A syntax error was detected at token P1. Token P1 is not a valid token. A partial list of valid tokens is DECLARE. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token P1. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause.
CREATE PROCEDURE Crys_Pgm.Simple_usp
(IN p_OpNbr INTEGER,
OUT p_OpDescription VARCHAR(40))
LANGUAGE SQL
NOT DETERMINISTIC
INHERIT SPECIAL REGISTERS
P1: BEGIN
SELECT SESCSPL.OPS.OPSNAM
INTO p_OpDescription
FROM SESCSPL.OPS
WHERE SESCSPL.OPS.OPSID = p_OpNbr
[SQL0104] Token <END-OF-STATEMENT> was not valid. Valid tokens: ;. Cause . . . . . : A syntax error was detected at token <END-OF-STATEMENT>. Token <END-OF-STATEMENT> is not a valid token. A partial list of valid tokens is ;. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token <END-OF-STATEMENT>. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause.
DROP PROCEDURE Crys_Pgm.Simple_usp
[SQL0204] SIMPLE_USP in CRYS_PGM type *N not found. Cause . . . . . : SIMPLE_USP in CRYS_PGM type *N was not found. If this is an ALTER TABLE statement and the type is *N, a constraint or partition was not found. If this is not an ALTER TABLE statement and the type is *N, a function, procedure, or trigger was not found. If a function was not found, SIMPLE_USP is the service program that contains the function. The function will not be found unless the external name and usage name do not match exactly. Examine the job log for a message that gives more details on which function name is being searched for and the name that did not match. Recovery . . . : Change the name and try the request again. If the object is a node group, ensure that the DB2 Multisystem product is installed on your system and create a nodegroup with the CRTNODGRP CL command. If an external function was not found, be sure that the case of the EXTERNAL NAME on the CREATE FUNCTION statement exactly matches the case of the name exported by the service program.
Yup, I'm using an iSeries.
I tried creating the procedure again after taking out the INHERIT statement. These are the messages that were returned.
Thanks,
H
END P1
[SQL0104] Token P1 was not valid. Valid tokens: DECLARE. Cause . . . . . : A syntax error was detected at token P1. Token P1 is not a valid token. A partial list of valid tokens is DECLARE. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token P1. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause.
CREATE PROCEDURE Crys_Pgm.Simple_usp
(IN p_OpNbr INTEGER,
OUT p_OpDescription VARCHAR(40))
LANGUAGE SQL
NOT DETERMINISTIC
P1: BEGIN
SELECT SESCSPL.OPS.OPSNAM
INTO p_OpDescription
FROM SESCSPL.OPS
WHERE SESCSPL.OPS.OPSID = p_OpNbr
[SQL0104] Token <END-OF-STATEMENT> was not valid. Valid tokens: ;. Cause . . . . . : A syntax error was detected at token <END-OF-STATEMENT>. Token <END-OF-STATEMENT> is not a valid token. A partial list of valid tokens is ;. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token <END-OF-STATEMENT>. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause.
DROP PROCEDURE Crys_Pgm.Simple_usp
[SQL0204] SIMPLE_USP in CRYS_PGM type *N not found. Cause . . . . . : SIMPLE_USP in CRYS_PGM type *N was not found. If this is an ALTER TABLE statement and the type is *N, a constraint or partition was not found. If this is not an ALTER TABLE statement and the type is *N, a function, procedure, or trigger was not found. If a function was not found, SIMPLE_USP is the service program that contains the function. The function will not be found unless the external name and usage name do not match exactly. Examine the job log for a message that gives more details on which function name is being searched for and the name that did not match. Recovery . . . : Change the name and try the request again. If the object is a node group, ensure that the DB2 Multisystem product is installed on your system and create a nodegroup with the CRTNODGRP CL command. If an external function was not found, be sure that the case of the EXTERNAL NAME on the CREATE FUNCTION statement exactly matches the case of the name exported by the service program.
Okay, I got the procedure to compile but I had to do it through the SQL Script Editor in iSeries Navigator. I was initially trying it through the SQL tool used in Surveyor (product of Linoma Software). Go figure.
I appreciate the help.
One more question that is related...In Oracle you can do a DBMS_OUPUT.PUT_LINE to return messages or results. Is there a similar option available with DB2?
I don't think you can change a stored procedure on the iSeries, at least from what I've read and surmized in working with Navigator. As you've mentioned, your only apparent option is to delete the procedure and then create it again. I wondered about this also as Oracle has the option of 'CREATE OR REPLACE...' when writing procedures or functions which saves you a step.
H
There must be tools out there so that you can change a procedure and under the covers it does the DROP and CREATE. The problem with using iSeries navigator is I can copy/paste my SQL statement but I have to redefine all my parameters again which a waste of a developer's time and we all know how valuable our time is.
Business Accounts
Answer for Membership
by: KdoPosted on 2005-04-01 at 13:53:20ID: 13684778
It's similar, but different. :)
DROP PROCEDURE simple_usp;
CREATE PROCEDURE simple_usp
(IN p_dlrNumber integer,
OUT p_DlrNumber VARCHAR (45) )
LANGUAGE SQL
NOT DETERMINISTIC
INHERIT SPECIAL REGISTERS
--------------------------
-- SQL Stored Procedure
--------------------------
P1: BEGIN
-- Insert SQL statements here
SELECT Dlr_Nme
INTO p_DlrNumber
FROM DealerTable
WHERE Dlr_Num = p_DlrNumber
END P1
Good Luck,
Kent