INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Stored procedure stuck in a loop

Stored procedure stuck in a loop

(OP)
The following procedure is stuck in a loop. All I am trying to do is read some columns from a table, load it in TEMP table and write it to a file. Can someone help me here?

{code}
drop procedure Proc_Test

CREATE PROCEDURE SVITTALAM.Proc_Test
                (OUT p_Cnt VARCHAR(4),
                OUT p_SQLSTATE VARCHAR(100)
                )
                LANGUAGE SQL
BEGIN
 
    DECLARE V_DYNAMIC VARCHAR(100) ;                     -- (2)
    DECLARE v_Tsql VARCHAR(100) ;
    DECLARE v_Tid VARCHAR(100) ;
    DECLARE SQLSTATE CHAR(5) DEFAULT '00000';    
    DECLARE v_SQLSTATE CHAR(5) DEFAULT '00000';                 -- (2)
    DECLARE cursor1 CURSOR with hold FOR
         SELECT ID,SQLTEXT FROM  test;--
        
    DECLARE CONTINUE HANDLER FOR SQLWARNING, SQLEXCEPTION, NOT FOUND
    SET p_SQLSTATE = SQLSTATE;
   
    DECLARE GLOBAL TEMPORARY TABLE Rslt (
     sql_id varchar(100),
     cnt Varchar(4),
     sql_state varchar(6)
     )
     on commit
     preserve rows
     not logged ;

    Open cursor1;
    A:
    Loop
        fetch cursor1 into v_Tid, v_Tsql;
    
            
        insert into session.Rslt values(v_Tsql, v_Tid, '0');
        commit;
        
        call sysproc.admin_cmd('export to c:\test\test.csv of del select * from session.Rslt') ;
            
    end loop A;
    
    close cursor1;
    
    drop table session.Rslt;
END
{code}

RE: Stored procedure stuck in a loop

What will cause the LOOP to terminate?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close