Writing Pl/SQL function

Write a PL/SQL fuction named say TRUN, which does the same work as the oracle predefined function "TRUNCATE".

Questions by csprusty

Showing Answers 1 - 6 of 6 Answers

sgbang

  • Jul 7th, 2008
 

Hi,

Please check out this function:

create or replace function trun(p_table_name varchar2) return number as
begin
execute immediate ' truncate table '|| p_table_name;
return 0 ;
end;
 /

How to execute example:


declare
return_int number;
begin
return_int:=trun('emp');                                      --emp is a dummy table i used
dbms_output.put_line('return is :'||return_int);  --return_int should return 0
end;
/

Hope this is helpful

ajaz_11i

  • Jul 9th, 2008
 

It will truncate/delete all the rows in the table emp very fast as compared of delete command, but the table must have no Foriegn key
Mr. Ajaz Ahmad Kumar

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions