Insert by Using RECORD Type Variable

SQL>
SQL> -- create demo table
SQL> create table Employee(
  2    ID                 VARCHAR2(BYTE),
  3    First_Name         VARCHAR2(10 BYTE),
  4    City               VARCHAR2(10 BYTE)
  5  )
  6  /

Table created.

SQL>
SQL>
SQL> create or replace procedure p_create(i_deptNo VARCHAR, i_dName VARCHAR2, i_loc VARCHAR2is
  2  v_row employee%ROWTYPE;
  3  begin
  4      if length(i_dName)>10 then
  5          raise_application_error(-20999,'first name is too long');
  6      end if;
  7
  8      v_row.id:=i_deptNo;
  9      v_row.first_Name:=i_dName;
 10      v_row.city:=i_loc;
 11
 12      insert into employee values v_row;
 13  end;
 14  /

Procedure created.

SQL>
SQL> call p_create ('01','new','new');

Call completed.

SQL>
SQL> select from employee;

ID   FIRST_NAME CITY
---- ---------- ----------
01   new        new

SQL>
SQL>
SQL> -- clean the table
SQL> drop table Employee
  2  /

Table dropped.
arrow
arrow
    全站熱搜

    Somebaby 發表在 痞客邦 留言(0) 人氣()