--Program : dt.sql --Purpose : To change the default date format without losing the query in the current buffer. --Usage : SQL>@dt [DD|YY|RR|MM|DT|YT|RT|MT|TT] --Notes : The parameters supplied are short hand for the following formats. -- DD DD-MON-YYYY -- DT DD-MON-YYYY HH24:MI:SS -- YY DD-MON-YY -- YT DD-MON-YY HH24:MI:SS -- RR DD-MON-RR -- RT DD-MON-RR HH24:MI:SS -- MM DD-MM-YYYY -- MT DD-MM-YYYY HH24:MI:SS -- TT HH24:MI:SS -- -- The script generates two temporary files , one to store the query in the current buffer (dt.sql.buffer.tmp) -- and one as the command file (dt.tmp) used to alter default date format for the session.NOTE the temporary -- files are stored in the directory pointed to, by the TEMP environment variable. On Windows this is referred -- to as %TEMP% and on unix this refered as $TEMP (may need to defined by the user in his/her login profile). -- --Example : SQL>@dt DT --Author : Ram Razdan , ramrazdan@yahoo.com --License : Free for public use, amendment and distribution. -- Please refer https://ramrazdan.tripod.com/termsofuse.txt for full details. --Revision : Version Date Server/OS Comments -- 1.0 Dec,1997 Oracle7.1/VM-CMS Initial Revision. -- 1.1 Aug,1998 Oracle7.3/SunOS Save and Restore the query in the default SQL*Plus buffer. -- 1.2 Apr,2001 Oracle8.1/Win98 Amend OS specific code , like deleting files and refering env variables -- SET TERMOUT OFF FEEDBACK OFF HEADING OFF TIMING OFF PAUSE OFF TIME OFF VERIFY OFF ECHO OFF -- -- Use for UNIX -- --SAVE $TEMP/dt.sql.buffer.tmp --SPOOL $TEMP/dt.tmp -- -- Use for Windows -- SAVE %TEMP%\dt.sql.buffer.tmp REPLACE SPOOL %TEMP%\dt.tmp -- -- Common -- SELECT 'ALTER SESSION SET NLS_DATE_FORMAT = '''|| DECODE(UPPER('&1') ,'DT','DD-MON-YYYY HH24:MI:SS' ,'DD','DD-MON-YYYY' ,'YY','DD-MON-YY' ,'RR','DD-MON-RR' ,'YT','DD-MON-YY HH24:MI:SS' ,'RT','DD-MON-RR HH24:MI:SS' ,'TT','HH24:MI:SS' ,'MM','DD-MM-YYYY' ,'MT','DD-MM-YYYY HH24:MI:SS' ,'DD-MON-YYYY')||''';' FROM DUAL ; SELECT 'SET TERMOUT ON' FROM DUAL; SELECT 'SELECT ''Format set to '||DECODE(UPPER('&1') ,'DT','DD-MON-YYYY HH24:MI:SS' ,'DD','DD-MON-YYYY' ,'YY','DD-MON-YY' ,'RR','DD-MON-RR' ,'YT','DD-MON-YY HH24:MI:SS' ,'RT','DD-MON-RR HH24:MI:SS' ,'TT','HH24:MI:SS' ,'MM','DD-MM-YYYY' ,'MT','DD-MM-YYYY HH24:MI:SS' ,'DD-MON-YYYY')|| ' eg. ''||SYSDATE FROM DUAL;' FROM DUAL ; SPOOL OFF -- -- Use for UNIX -- --@$TEMP/dt.tmp -- -- Use for Windows -- @%TEMP%\dt.tmp -- -- Common -- SET TERMOUT OFF -- -- Use for UNIX -- --HO rm $TEMP/dt.tmp --GET $TEMP/dt.sql.buffer.tmp --HO rm $TEMP/dt.sql.buffer.tmp -- -- Use for Windows -- HO del %TEMP%\dt.tmp GET %TEMP%\dt.sql.buffer.tmp HO del %TEMP%\dt.sql.buffer.tmp -- -- Common -- DEFINE 1='DD' SET TERMOUT ON FEEDBACK ON HEADING ON