Insert by Using RECORD Type Variable : Insert « PL SQL Programming « Oracle PL/SQL Tutorial






SQL>
SQL> -- create demo table
SQL> create table Employee(
  2    ID                 VARCHAR2(4 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 VARCHAR2) is
  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.








24.10.Insert
24.10.1.Use PL/SQL to insert data to table
24.10.2.Insert data in PL/SQL block
24.10.3.How INSERTs work with PL/SQL
24.10.4.Use Declared variables in SQL statements
24.10.5.Use LOOP to insert data to a table with loop counter variable
24.10.6.Add a row to the classes table, using the values of the variables
24.10.7.Use PL/SQL variables with insert statement
24.10.8.A Safe INSERT Statement
24.10.9.Insert by Using RECORD Type Variable
24.10.10.Insert values using PL/SQL literals and variables
24.10.11.Insert value to product and productcategory with stored procedure