| |
|
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.
|
 |

08-10-11, 19:06
|
|
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.
|

08-10-11, 22:02
|
|
:-)
|
|
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.
|
|

08-11-11, 02:02
|
|
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.
|

08-11-11, 03:23
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
|
|

08-11-11, 04:59
|
|
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
|

08-11-11, 10:29
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by przytula_guy
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
|
|

08-12-11, 00:56
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by tonkuma
|
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
|
|

08-12-11, 01:54
|
|
Registered User
|
|
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
|
|
__________________
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
|
|

08-12-11, 05:14
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by przytula_guy
|
Hello sir, Thank you for this link,i will try this and i will write again if i have doubt.more power to you....
|
|

08-12-11, 08:10
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
jemz, sir, how do you know all responders are male?
|
|

08-12-11, 08:45
|
|
Super Moderator
|
|
Join Date: Aug 2001
Location: UK
Posts: 4,534
|
|
Quote:
Originally Posted by db2girl
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.
|
|

08-12-11, 09:06
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
|
|

08-12-11, 11:48
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by db2girl
jemz, sir, how do you know all responders are male?
|
huh?
because they use male name... 
|
|

08-12-11, 12:06
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by przytula_guy
|
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...
|
|

08-13-11, 03:27
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by tonkuma
|
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|