PROGRAM TO CHECK WHETHER THE RECORD FOR A GIVEN EMPNO AND ALSO RETRIEVE HIS SALARY IN ORACLE?



SQL> DECLARE
  2  SALARY NUMBER;
  3  BEGIN
  4  SELECT SAL INTO SALARY FROM EMP WHERE    
      EMPNO=&EMPNO;
  5  IF SQL%FOUND THEN
      DBMS_OUTPUT.PUT_LINE('RECORD IS FOUND');
  6  DBMS_OUTPUT.PUT_LINE('SALARY IS '||SALARY);
  7  END IF;
  8  EXCEPTION
  9  WHEN NO_DATA_FOUND THEN
 10  DBMS_OUTPUT.PUT_LINE('EMPLOYEE RECORD IS NOT
       PRESENT');
 11  END;
 12  /
Enter value for empno: 7499
old   4: SELECT SAL INTO SALARY FROM EMP WHERE EMPNO=&EMPNO;
new   4: SELECT SAL INTO SALARY FROM EMP WHERE EMPNO=7499;
RECORD IS FOUND
SALARY IS 2042.05

PL/SQL procedure successfully completed.
SQL> @ RECORD.SQL;
Enter value for empno: 7369
old   4: SELECT SAL INTO SALARY FROM EMP WHERE EMPNO=&EMPNO;
new   4: SELECT SAL INTO SALARY FROM EMP WHERE EMPNO=7369;
RECORD IS FOUND
SALARY IS 1269.5

PL/SQL procedure successfully completed.

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart