- How can I execute SQL statements in PLSQL stored procedures?
Use dynamic SQL Execution:Execute immediate
Select * FromEmp_temp;
Create Or Replace Procedure F_delete_rows (table_name In Varchar2 , Condition In Varchar2 Default Null ) As Where_clause Varchar2 ( 100 ): = ' Where ' | Condition; v_table Varchar2 ( 30 ); V_ SQL Varchar2 (100 ); /* * Name: f_calculate_dataitem * purpose: dynamically Delete table data * imput: table_name condition for deleting the condition table to which the data will be deleted * Author: -- Cici * createdate: -- 2012, 12, 30 * updatedate: --*************************************** ******************** */ Begin -- First make sure that the table actually exists; if not, raise an exception Select O. Object_name Into V_table From SYS. all_objects o Where O. Object_name = Upper (Table_name) And O. object_type = ' Table ' ; If Condition Is Null Then Where_clause: = Null ; End If ; If Table_name Is Not Null Then V_table: = Table_name; End If ; -- Spelling the dynamic SQL statement to be executed V_ SQL: = ' Delete from ' | V_table | Where_clause; -- Execute the delete statement. Execute Immediate v_ SQL; Exception When No_data_found Then Dbms_output.put_line ( ' Invalid table: ' | Table_name ); End ;