Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Create Table default Date Value to TO_CHAR
I've created a table Barf as follows:
CREATE TABLE Barf (DBName Varchar2(15),UserName Varchar2(30), ConnectionDate DATE DEFAULT SYSDATE, UserCount NUMBER);
Then inserted a row:
INSERT INTO Barf (DBName,UserName,UserCount) VALUES ('ora.database','Development',234);
Then selected * from table Barf:
SELECT * FROM Barf;
DBNAME USERNAME CONNECTIO USERCOUNT --------------- ------------------------------ --------- ---------- ora.database Development 10-MAY-02234
Then selected the individual columns so i could TO_CHAR on the DATE column ConnectionDate to give the time as well.
SELECT DBName, UserName, TO_CHAR(ConnectionDate,'DD-MON-YYYY HH24:MI:SS'), UserCount FROM Barf;
DBNAME USERNAME TO_CHAR(CONNECTIONDAUSERCOUNT
--------------- ------------------------------ -------------------- ---------- ora.database Development10-MAY-200212:08:50 234
Fine.....
Now, is it possible to use the CREATE TABLE statement to automatically convert the SYSDATE default value column to a TO_CHAR so when you do a select * the time is there as well? Something along the lines of:
CREATE TABLE Barf (DBName Varchar2(15),UserName Varchar2(30), ConnectionDate DATE DEFAULT TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'), UserCount NUMBER);
ORA-01830: date format picture ends before converting entire input string Received on Fri May 10 2002 - 06:23:33 CDT