Votes

Make package constants available from SQL (details)
 
Dear Bryn,

I love how you can called packaged functions from within SQL statements.

I would love it even more if I could refer to packaged variables and constants inside those same SQL statements. That way I don't have to write a function wrapper around the data.

Thanks!

We often need to reference package-constants in SQL-statements. At the moment we have to implement a function for every constant. Alternatively we access the package-constant via a function which use dynamic sql (as: pck.get_constant('pck2.constant_name') ).


Make package constants available from within SQL statements directly.


-- Package pck
FUNCTION get_value
  ( pv_plsql_expression IN VARCHAR2
  ) RETURN VARCHAR2
IS
  lv_value VARCHAR2(1000) := NULL;
BEGIN
  IF pv_plsql_expression IS NOT NULL
  THEN
    EXECUTE IMMEDIATE 'BEGIN :ret := ' || pv_plsql_expression || '; END;'
      USING OUT lv_value;
  END IF;
  RETURN lv_value;
END get_value;

SELECT pck.get_value('pck1.constant_name') FROM table;


SELECT pck1.constant_name FROM table;


Steven Feuerstein, PL/SQL Evangelist, Quest Software: "Help me help Oracle improve the PL/SQL language!"


Bryn Llewellyn: "We love to hear from PL/SQL developers. Let us know what is important to you!"

PL/SQL Obsession
Apex Evangelists
O'Reilly Books on Oracle
OTN PL/SQL Best Practices
OTN PL/SQL Page
Steven Feuerstein's Blog