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 > Get query error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-11, 12:54
ricci ricci is offline
Registered User
 
Join Date: Sep 2011
Posts: 39
Red face Get query error

Hi.

I wonder if anybody knows if is any variable in db2 where catche the query that is excecuting, I mean for exemple:
If I execute this:

SELEC * FROM schema.table;

In data studio in SQL Reults send me this:

selec * from schema.table
An unexpected token "selec" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "SELECT".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.11.69


The word "selec" has to come from any part and I want to get it just like I can get SQLCODE. I've looked for it en SQLCA but I haven't foun it. Please help.

Regards.
Reply With Quote
  #2 (permalink)  
Old 09-27-11, 13:45
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ricci View Post
I've looked for it en SQLCA but I haven't foun it.
Look again. You need sqlerrmc.
Reply With Quote
  #3 (permalink)  
Old 09-27-11, 18:21
ricci ricci is offline
Registered User
 
Join Date: Sep 2011
Posts: 39
Thanks

Thanks a lot for for your help, but i wonder if I can get here the error and insert into 'x' table, i'm working on CML. According what I see it's for java, isn't it?.

Regards.
Reply With Quote
  #4 (permalink)  
Old 09-27-11, 22:24
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I understand some of the words, but not the entire sentence. Could you please rephrase?
Reply With Quote
  #5 (permalink)  
Old 09-28-11, 11:20
ricci ricci is offline
Registered User
 
Join Date: Sep 2011
Posts: 39
I've tried to use it, I mean I wanna catch error when ocurrs. till this momment I cath the SQLCODE somethig like this:

BEGIN ATOMIC
DECLARE UNDO HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND
set v_ErrorCode = SQLCODE;

set v_TransactionDate = CURRENT TIMESTAMP;

INSERT INTO NOM_ESQ.BOOKS(ID_BOOK, BOOK_TITLE, BOOK_PAGES) VALUES (p_IdBook, p_BookTitle, p_BookPages);

INSERT INT NOM_ESQ.BOOKS(BOOK_TITLE, BOOK_PAGES) VALUES ('LA CONSPIRACION', 588);

set v_ErrorCode = SQLCODE;
END;

When I execute this I get an error from the sentence INT instead or INTO, till this moment I catch the SQLCODE of the and insert into a bitacora table. But I gotta catch also the sentence which makes the error.
Reply With Quote
  #6 (permalink)  
Old 09-28-11, 13:13
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Try this:

Code:
    DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
       BEGIN
          GET DIAGNOSTICS EXCEPTION 1 MESSAGE_TEXT_OUT = MESSAGE_TEXT;
          SELECT SQLSTATE, SQLCODE INTO SQLSTATE_OUT, SQLCODE_OUT
              FROM SYSIBM.SYSDUMMY1;
       END;
ANdy
Reply With Quote
  #7 (permalink)  
Old 09-29-11, 11:28
ricci ricci is offline
Registered User
 
Join Date: Sep 2011
Posts: 39
Question

First of all, thank for your support but I still got a troble. I've tried to use it in this way, but doesn't insert the description of the error, maybe I'm not settingo something, this is the code.

Code:
BEGIN ATOMIC		
     DECLARE UNDO HANDLER FOR SQLEXCEPTION
     set v_codError = SQLCODE;
     set v_fechaProceso = CURRENT TIMESTAMP;
     GET DIAGNOSTICS EXCEPTION 1 MESSAGE_TEXT_OUT = MESSAGE_TEXT;
END;	

-- Sentences to execute
    INSERT INTO NOM_ESQ.BOOKS(ID_BOOK, BOOK_TITLE, BOOK_PAGES) VALUES (p_IdBook, p_BookTitle, p_BookPages);

INSERT INT NOM_ESQ.BOOKS(BOOK_TITLE, BOOK_PAGES) VALUES ('LA CONSPIRACION', 588);
-- End sentences
		
B:			
     Insert into NOM_ESQ.EXCEPCION_FELIZ (fecha_excepcion, codigo_error,   mensaje_error, sentencia)
     values (v_fechaProceso, v_codError, SYSPROC.SQLERRM(v_codError), MESSAGE_TEXT_OUT);

END
Reply With Quote
  #8 (permalink)  
Old 09-29-11, 11:32
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
If you read the documentation on GET DIAGNOSTICS, it states it gets the info from the previous SQL statement. For this reason it has to be the first statement in the handler.

Andy
Reply With Quote
  #9 (permalink)  
Old 09-29-11, 13:14
ricci ricci is offline
Registered User
 
Join Date: Sep 2011
Posts: 39
You´re rigth actually the issue was that I make the set of v_coderror, finally I get what I want.

Thanks a lot for your help.
Regards.
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