0

i want to create funtion that truncate all user objects, this is my script

CREATE OR REPLACE Function Truncate_user ( name_in IN varchar2 )
return number 
is
cnumber number;
v_str1 varchar2(200) := null;
cursor get_sql is
select
'drop '||object_type||' '||owner||'. '|| object_name|| DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS PURGE') v_str1
from DBA_objects
where object_type in ('TABLE','VIEW','PACKAGE','TYPE','PROCEDURE','FUNCTION','TRIGGER','SEQUENCE','SYNONYM') 
AND owner=name_in
order by object_type,object_name;
begin
open get_sql;
loop
fetch get_sql into v_str1;
if get_sql%notfound
then cnumber :=0; 
end if;

execute immediate v_str1;
end loop;
RETURN 1;
close get_sql;
end;
/

after the execution i got these errors

Erreur(7,1): PL/SQL: SQL Statement ignored
Erreur(9,6): PL/SQL: ORA-00942: Table ou vue inexistante

but when i execute this code without make a function ,the operation is done!

1
  • 1
    You get an error on execution of the function, or when you compile it? Commented Apr 7, 2016 at 13:25

2 Answers 2

1

Your user does not have the priviliges to access DBA_OBJECTS

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe there are objects that requires quoted identifiers (e.g. using lowercase letters), try

select 'drop '||object_type||' '||owner||'. "'|| object_name||'"'|| ...

1 Comment

There's also an extra space, but the error line numbers indicate it's a compile time error - failing on the cursor select - not at runtime on execution of the dynamic SQL. Including the quotes is a good idea anyway, of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.