Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Creating Table using EXECUTE IMMEDIATE

User910243567Aug 27 2017 — edited Aug 30 2017

I have requirement to create table using EXECUTE IMMEDIATE in package. However table name needs to be dynamic using sysdate on daily basis.

e.g XXAA_TESTTBL_08272017 - Aug 27th

    XXAA_TESTTBL_08282017 - Aug 28th

Below Declare block creates table, how can i make the table name dynamic using SYSDATE.

DECLARE

   sqlstring VARCHAR2(2000);

BEGIN

   EXECUTE IMMEDIATE

   'CREATE TABLE XXAA_TESTTBL_1 AS SELECT * FROM AR.HZ_PARTIES WHERE 1=2'

   ;

EXCEPTION

WHEN OTHERS THEN

   DBMS_OUTPUT.PUT_LINE('Error: '||SQLERRM);

END;

This post has been answered by Frank Kulash on Aug 27 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2017
Added on Aug 27 2017
16 comments
3,792 views