Dynamic SQL

From: Robert <rtennys_at_hotmail.com>
Date: 6 Jun 2003 07:14:31 -0700
Message-ID: <6e21d614.0306060614.3bd894f1_at_posting.google.com>


Below is a simple example of what I'm trying to accomplish. It's not working unfortunately. I don't think that EXECUTE IMMEDIATE likes the INTO to be in the sql statement. I think it wants something like EXECUTE IMMEDIATE sql_statement INTO varname. The problem is that 'varname' is what needs to be dynamic. Any ideas?

DECLARE
 tmp1 VARCHAR(50);
 tmp2 VARCHAR(50);
BEGIN
 FOR loop_counter IN 1..2
 LOOP
   EXECUTE IMMEDIATE 'SELECT ''blah'' INTO tmp' || loop_counter || ' FROM DUAL';
 END LOOP;
 DBMS_OUTPUT.PUT_LINE(tmp1);
 DBMS_OUTPUT.PUT_LINE(tmp2);
END; Received on Fri Jun 06 2003 - 16:14:31 CEST

Original text of this message