UPDATE Table 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)
Name Null? Type
----------------------------------------------------------------------------------- -------- ------------
ID NUMBER
NAME VARCHAR2(20)
SQL> select * from ab;
ID NAME
---------- ---------------
2 hello
Update records in ab table using Execute Immediate/Dynamic SQL
--it has 2 columns declare 2 variables of same type
--declare another variable to hold sql statement. here insert
--assign values to 2 variables
--pass sql statement to execute immediate statement along with 2 variables .
declaren number:=1;
nm varchar2(20);
sql_stmt varchar2(250);
begin
sql_stmt :='update ab set name=:nm where id=:1';
n:=2;
nm:='hello world';
execute immediate sql_stmt using nm,n;
end;
--Execute the above block of code
SQL> /
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
--test whether insert successful or not
SQL> select * from ab;
SQL> select * from ab;
ID NAME
---------- ---------------
2 hello world
Tags:update Table using Execute Immediate,Execute Immediate for update ,Execute Immediate with using variables, update data using dynamic sql, updating data using Execute immediate,updating table data using Execute immediate,How to update data using Execute immediate, how to update data using dynamic sql.
No comments:
Post a Comment