Monday, 1 April 2013

Variable Types in Oracle



Ex: 1:-

--BIND VARIABLES MUST BE PREFIXED WITH COLON(:)
--IN SQL*PLUS BIND VARIABLES ARE DISPLAYED USING PRINT COMMAND
--SQL>VARIABLE G_SALARY NUMBER;
DECLARE
 V_SAL NUMBER(9,2);
BEGIN
 SELECT Sal INTO V_SAL FROM EMP where Empno=&V_SAL;
 :G_SALARY:=V_SAL;
END;
--SQL>PRINT G_SALARY;
/

Ex:2:-
DECLARE
 V_SAL NUMBER(9,2);
BEGIN
 SELECT Sal INTO V_SAL FROM EMP where Empno=&V_SAL;
 :G_SALARY:=V_SAL;
END;

Pl/Sql Variables:

DECLARE
 V_SAL NUMBER(9,2):=&P_SAL;
 V_BONUS NUMBER(9,2):=&P_Bon;
 V_RES NUMBER(9,2);
BEGIN
 V_RES:=NVL(V_SAL,0)*(1+NVL(V_BONUS,0)/100);
 DBMS_OUTPUT.PUT_LINE('RESULTS: '||V_RES);
END;
/


Ur's
AmarAlam

0 comments:

Post a Comment