Saturday, October 1, 2011

PL/SQL: SQL Statement


Shafeen with flower


The following code block shows how to run DML statements in PL/SQL. Basically they look similar to the SQL. Note that the SELECT statement retrieves the single-row value and store into a variable using INTO clause.
DECLARE
    v_sal employee.sal%TYPE;
BEGIN


    INSERT INTO employee VALUES (6, 'TOM LEE', 10000);


    UPDATE employee SET sal = sal + 5000 WHERE empno = 6;

      SELECT sal INTO v_sal FROM employee WHERE empno = 6;
    DBMS_OUTPUT.PUT_LINE('Salary increased to ' || v_sal); 
    DELETE FROM employee WHERE empno = 6;
      COMMIT;
END;

/

No comments: