Simple usage of the oracle execute immediate

Create  or  Replace  Procedure proc_test (
 - Parameter Area 
)
 IS  
- variable region 
    - SQL script 
    v_sql VARCHAR2 ( 2000 ): = '' ;
     - Record the number of students 
    v_num Number ;
 the begin 
- execution region

    - the Execute load immediate Usage 1: execute sql statement immediately 
    v_sql: =  ' the Create or the replace the SELECT AS View MyView the above mentioned id, name from Student ' ;
     the Execute load immediate v_sql;
    
    - - the Execute load immediate Usage 2: Execute the sql statement immediately, and assigned to a variable 
    v_sql: =  ' the SELECT COUNT (1) from Student ' ;
     the Execute load immediate v_sql INTO v_num;
    
    - Execute immediate usage 3: sql with parameters 
    v_sql: = ' SELECT * WHERE t.name from Student T =: =. 1 and t.age: 2 ' ; 
     Execute immediate v_sql the using ' zhangsan ' , 23 is ;
    
end proc_test;
/

 

Guess you like

Origin www.cnblogs.com/weiyi1314/p/11995848.html