Skip to content
Advertisement

How to create 2 tables using EXECUTE IMMEDIATE only once?

I have a requirement where I need to create 2 tables inside a PLSQL block. Currently we’re using EXECUTE IMMEDIATE. Now the issue is I need to create 2 tables but I can use EXECUTE IMMEDIATE only once.

Are there ways to create tables within PLSQL either by 1) without using EXECUTE IMMEDIATE or 2) create 2 tables inside a single usage of EXECUTE IMMEDIATE

I tried like below. and some trail and error combinations. but didnt help. Expecting like the below.

Advertisement

Answer

I admit it’s not very nice but you can run multiple execute immediate inside a plsql block in an execute immediate:

EDIT:

As per your comment, you can run the following.

Also, you may need to rethink your problem. Do you really need to create table? Can you not create the tables beforehand and just do simple insertion instead. You can circumvent dynamic SQL.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement