Thursday, May 2, 2013

Delete row(s) using Execute Immediate

 Delete row(s) using Execute Immediate




Oracle PL/SQL supports Dynamic sql through which DML operations can be performed using bind variables.


You have a table called ab
SQL>desc ab;

SQL> desc ab;
 Name                                                                                Null?    Type
 ----------------------------------------------------------------------------------- -------- ------------
 ID                                                                                           NUMBER
 NAME                                                                                         VARCHAR2(20)



SQL> select * from ab;

        ID NAME
---------- ---------------
         2 hello world

Delete records from ab table using Execute Immediate/Dynamic SQL

--delcare variable of type that included in where clause
--declare another variable to hold sql statement. here insert
--assign value to  variable
--pass sql statement to execute immediate statement along with variable .

declare
n number:=1;
sql_stmt varchar2(250);begin
sql_stmt :='delete from  ab where id=:1';
n:=2;
execute immediate sql_stmt using n;end;


--Execute the above block of code
SQL> /

PL/SQL procedure successfully completed.
--test whether insert successful or not

SQL> select * from ab;
Tags:delete  from a Table using Execute Immediate,Execute Immediate for delete ,Execute Immediate with using variables, delete  data using dynamic sql, deleting data using Execute immediate,

















No comments:

Post a Comment