Post

Oracle plsql DDL in procedure

Oracle plsql DDL in procedure

This one catches people out the first time: you can’t run DDL statements like TRUNCATE or CREATE TABLE directly inside a PL/SQL procedure — you get a compilation error. The workaround is EXECUTE IMMEDIATE, which runs the statement dynamically at runtime. Works for any DDL you need to automate.

  • Running DDL like truncate in procedure
1
2
3
4
5
create or replace procedure proc_truncate_table
is
begin
 execute immediate 'truncate table data_table';
end;
  • calling the above procedure
1
CALL proc_truncate_table ();
This post is licensed under CC BY 4.0 by the author.