Solved

truncate table in a package/proc

Posted on 2002-07-17
2
1,746 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 34

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.

Join & Write a Comment

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now