Insert: Using A Record

Description: Insert by Using RECORD Type Variable.

-- create demo table
CREATE TABLE Employee(
ID                 VARCHAR2(4 BYTE),
First_Name         VARCHAR2(10 BYTE),
City               VARCHAR2(10 BYTE)
)
/
 
TABLE created.
 
 
 
CREATE OR REPLACE PROCEDURE p_create(i_deptNo VARCHAR, i_dName VARCHAR2, i_loc VARCHAR2) IS
v_row employee%ROWTYPE;
BEGIN
IF LENGTH(i_dName)>10 THEN
        raise_application_error(-20999,'first name is too long');
END IF;
 
v_row.id:=i_deptNo;
v_row.first_Name:=i_dName;
v_row.city:=i_loc;
 
INSERT INTO employee VALUES v_row;
END;
/
 
PROCEDURE created.
 
 
call p_create ('01','new','new');
Call completed.
 
 
SELECT * FROM employee;
 
ID   FIRST_NAME CITY
---- ---------- ----------
01   NEW        NEW
 
 
 
 -- clean the table
 DROP TABLE Employee
/
 
TABLE dropped.

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.