0% found this document useful (0 votes)
17 views2 pages

Professor

The document demonstrates using a cursor to insert a new record into the professor table. It defines a cursor to select from the professor table, declares variables to hold the column values, prompts the user to enter values, inserts the new record, and then confirms it was added by selecting all records from the table. It also shows creating an object type called eemploy, creating a table to store it, and inserting a sample record.

Uploaded by

anon-80109
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Professor

The document demonstrates using a cursor to insert a new record into the professor table. It defines a cursor to select from the professor table, declares variables to hold the column values, prompts the user to enter values, inserts the new record, and then confirms it was added by selecting all records from the table. It also shows creating an object type called eemploy, creating a table to store it, and inserting a sample record.

Uploaded by

anon-80109
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Befor execution

SQL> select * from professor;

PNO PNAME DOB DOJ AGE


---------- -------------------- --------- --------- ----------
YEARS_OF_EXPERIENCE
-------------------
100 anand 09-MAY-86 20-MAY-06 24
2
SQL> ed cursor.sql;

declare
cursor cp is select * from professor;
name professor.pname%type;
no professor.pno%type;
cdob professor.dob%type;
cdoj professor.doj%type;
cage professor.age%type;
cyear professor.years_of_experience%type;
begin
name:='&professor_name';
no:='&professor_no';
open cp;
cdob:='&date_of_birth';
cdoj:='&date_of_joining';
cage:=round(months_between(sysdate,cdob)/12);
cyear:=round(months_between(sysdate,cdoj)/12);
insert into professor values(no,name,cdob,cdoj,cage,cyear);
close cp;
end;

SQL> @cursor.sql;
22 /
Enter value for professor_name: siva
old 10: name:='&professor_name';
new 10: name:='siva';
Enter value for professor_no: 143
old 11: no:='&professor_no';
new 11: no:='143';
Enter value for date_of_birth: 25-mar-1980
old 13: cdob:='&date_of_birth';
new 13: cdob:='25-mar-1980';
Enter value for date_of_joining: 25-jun-2001
old 14: cdoj:='&date_of_joining';
new 14: cdoj:='25-jun-2001';

PL/SQL procedure successfully completed.


After execution

SQL> select * from professor;

PNO PNAME DOB DOJ AGE


---------- -------------------- --------- --------- ----------
YEARS_OF_EXPERIENCE
-------------------
100 anand 09-MAY-86 20-MAY-06 24
2

143 siva 25-MAR-80 25-JUN-01 29


7

Creating a type

SQL> create type eemploy as object(empno number(10),empname varchar2(20),dname


varchar2(20));
2 /

Type created.

SQL> create table eemployee(emp eemploy,address varchar2(20));

Table created.

SQL> insert into eemployee values(eemploy(10,'swathi','IT'),'vadapalani');

1 row created.

SQL> select * from eemployee;

EMP(EMPNO, EMPNAME, DNAME)


--------------------------------------------------------------------------------
ADDRESS
--------------------
EEMPLOY(10, 'swathi', 'IT')
Vadapalani

You might also like