Results 1 to 3 of 3

Thread: Pl/sql

  1. #1
    Join Date
    May 2011
    Posts
    36

    Unanswered: Pl/sql

    wo tables Emp and Etemp.

    Case 1:
    If Emp table record found in Etemp table then check salary.
    if both salary are equal do nothing..Else update salary.

    Case 2:
    If Emp table record not found insert record into Etemp.

    I know the below code is wrong please correct me..

    ================================================== =======

    Create or replace procedure Proc1
    Is
    Declare
    cursor c1 Is select * from Emp;
    --e1 Emp%rowtype;
    Cursor c2 Is select * from Etemp;
    e2 Etemp%rowtype;
    Begin
    open c2;
    fetch c2 into e2;
    for i in c1
    Loop
    if(i.Empid = e2.Empid)
    then
    if(i.salary = e2.salary)
    then Exit;
    Else
    update Etemp set salary = i.salary where i.Empid = e2.Empid;
    End if;
    Else
    Insert into Etemp values(i.Empid, i.salary, i.Job);
    End if;
    End Loop;
    End;
    /

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    no PL/SQL required; use MERGE instead
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    May 2011
    Posts
    36

    Hi anacedent

    Yes I learned using merge...its simple

    Thanks for reply.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •