SQL 8i Programs

Embed Size (px)

Citation preview

  • 8/14/2019 SQL 8i Programs

    1/38

    [email protected]

    Create a student database (rollno,name,tot_marks,trade).

    Write a PL/SQL program to create student details for each

    trade adding an extra field rank which includes the ranking

    details of each student. Also print top 3 rankers.

    create table student(rollno INT,name char(25),tot_marks number(10),trade char(25));

    create table IT(rollno INT,name char(25),tot_marks number(10),trade char(25),rank number(3));

    create table CS(rollno INT,name char(25),tot_marks number(10),trade char(25),rank number(3));

    declare

    rno INT;

    nam char(25);

    tot number(10);

    trd char(25);

    rnk number(3);

    mx number(10);

    cursor curr is select * from student;

    cursor cit is select * from IT;

    cursor ccs is select * from CS;

    i number(4);

    begin

    delete from IT;

    delete from CS;

    open curr;

    loop

    fetch curr into rno,nam,tot,trd;

    if(curr%found) then

    Page | 1

  • 8/14/2019 SQL 8i Programs

    2/38

    [email protected]

    if trd='IT' then

    insert into IT values(rno,nam,tot,trd,rnk);

    elsif trd='CS' then

    insert into CS values(rno,nam,tot,trd,rnk);

    end if;

    else

    exit;

    end if;

    end loop;

    commit;

    close curr;

    i:=1;

    update CS set rank=null;

    open ccs;

    loop

    fetch ccs into rno,nam,tot,trd,rnk;

    if(ccs%found) then

    select max(tot_marks) into mx from CS where rank is null;

    update CS set rank=i where tot_marks=mx;

    i:=i+1;

    else

    exit;

    end if;

    end loop;

    commit;

    close ccs;

    Page | 2

  • 8/14/2019 SQL 8i Programs

    3/38

    [email protected]

    i:=1;

    update IT set rank=null;

    open cit;

    loop

    fetch cit into rno,nam,tot,trd,rnk;

    if(cit%found) then

    select max(tot_marks) into mx from IT where rank is null;

    update IT set rank=i where tot_marks=mx;

    i:=i+1;

    else

    exit;

    end if;

    end loop;

    commit;

    close cit;

    end;

    SQL> select * from student;

    ROLLNO NAME TOT_MARKS TRADE

    ----------------------------------------------------------------------------

    1 Ammu 555 IT

    2 Appu 556 IT

    1 Tinto 585 CS

    2 Tintumon 598 CS

    3 Kuttoos 542 IT

    3 Tuttu 562 CS

    Page | 3

  • 8/14/2019 SQL 8i Programs

    4/38

    [email protected]

    6 rows selected.

    SQL> select * from IT;

    ROLLNO NAME TOT_MARKS TRADE RANK

    ----------------------------------------------------------------------------------------------------------

    1 Ammu 555 IT 2

    2 Appu 556 IT 1

    3 Kuttoos 542 IT 3

    SQL> select * from CS;

    ROLLNO NAME TOT_MARKS TRADE RANK

    ------------------------------------------------------------------------------------------------------

    1 Tinto 585 CS 2

    2 Tintumon 598 CS 1

    3 Tuttu 562 CS 3

    BANK DATABASE

    SQL> create table ACCTMASTER(accno INT primary key,name char(25),balance number(10));

    SQL> create table ACCTTRAN(accno INT references ACCTMASTER(accno),tran_date datedefault sysdate,deb_cred char(7),flag char(2) default 'N',amount number(10));

    SQL> insert into ACCTMASTER values(&accno,'&name',&balance);

    Enter value for accno: 101

    Enter value for name: Tuttu

    SQL> /

    Enter value for accno: 102

    Enter value for name: Tintumon

    Enter value for balance: 19000

    Page | 4

  • 8/14/2019 SQL 8i Programs

    5/38

    [email protected]

    SQL> select * from ACCTMASTER;

    ACCNO NAME BALANCE

    -------------------------------------------------------------

    101 Tuttu 10000

    102 Tintumon 19000

    SQL> insert into ACCTTRAN values(&accno,'&tran_date','&deb_cred','&flag',&amt);

    Enter value for accno: 101

    Enter value for tran_date: 05-JAN-10

    Enter value for deb_cred: Debit

    Enter value for flag: n

    Enter value for amt: 1000

    SQL> /

    Enter value for accno: 102

    Enter value for tran_date: 05-JAN-10

    Enter value for deb_cred: Credit

    Enter value for flag: n

    Enter value for amt: 1000

    SQL> select * from ACCTTRAN;

    ACCNO TRAN_DATE DEB_CRE FL AMOUNT

    -------------------------------------------------------------------------------------

    101 05-JAN-10 Debit n 1000

    102 05-JAN-10 Credit n 1000

    declare

    no INT;

    bal number(10);

    Page | 5

  • 8/14/2019 SQL 8i Programs

    6/38

    [email protected]

    trdate date;

    dc char(7);

    a number(10);

    fl char(2);

    cursor ctrn is select * from ACCTTRAN where flag='n' or flag='N';

    begin

    open ctrn;

    loop

    fetch ctrn into no,trdate,dc,fl,a;

    if ctrn%found then

    if dc='Debit' then

    update ACCTMASTER set balance=balance-a where accno=no;

    update ACCTTRAN set flag='Y' where accno=no;

    elsif dc='Credit' then

    update ACCTMASTER set balance=balance+a where accno=no;

    update ACCTTRAN set flag='Y' where accno=no;

    end if;

    else

    exit;

    end if;

    end loop;

    commit;

    close ctrn;

    end;

    SQL> /

    PL/SQL procedure successfully completed.

    Page | 6

  • 8/14/2019 SQL 8i Programs

    7/38

    [email protected]

    SQL> select * from ACCTMASTER;

    ACCNO NAME BALANCE

    ---------------------------------------------------------------------

    101 Tuttu 9000

    102 Tintumon 20000

    SQL> select * from ACCTTRAN;

    ACCNO TRAN_DATE DEB_CRE FL AMOUNT

    --------------------------------------------------------------------------------

    101 05-JAN-10 Debit Y 1000

    102 05-JAN-10 Credit Y 1000

    HOSPITAL MANAGEMENT

    >>>>>>>>>>>>>>>>>>>>CREATE TABLE>DOCTORS_DETAILS

  • 8/14/2019 SQL 8i Programs

    8/38

    [email protected]

    Enter value for fees: 100

    SQL> /

    Enter value for doc_id: 2

    Enter value for name: Kuttoos

    Enter value for specialization: CARDIO

    Enter value for fees: 500

    SQL> select * from doctors_details;

    DOC_ID NAME SPECIALIZATION FEES

    -----------------------------------------------------------------------------------

    1 Tintumon ENT 100

    2 Kuttoos CARDIO 500

    >>>>>>>>>>>>>>>>>>>>PL/SQL BLOCK

  • 8/14/2019 SQL 8i Programs

    9/38

    [email protected]

    /

    Enter value for reg: 1

    Enter value for name: Tuttu

    Enter value for age: 17

    Enter value for sex: M

    Enter value for address: 17/23 vietnam colony

    Enter value for category: ENT

    Mr/Mrs/MissTuttu has been refered to Dr.Tintumon

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for reg: 2

    Enter value for name: Ammu

    Enter value for age: 18

    Enter value for sex: F

    Enter value for address: 18/23 vietnam colony

    Enter value for category: ENT

    Mr/Mrs/MissAmmu has been refered to Dr.Tintumon

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for reg: 3

    Enter value for name: Appu

    Enter value for age: 19

    Enter value for sex: M

    Enter value for address: 1/23 gandhi colony

    Enter value for category: CARDIO

    Mr/Mrs/MissAppu has been refered to Dr.Kuttoos

    Page | 9

  • 8/14/2019 SQL 8i Programs

    10/38

    [email protected]

    PL/SQL procedure successfully completed.

    SQL> select * from register;

    REGNO NAME AGE SEX ADDRESS DATE_REG

    CATEGORY

    -------------------------------------------------------------------------------------------------------------------------------

    1 Tuttu 17 M 17/23 vietnam colony 07-JAN-10 ENT

    2 Ammu 18 F 18/23 vietnam colony 07-JAN-10 ENT

    3 Appu 19 M 1/23 gandhi colony 07-JAN-10 CARDIO

    >>>>>>>>>>>>>>>>>>>>QUERIES

  • 8/14/2019 SQL 8i Programs

    11/38

    [email protected]

    loop

    fetch cur into cat;

    if cur%found then

    select COUNT(*) into cnt from register where category=cat;

    select name into dname from doctors_details where specialization=cat;

    select fees into f from doctors_details where specialization=cat;

    if cnt>mx then

    mx:=cnt;

    dname1:=dname;

    end if;

    earn:=f*cnt;

    if earn>mxern then

    mxern:=earn;

    dname2:=dname;

    end if;

    else

    exit;

    end if;

    end loop;

    commit;

    close cur;

    dbms_output.put_line('The doctor who has attended maximum number of patients is '||dname1);

    dbms_output.put_line('The doctor who has earned the maximum is '||dname2);

    end;

    /

    The doctor who has attended maximum number of patients is Tintumon

    Page | 11

  • 8/14/2019 SQL 8i Programs

    12/38

    [email protected]

    The doctor who has earned the maximum is Kuttoos

    PL/SQL procedure successfully completed.

    LIBRARY MANAGEMENT SYSTEM

    >>>>>>>>>>>>>>>>>>>>CREATE TABLE>ADD A NEW BOOK

  • 8/14/2019 SQL 8i Programs

    13/38

    [email protected]

    select MAX(book_id) into no from book_details;

    if no is not null then

    id:=no+1;

    else

    id:=1;

    end if;

    insert into book_details values(id,bknam,null);

    end loop;

    end;

    /

    Enter value for bknam: DCD

    Enter value for auth: Mano

    Enter value for tot: 3

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for bknam: OS

    Enter value for auth: Silber

    Enter value for tot: 2

    PL/SQL procedure successfully completed.

    SQL> select * from book_rec;

    BOOK_NAME AUTHOR TOTAL_COPIES AVAILABLE_COPIES

    --------------------------------------------------------------------------------------------------------------

    DCD Mano 3 3

    OS Silber 2 2

    SQL> select * from book_details;

    BOOK_ID BOOK_NAME MEM_ID

    Page | 13

  • 8/14/2019 SQL 8i Programs

    14/38

    [email protected]

    --------------------------------------------------------------

    1 DCD

    2 DCD

    3 DCD

    4 OS

    5 OS

    >>>>>>>>>>>>>>>>>>>>CREATE A NEW MEMBER

  • 8/14/2019 SQL 8i Programs

    15/38

    [email protected]

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for nam: Kuttoos

    Mr/Mrs/Miss. Kuttoos , your membership id is 2

    PL/SQL procedure successfully completed.

    SQL> select * from membership_rec;

    MEM_ID MEM_NAME NO_OF_BOOKS_TAKEN

    --------------------------------------------------------------------------------------

    1 Tintumon

    2 Kuttoos

    >>>>>>>>>>>>>>>>>>>>ISSUE A BOOK

  • 8/14/2019 SQL 8i Programs

    16/38

    [email protected]

    n:=0;

    end if;

    update membership_rec set no_of_books_taken=n+1 where mem_id=mid;

    update book_rec set available_copies=available_copies-1 where book_name=bknam;

    select ADD_months(sysdate,1) into dat from dual;

    insert into circulation_rec values(bid,mid,sysdate,dat);

    end;

    /

    Enter value for bknam: DCD

    Enter value for mid: 2

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for bknam: OS

    Enter value for mid: 1

    PL/SQL procedure successfully completed.

    SQL>/

    Enter value for bknam: DCD

    Enter value for mid: 1

    PL/SQL procedure successfully completed.

    SQL> select * from book_details;

    BOOK_ID BOOK_NAME MEM_ID

    ------------------------------------------------------------

    1 DCD 2

    2 DCD 1

    3 DCD

    4 OS 1

    Page | 16

  • 8/14/2019 SQL 8i Programs

    17/38

    [email protected]

    5 OS

    SQL> select * from book_rec;

    BOOK_NAME AUTHOR TOTAL_COPIES AVAILABLE_COPIES

    -------------------------------------------------------------------------------------------------------------

    DCD Mano 3 1

    OS Silber 2 1

    SQL> select * from membership_rec;

    MEM_ID MEM_NAME NO_OF_BOOKS_TAKEN

    ------------------------------------------------------------------------------------

    1 Tintumon 2

    2 Kuttoos 1

    SQL> select * from circulation_rec;

    BOOK_ID MEM_ID ISSUE_DAT RETURN_DA

    ------------------------------------------------------------------------------

    1 2 08-JAN-10 08-FEB-10

    4 1 08-JAN-10 08-FEB-10

    2 1 08-JAN-10 08-FEB-10

    >>>>>>>>>>>>>>>>>>>>RETURN A BOOK

  • 8/14/2019 SQL 8i Programs

    18/38

    [email protected]

    id:=&id;

    select book_id into bid from book_details where book_name=bknam and mem_id=id;

    update book_details set mem_id=null where book_id=bid;

    update membership_rec set no_of_books_taken=no_of_books_taken-1 where mem_id=id;

    update book_rec set available_copies=available_copies+1 where book_name=bknam;

    select return_date into dat from circulation_rec where book_id=bid and mem_id=id;

    select months_between(sysdate,dat) into tim from dual;

    if tim>0 then

    dbms_output.put_line('You have to pay fine');

    end if;

    end;

    /

    Enter value for bknam: DCD

    Enter value for id: 1

    PL/SQL procedure successfully completed.

    SQL> select * from book_rec;

    BOOK_NAME AUTHOR TOTAL_COPIES AVAILABLE_COPIES

    -------------------------------------------------------------------------------------------------------------

    DCD Mano 3 2

    OS Silber 2 1

    SQL> select * from membership_rec;

    MEM_ID MEM_NAME NO_OF_BOOKS_TAKEN

    -----------------------------------------------------------------------------------

    1 Tintumon 1

    2 Kuttoos 1

    SQL> select * from book_details;

    Page | 18

  • 8/14/2019 SQL 8i Programs

    19/38

    [email protected]

    BOOK_ID BOOK_NAME MEM_ID

    --------------------------------------------------------------

    1 DCD 2

    2 DCD

    3 DCD

    4 OS 1

    5 OS

    SQL> select * from circulation_rec;

    BOOK_ID MEM_ID ISSUE_DAT RETURN_DA

    ------------------------------------------------------------------------------

    1 2 08-JAN-10 08-FEB-10

    4 1 08-JAN-10 08-FEB-10

    2 1 08-JAN-10 08-FEB-10

    RAILWAY RESERVATION SYSTEM

    >>>>>>>>>>>>>>>>>>>>CREATE TABLE>ENTER TRAIN DETAILS

  • 8/14/2019 SQL 8i Programs

    20/38

    [email protected]

    cursor cur is select * from train_details;

    begin

    insert into train_details values('&train_name',&total_seats,0);

    open cur;

    loop

    fetch cur into tname,tot,resv;

    if cur%found then

    for i in 1..tot

    loop

    insert into reservation_status values(tname,i,'n',null);

    end loop;

    else

    exit;

    end if;

    end loop;

    commit;

    close cur;

    end;

    /

    Enter value for train_name: AA

    Enter value for total_seats: 3

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for train_name: BB

    Enter value for total_seats: 2

    PL/SQL procedure successfully completed.

    Page | 20

  • 8/14/2019 SQL 8i Programs

    21/38

    [email protected]

    SQL> select * from train_details;

    TRAIN_NAME TOTAL_SEATS RESERVED_SEATS

    --------------------------------------------------------------------------------------

    AA 3 0

    BB 2 0

    SQL> select * from reservation_status;

    TRAIN_NAME SEAT_ID RE CUSTOMER_NAME

    -----------------------------------------------------------------------------------------

    AA 1 n

    AA 2 n

    AA 3 n

    BB 1 n

    BB 2 n

    5 rows selected.

    >>>>>>>>>>>>>>>>>>>>RESERVE A SEAT

  • 8/14/2019 SQL 8i Programs

    22/38

    [email protected]

    tname:=&tname;

    select total_seats into tot from train_details where train_name=tname;

    select reserved_seats into resv from train_details where train_name=tname;

    if tot>resv then

    select MIN(seat_id) into sid from reservation_status where train_name=tname and

    reserved='n';

    update reservation_status set reserved='y' where train_name=tname and seat_id=sid;

    update reservation_status set customer_name=cname where train_name=tname and

    seat_id=sid;

    update train_details set reserved_seats=reserved_seats+1 where train_name=tname;

    else

    select MAX(slno) into sno from waiting_list;

    if sno is null then

    sl:=1;

    else

    sl:=sno+1;

    end if;

    insert into waiting_list values(sl,cname,tname);

    end if;

    end;

    SQL> /

    Enter value for cname: 'Tintumon'

    Enter value for tname: 'AA'

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for cname: 'Kuttoos'

    Enter value for tname: 'BB'

    Page | 22

  • 8/14/2019 SQL 8i Programs

    23/38

    [email protected]

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for cname: 'Appu'

    Enter value for tname: 'BB'

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for cname: 'Tuttu'

    Enter value for tname: 'BB'

    PL/SQL procedure successfully completed.

    SQL> select * from reservation_status;

    TRAIN_NAME SEAT_ID RE CUSTOMER_NAME

    ---------------------------------------------------------------------------------------

    AA 1 y Tintumon

    AA 2 n

    AA 3 n

    BB 1 y Kuttoos

    BB 2 y Appu

    5 rows selected.

    SQL> select * from waiting_list;

    SLNO CUSTOMER_NAME TRAIN_NAME

    --------------------------------------------------------------------------------

    1 Tuttu BB

    >>>>>>>>>>>>>>>>>>>>CANCEL A RESERVATION

  • 8/14/2019 SQL 8i Programs

    24/38

    [email protected]

    tname char(15);

    sid number(3);

    sno number(3);

    sl number(3);

    begin

    cname:=&cname;

    tname:=&tname;

    select seat_id into sid from reservation_status where train_name=tname and

    customer_name=cname;

    select MIN(slno) into sno from waiting_list where train_name=tname;

    if sno is not null then

    select customer_name into cname from waiting_list where train_name=tname and slno=sno;

    update reservation_status set customer_name=cname where train_name=tname and

    seat_id=sid;

    delete from waiting_list where train_name=tname and slno=sno;

    else

    update reservation_status set reserved='n' where train_name=tname and seat_id=sid;

    update reservation_status set customer_name=null where train_name=tname and

    seat_id=sid;

    update train_details set reserved_seats=reserved_seats-1 where train_name=tname;

    end if;

    end;

    /

    Enter value for cname: 'Appu'

    Enter value for tname: 'BB'

    PL/SQL procedure successfully completed.

    SQL> select * from reservation_status;

    Page | 24

  • 8/14/2019 SQL 8i Programs

    25/38

    [email protected]

    TRAIN_NAME SEAT_ID RE CUSTOMER_NAME

    ---------------------------------------------------------------------------------------

    AA 1 y Tintumon

    AA 2 n

    AA 3 n

    BB 1 y Kuttoos

    BB 2 y Tuttu

    5 rows selected.

    SQL> select * from waiting_list;

    SLNO CUSTOMER_NAME TRAIN_NAME

    ----------------------------------------------------------------------------------

    SQL> select * from train_details;

    TRAIN_NAME TOTAL_SEATS RESERVED_SEATS

    --------------- ----------- --------------

    AA 3 1

    BB 2 2

    RECRUITMENT DATABASE

    >>>>>>>>>>>>>>>>>>>>CREATE TABLE

  • 8/14/2019 SQL 8i Programs

    26/38

    [email protected]

    >>>>>>>>>>>>>>>>>>>>PROCEDURE

  • 8/14/2019 SQL 8i Programs

    27/38

    [email protected]

    COMPANY_NAME SALARY

    ----------------------------------------------------

    Wipro 25000

    >>>>>>>>>>>>>>>>>>>>TRIGGER>REGISTER

  • 8/14/2019 SQL 8i Programs

    28/38

    [email protected]

    declare

    pname char(15);

    pcoll char(15);

    pdgr char(10);

    begin

    pname:='&pname';

    pcoll:='&pcoll';

    pdgr:='&pdgr';

    insertreg(pname,pcoll,pdgr);

    end;

    /

    Enter value for pname: Tintumon

    Enter value for pcoll: UCE

    Enter value for pdgr: B tech

    Registration success, your registration number is 1

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for pname: Kuttoos

    Enter value for pcoll: VJC

    Enter value for pdgr: B tech

    Registration success, your registration number is 2

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for pname: Tuttu

    Enter value for pcoll: UCE

    Enter value for pdgr: B tech

    Page | 28

  • 8/14/2019 SQL 8i Programs

    29/38

    [email protected]

    Registration success, your registration number is 3

    PL/SQL procedure successfully completed.

    SQL> select * from registration;

    REGNO NAME COLLEGE DATE_OF_R DEGREE

    -------------------------------------------------------------------------------------------------------

    1 Tintumon UCE 08-JAN-10 B tech

    2 Kuttoos VJC 08-JAN-10 B tech

    3 Tuttu UCE 08-JAN-10 B tech

    >>>>>>>>>>>>>>>>>>>>RESULT

  • 8/14/2019 SQL 8i Programs

    30/38

    [email protected]

    REGNO MARKS SEL

    ----------------------------------------------

    1 98

    2 99

    3 100

    >>>>>>>>>>>>>>>>>>>>PL/SQL BLOCK

  • 8/14/2019 SQL 8i Programs

    31/38

    [email protected]

    loop

    fetch cur into rno,mk,sel;

    if cur%found then

    select COUNT(*) into i from result where selected='Y';

    if i=intake then

    exit;

    end if;

    select MAX(marks) into mx from result where selected='N' or selected is null;

    update result set selected='Y' where marks=mx;

    else

    exit;

    end if;

    end loop;

    commit;

    close cur;

    dbms_output.put_line('Selected Candidates');

    open cur;

    loop

    fetch cur into rno,mk,sel;

    if cur%found then

    if sel='Y' then

    select name into nam from registration where regno=rno;

    dbms_output.put_line(nam);

    end if;

    else

    exit;

    Page | 31

  • 8/14/2019 SQL 8i Programs

    32/38

    [email protected]

    end if;

    end loop;

    commit;

    close cur;

    select salary into sal from company_details where company_name=cnam;

    update company_details set salary=sal*1 where company_name=cnam;

    end;

    /

    Enter value for cnam: Wipro

    Enter value for intake: 2

    Total no of appearence for the exam: 3

    Selected Candidates

    Kuttoos

    Tuttu

    PL/SQL procedure successfully completed.

    SQL> select * from agency_income_details;

    COMPANY_NAME AGENCY_PROFIT

    ------------------------------------------------------

    Wipro 24650

    SQL> select * from company_details;

    COMPANY_NAME SALARY

    ---------------------------------------------------

    Wipro 25000

    SQL> select * from registration;

    REGNO NAME COLLEGE DATE_OF_R DEGREE

    Page | 32

  • 8/14/2019 SQL 8i Programs

    33/38

    [email protected]

    ------------------------------------------------------------------------------------------------------

    1 Tintumon UCE 08-JAN-10 B tech

    2 Kuttoos VJC 08-JAN-10 B tech

    3 Tuttu UCE 08-JAN-10 B tech

    SQL> select * from result;

    REGNO MARKS SEL

    -----------------------------------------------

    1 98

    2 99 Y

    3 100 Y

    UNIVERSITY EXAM REGISTRATION SYSTEM

    >>>>>>>>>>>>>>>>>>>>CREATE TABLE>UNIVERSITY DATABASE

  • 8/14/2019 SQL 8i Programs

    34/38

    [email protected]

    Enter value for student_name: Tuttu

    Enter value for branch: CS

    Enter value for college: VJC

    1 row created.

    SQL> /

    Enter value for student_name: Tintumon

    Enter value for branch: CS

    Enter value for college: UCE

    1 row created.

    SQL> /

    Enter value for student_name: Ammu

    Enter value for branch: EC

    Enter value for college: UCE

    1 row created.

    SQL> select * from university;

    STUDENT_NAME BRANCH COLLEGE

    ---------------------------------------------------------------

    Kuttoos IT UCE

    Tuttu CS VJC

    Tintumon CS UCE

    Ammu EC UCE

    >>>>>>>>>>>>>>>>>>>>APPLICATION

  • 8/14/2019 SQL 8i Programs

    35/38

    [email protected]

    rcs number(5);

    rec number(5);

    rit number(5);

    sno number(5);

    sname char(15);

    brch char(7);

    clg char(15);

    dat number(7,2);

    nam char(15);

    begin

    rcs:=1000;

    rec:=1100;

    rit:=1200;

    last_date:='07-JAN-10';

    sno:=&sno;

    sname:=&sname;

    brch:=&brch;

    clg:=&clg;

    insert into application values(sno,sname,brch,clg,sysdate);

    select student_name into nam from university where student_name=sname and branch=brch and

    college=clg;

    select months_between(sysdate,last_date) into dat from dual;

    if nam is null or dat>0 then

    dbms_output.put_line('Application Rejected');

    else

    select MAX(regno) into no from register_nos where branch=brch;

    Page | 35

  • 8/14/2019 SQL 8i Programs

    36/38

    [email protected]

    if no is null then

    if brch='IT' then

    reg:=rit;

    elsif brch='CS' then

    reg:=rcs;

    elsif brch='EC' then

    reg:=rec;

    end if;

    else

    reg:=no+1;

    end if;

    insert into register_nos values(reg,sname,brch,clg);

    dbms_output.put_line('Register No: '||reg);

    end if;

    end;

    SQL> /

    Enter value for sno: 1

    Enter value for sname: 'Tintumon'

    Enter value for brch: 'CS'

    Enter value for clg: 'UCE'

    Register No: 1000

    PL/SQL procedure successfully completed.

    SQL> /

    Enter value for sno: 2

    Page | 36

  • 8/14/2019 SQL 8i Programs

    37/38

    [email protected]

    Enter value for sname: 'Kuttoos'

    Enter value for brch: 'IT'

    Enter value for clg: 'UCE'

    Register No: 1200

    PL/SQL procedure successfully completed.

    SQL> select * from register_nos;

    REGNO STUDENT_NAME BRANCH COLLEGE

    ------------------------------------------------------------------------------------

    1000 Tintumon CS UCE

    1200 Kuttoos IT UCE

    SQL> select * from application;

    SLNO STUDENT_NAME BRANCH COLLEGE DATE_APPL

    --------------------------------------------------------------------------------------------------------------

    1 Tintumon CS UCE 07-JAN-10

    2 Kuttoos IT UCE 07-JAN-10

    Page | 37

  • 8/14/2019 SQL 8i Programs

    38/38

    [email protected]

    Page | 38