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 > how to put error message

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-11, 19:06
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
how to put error message

Hi,


can you help me please,is it possible in the stored procedure to put error message or to print error message,example i want to find a certain employee id No. and it does not exist to the table employee then this will print that "Employee ID Does Not exist" else if the id is exist this will update the employee lastname.can you help me please on this, i don't have idea on this how to print error message and to search the employee i.d using the stored procedure.Thank you in advance.

Last edited by jemz; 08-10-11 at 19:13.
Reply With Quote
  #2 (permalink)  
Old 08-10-11, 22:02
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
A stored procedure runs on the database server; where do you expect it to print anything?

Use SIGNAL, RESIGNAL, or RAISE_ERROR() to report the condition to the client application, which can then print a message to the user. You can find examples in the manual.
Reply With Quote
  #3 (permalink)  
Old 08-11-11, 02:02
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
in developerswork there was an article (I am looking for) that documented how to execute a command from a stored proc for debugging purposes..
when I find the article, I will indicate the link..
http://www.ibm.com/developerworks/da.../0211yip4.html
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be

Last edited by przytula_guy; 08-11-11 at 02:05.
Reply With Quote
  #4 (permalink)  
Old 08-11-11, 03:23
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
How about this article in developerWorks?

Making Operating System Calls from SQL
Reply With Quote
  #5 (permalink)  
Old 08-11-11, 04:59
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
With 9.7, you can also do the following ...

Pl note, this is untested code.

Code:
CREATE OR REPLACE PROCEDURE proc1()
begin
DECLARE EMPNOTF CONDITION FOR SQLSTATE '40999' ;
DECLARE outfile  utl_file.file_type ;
DECLARE EXIT HANDLER FOR EMPNOTF
BEGIN
-- The three methods can be used with one another too
-- eg. use file output to record the output and the classic method to handle the error programatically
--
-- Classic method
--SIGNAL SQLSTATE '40999' SET MESSAGE_TEXT='Employee Not found'  ;
-- to the Std out
--CALL DBMS_OUTPUT.PUT_LINE('Employee Not found') ;
-- To a file
SET  outfile=utl_file.fopen('/tmp','spout.txt','w') ;
call utl_file.put_line(outfile,'Employee Not found') ;

END ;
SIGNAL SQLSTATE '40999' ;
END
@

set serveroutput on @

call proc1()  @

set serveroutput off @
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.

Last edited by sathyaram_s; 08-11-11 at 05:00. Reason: formatting
Reply With Quote
  #6 (permalink)  
Old 08-11-11, 10:29
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by przytula_guy View Post
in developerswork there was an article (I am looking for) that documented how to execute a command from a stored proc for debugging purposes..
when I find the article, I will indicate the link..
Yet Another Article on Advanced Scripting
Hi sir,Here is my stored procedure i get stuck on this,I don't know how. can you help me please how to do the for loop?is there a for loop in stored procedure i have not yet tried the loop controls in sp.please help me sir how to search the employee id so that i can update the table also to display message if does not exist.Thank you in advance.

Create procedure search(in emp_id varchar(5))

DYNAMIC RESULT SETS 1
LANGUAGE SQL

DECLARE MYCURSOR CURSOR WITH RETURN TO CLIENT FOR
DECLARE ID VARCHAR(5);

BEGIN

FETCH MY_CURSOR INTO ID;

IF ID = EMP_ID THEN

UPDATE LASTNAME FROM EMPLOYEE

WHERE EMP_ID = ID;

END IF;
END
Reply With Quote
  #7 (permalink)  
Old 08-12-11, 00:56
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by tonkuma View Post
How about this article in developerWorks?

Making Operating System Calls from SQL


sir can you help me in searching the employee id with the use of fetch and cursor with return for,i have no idea in combining this...Thank you in advance
Reply With Quote
  #8 (permalink)  
Old 08-12-11, 01:54
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
there are many samples in the doc
Looping statements in SQL procedures
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #9 (permalink)  
Old 08-12-11, 05:14
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by przytula_guy View Post
there are many samples in the doc
Looping statements in SQL procedures


Hello sir, Thank you for this link,i will try this and i will write again if i have doubt.more power to you....
Reply With Quote
  #10 (permalink)  
Old 08-12-11, 08:10
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
jemz, sir, how do you know all responders are male?
Reply With Quote
  #11 (permalink)  
Old 08-12-11, 08:45
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Quote:
Originally Posted by db2girl View Post
jemz, sir, how do you know all responders are male?
Easy on him/her

BTW, what language is this " Белла "
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #12 (permalink)  
Old 08-12-11, 09:06
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Reply With Quote
  #13 (permalink)  
Old 08-12-11, 11:48
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by db2girl View Post
jemz, sir, how do you know all responders are male?


huh?

because they use male name...
Reply With Quote
  #14 (permalink)  
Old 08-12-11, 12:06
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by przytula_guy View Post
there are many samples in the doc
Looping statements in SQL procedures

HI, Sir...

Can i ask something can i download the manuals just like the link that you give me,so that if i am not connecting to the internet i have a reference the manuals...can i download them all,please help me how to dowload the manuals?Thank you in advance...
Reply With Quote
  #15 (permalink)  
Old 08-13-11, 03:27
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by tonkuma View Post
How about this article in developerWorks?

Making Operating System Calls from SQL

sir, Here is my code i get problem on this in searching,please help me sir.Thank you in advance and I am hoping for your positive response.

CREATE PROCEDURE SEARCH_ID (IN EMP_ID CHAR(6),)
IN E_LASTNAME VARCHAR(30),
OUT MESSAGE VARCHAR(100))




BEGIN


FOR ROW_VAR AS CUR_SEARCH CURSOR FOR
IF EMPNO = EMP_ID
UPDATE LASTNAME FROM EMPLOYEE
WHERE EMPNO=EMP_ID;
FETCH FIRST 1 ROWS ONLY

SIGNAL SQLSTATE '80000' SET MESSAGE ='EMPLOYEE I.D DOES NOT EXIST';


END FOR;

END
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