I am using Adminer 4.7.3 connecting to an oracle DB and I want to display dates in a different format from what the default is ('DD-MON-YY'). I tried using the command
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH:MI:SS'
but it only lasts for that query, and it goes back to the old date format once I open the table again. Is there a better way to force the date to show up in a different format?
Asked
Active
Viewed 1,299 times
0

yunyun333
- 131
- 1
- 7
-
I think you can set `NLS_DATE_FORMAT` in environment variable. Then it should be default to that. – Wernfried Domscheit Oct 03 '19 at 17:26
1 Answers
1
You have a few options. First, you can perform an
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH:MI:SS'
every time you log on. If you don't want to do this you can:
If you're using *nix:
setenv NLS_DATE_FORMAT "dd-mon-yyyy hh:mi:ss"
If you're using Windows:
Control Panel-System-Advanced System Settings-Environment Variables, and create the NLS_DATE_FORMAT environment variable with the appropriate setting.
If you want an entirely database-dependent solution, you can use an
ON LOGON
trigger similar to the following:CREATE OR REPLACE TRIGGER DATABASE_AFTER_LOGON AFTER LOGON ON DATABASE BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = ''DD-MON-YYYY HH:MI:SS'''; END DATABASE_AFTER_LOGON;

Bob Jarvis - Слава Україні
- 48,992
- 9
- 77
- 110
-
I tried doing the first thing, but it doesn't "last"; with Adminer, I can enter the command and then enter another query, like 'ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH:MI:SS; SELECT * FROM dates_table' and it will work, but then if I enter another query, it will show the dates in the default format. – yunyun333 Oct 10 '19 at 19:03