Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2007
    Posts
    2

    Unanswered: update salary to 3000 if salary is less than 3000 (was "pl/sql"

    i'm really new to PL and need help. here is a question i need help with "Write a PL/SQL code to update salary of employee whose employee number is 7788 to 3000 if salary is less than 3000"
    information:
    tablename:emp
    columns:sal,empid

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Can you do that using SQL? If so, just enclose that code into the BEGIN-END keywords and you'll have a PL/SQL code. Because, having all those values hard-coded, there will be no difference between SQL and PL/SQL solution.

    If you, however, have a problem doing it, do post what you have done so far and someone will surely help you.

  3. #3
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Have a look at the PL/SQL documentation first, there are many examples there that will help you. Then try to write something by yourself and come back with your code if you don't get it to work : paste your code and the exact error you get.

    Then maybe someone will help you here, but noone will do your homework for you .

    Regards,

    rbaraer
    ORA-000TK : No bind variable detected... Shared Pool Alert code 5 - Nuclear query ready .

  4. #4
    Join Date
    Jul 2007
    Posts
    2

    thanks

    thanks guys for the suggestion.

  5. #5
    Join Date
    Aug 2007
    Location
    France
    Posts
    14
    In your PL/SQL code :
    Code:
    EXECUTE IMMEDIATE 'UPDATE emp SET sal = 3000 where empid = 7788 and sal < 3000;'

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    scheu, if it was not obvious, this was a homework question

    please do not just hand students the answer

    you may make suggestions, but the intention should be to encourage the students to figure out the answer for themselves

    thanks for understanding

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Also if you are going to give them the answer, do not teach them bad programming habits. Code should never use execute immediate except if it is absolutely necessary. To perform a simple update just

    Code:
    UPDATE emp SET sal = 3000 where empid = 7788 and sal < 3000;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

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