Monday, December 2, 2019

WITH Clause - Subquery Factoring in Oracle

SQL> set lines 100
SQL> set pages 50
SQL> select * from v$version;

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production              0
PL/SQL Release 12.1.0.2.0 - Production                                                    0
CORE    12.1.0.2.0      Production                                                                0
TNS for Linux: Version 12.1.0.2.0 - Production                                            0
NLSRTL Version 12.1.0.2.0 - Production                                                    0

SQL>

WITH FUNCTION GET_DNAME (I_DEPTNO NUMBER)
        RETURN VARCHAR2
     IS
        V_DNAME   VARCHAR2 (50) := NULL;
     BEGIN
        SELECT DNAME
          INTO V_DNAME
          FROM DEPT
         WHERE DEPTNO = I_DEPTNO;
        RETURN V_DNAME;
     EXCEPTION
     WHEN NO_DATA_FOUND THEN
     RETURN NULL;
     WHEN OTHERS THEN
     RETURN SQLERRM;
     END;
SELECT EMPNO,
       ENAME,
       DEPTNO,
       GET_DNAME (DEPTNO) AS DNAME
  FROM EMP;

No comments:

Post a Comment

Delete Row Button to all records of Interactive Report in Oracle Apex

 1. add 'Delete' Del column to Report Query 2. Set the Following Properties for the DEL Column Type: Link Heading: Delete Targ...