Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Monday 10 September 2018

Writing Dynamic Insert in Oracle

plsql program to insert data dynamically at runtime by taking input from the user





declare

val1 number := &Enter_value;

val2 varchar2(20) := '&Enter';
Tab_Name varchar2(50) := 'dynamic_value';
sql_stmt varchar2(2000);
begin
  sql_stmt := 'Insert into '||Tab_Name||'  values(:1 , :2)';
  execute immediate sql_stmt using val1,val2;
end;  

/*----------------------------------------------

In this procedure,
 we use bind variables to map the input variables at run time.
Table_name is not mapped using bind variables that's why i directly with the variable('Tab_Name').
Execute immediate is used to execute the sql statement dynamically
Using specifies a list  of input  and/or output bind arguments. The 
parameter mode defaults to IN if not specified.


-------------------------------------------------------------*/

No comments:

Post a Comment