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!

How to TRUNCATE a table dynamically in a Stored Procedure?

JulaayiAug 19 2013 — edited Aug 19 2013

Hi everyone, How can I create a Procedure with dynamic sql to truncate a table name I pass by every time in Oracle? I am running the following query and nothing happens. It neither creates the procedure nor errors out.

CREATE OR REPLACE PROCEDURE TruncateTable(TableName IN VARCHAR2(50))

IS

BEGIN

SQLCmd VARCHAR(200);

BEGIN

SQLCmd := 'TRUNCATE TABLE ' || TableName;

EXECUTE IMMEDIATE SQLCmd;

END;

Could someone please help me?

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2013
Added on Aug 19 2013
2 comments
1,917 views