MySQL Forums
Forum List  »  General

Re: Procedure is not working
Posted by: irek kordirko
Date: April 17, 2012 09:03AM

This cannot be done in that way.
You need to use dynamic SQL (prepare statement).

Try this code:

OPEN cur1;

read_loop: LOOP
    set done = 0;
    FETCH cur1 INTO v_Table_Name;
    IF done = 1 THEN 
       LEAVE read_loop;
    END IF;

    Set v_Datei = CONCAT('/home/irko/xxxx','/',v_Table_Name,'.csv');

    set @v_sql = concat( 'SELECT * FROM `', v_Table_Name, '` ' );
    set @v_sql = concat( @v_sql, 'INTO OUTFILE ''', v_Datei , ''' ' );
    set @v_sql = concat( @v_sql, 'FIELDS TERMINATED BY '';'' LINES TERMINATED BY ''\\n''');

    PREPARE stmt1 FROM @v_sql;
    EXECUTE stmt1;
    DEALLOCATE PREPARE stmt1;

END LOOP;

CLOSE cur1;

Options: ReplyQuote


Subject
Written By
Posted
April 17, 2012 05:33AM
Re: Procedure is not working
April 17, 2012 09:03AM
April 19, 2012 08:17PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.