Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Truncate in stored procedure

Re: Truncate in stored procedure

From: Connor McDonald <mcdonald.connor.cs_at_bhp.com.au>
Date: Wed, 30 Dec 1998 13:41:00 +0800
Message-ID: <3689BCEC.2515@bhp.com.au>


Diane wrote:
>
> In article <76bdjh$7bs$1_at_nnrp1.dejanews.com>, andrewf_at_jaredgroup.com
> writes
> >I was creating a simple procedure,
> >
> >Create procedure p_truncate
> >as
> >begin
> > truncate table employee;
> >end;
> >
> >and got compilation error. It seems the pl/sql does not recognize the Truncate
> >syntax. Should I change some configure parms or other solutions?
> >
> >-----------== Posted via Deja News, The Discussion Network ==----------
> >http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
> What is the syntax error you are getting?
> It may be because the privilege to truncate a table has not been granted
> directly to the procedure owner or to the procedure executor.
> If truncate privilege is granted via a role it will not be possible to
> truncate in a procedure.
> We have a number of procedures which truncate partitions in tables so it
> is possible to do it. The stored procedure is owned by and executed by
> the table owner in all cases.
> --
> Diane

truncate is DDL and thus not permitted in PL/SQL...Use dbms_sql..

create or replace procedure do_trunc(p_table varchar2) is   c integer := dbms_sql.open_cursor;
  d integer;
begin
  dbms_sql.parse('truncate table '||p_table,dbms_sql.native);   d := dbms_sql.execute(c);
  dbms_sql.close_cursor(c);
exception when others then
  dbms_sql.close_cursor(c);
  raise;
end;

--



Connor McDonald
BHP Information Technology
Perth, Western Australia
"The difference between me and a madman is that I am not mad" Received on Tue Dec 29 1998 - 23:41:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US