DBMS_SQL 包 ( 8i 后 建议用 Native Dynamic SQL 代替)

Using DBMS_SQL with a Parameterized DML Statement

create procedure insert_row(table_name varchar2,
       id varchar2,name varchar2,region number) is
    csr_id integer;
    stmt   varchar2(200);
    rows_added number;
begin
  -- 语句
  stmt := 'insert into '||table_name||
          ' values (:cid, :cname, :rid)';
  -- 开游标        
  csr_id := dbms_sql.open_cursor;
  
  -- 解析
  dbms_sql.parse(csr_id, stmt, dbms_sql.native);
  
  -- 绑定变量
  dbms_sql.bind_variable(csr_id, ':cid',id);
  dbms_sql.bind_variable(csr_id, ':cname',name);
  dbms_sql.bind_variable(csr_id, ':rid',region);
  
  -- 执行
  rows_added := dbms_sql.execute(csr_id);
  
  -- 关闭
  dbms_sql.close_cursor(csr_id);
  
  dbms_output.put_line(rows_added||' row added');
end;          



你可能感兴趣的:(Oracle)