Solved

truncate table in a package/proc

Posted on 2002-07-17
2
1,749 Views
Last Modified: 2012-05-05
What rights do I have to grant to a user to truncate a table in a package?

I have TRUNCATE TABLE table_name in a proc inside of a package. When I try to compile it, I get an error:

LINE/COL ERROR
-------- -----------------------------------------------------------------
363/12   PLS-00103: Encountered the symbol "TABLE" when expecting one of
         the following:
         := . ( @ % ;
         The symbol ":= was inserted before "TABLE" to continue.
0
Comment
Question by:jflemin
2 Comments
 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 50 total points
ID: 7160318
The "truncate table" command and all other DDL statements, are not supported directly in standard (static) PL\SQL.  You can use those statements in dynamic PL\SQL if the user either is the owner of the table, or has the appropriate privilege(s).  If you have Oracle8.1.5 or higher, you can use the "execute immediate..." syntax for dynamic PL\SQL.  If you have an older version, you need the slower and more complex syntax of the procedures/functions in the dbms_utl package.

Here is an example from one of my procedures to do a truncate using "execute immediate":
  execute immediate ('truncate table disabled_triggers');

Note that this works if the PL\SQl procedure is in the same schema as the table owner.  Otherwise the procedure owner may need the "alter any table" system privilege and that is not a privilege you want many users to have.
0
 
LVL 1

Author Comment

by:jflemin
ID: 7160342
I figured this out at the same time that you answered the question. It works. Thanks for your help!!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to recover a database from a user managed backup

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question