Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Define Const for Date Format
I believe that you can only use such a constant that is declared inside
of a package in such a way from within pl/sql. If you want to use it
as your date format in sql, then you can create a function that returns
it. Please see the demonstration below.
scott_at_ORA92> -- package with constant:
scott_at_ORA92> CREATE OR REPLACE PACKAGE userconst AS
2 date_format VARCHAR2(21) := 'YYYY-MM-DD HH24:MI:SS';
3 END userconst;
4 /
Package created.
scott_at_ORA92> -- package.constant used in pl/sql: scott_at_ORA92> SET SERVEROUTPUT ON scott_at_ORA92> DECLARE
PL/SQL procedure successfully completed.
scott_at_ORA92> -- package with function:
scott_at_ORA92> CREATE OR REPLACE PACKAGE userconst AS
2 date_format VARCHAR2(21) := 'YYYY-MM-DD HH24:MI:SS';
3 FUNCTION get_date_format RETURN VARCHAR2;
4 END userconst;
5 /
Package created.
scott_at_ORA92> SHOW ERRORS
No errors.
scott_at_ORA92> CREATE OR REPLACE PACKAGE BODY userconst AS
2 FUNCTION get_date_format RETURN VARCHAR2
3 IS
4 BEGIN
5 RETURN date_format;
6 END get_date_format;
7 END userconst;
8 /
Package body created.
scott_at_ORA92> SHOW ERRORS
No errors.
scott_at_ORA92> -- package.function used in sql:
scott_at_ORA92> SELECT TO_CHAR (SYSDATE, userconst.get_date_format) FROM
DUAL
2 /
TO_CHAR(SYSDATE,USERCONST.GET_DATE_FORMAT)
scott_at_ORA92> Received on Wed Jul 13 2005 - 11:48:38 CDT