Oracle does not have the date () function. The sysdate function value includes the time, minute, and second. It is really troublesome to insert the default value of the current time.
You have to write the stored procedure on your own, and you cannot call the stored procedure in the field default value. You have to write a trigger! The first few digits of sysdate obtained during the storage process are only in the format of-07, instead of what you want, in the format of-11-17, you have to combine the values of year, month, and day separately, so that the return value cannot be a date type but a character type.
A word is annoying! But I still implemented it. I will share with you the code below. If there is a better way, please let us know.
1. Storage Process
Create or replace function "GET_DATE" RETURN VARCHAR2
IS
Yyyy varchar2 (36 );
Mm varchar2 (36 );
Dd varchar2 (36 );
Tempdate varchar2 (36 );
BEGIN
Tempdate: = '';
Select to_char (to_date (sysdate), 'yyyy') into YYYY from dual;
Select to_char (to_date (sysdate), 'mm') into MM from dual;
Select to_char (to_date (sysdate), 'dd') into DD from dual;
Tempdate: = substr (yyyy, 1, 4) | '-' |
Substr (mm, 1, 2) | '-' |
Substr (dd, 1, 2)
;
Return tempdate;
END;
2. triggers
Create or replace trigger STATWEEK_tg
-- STATWEEK fdate trigger
BEFORE INSERT ON STATWEEK FOR EACH ROW
BEGIN
SELECT get_date INTO: NEW. fdate from dual;
END;
Note: STATWEEK indicates that the corresponding data table fdate is an Automatically increasing field, and get_date indicates the corresponding stored procedure name.
3. Data Table
-- Create table
Create table STATWEEK
(
Monday VARCHAR2 (20) default 0,
Tuesday VARCHAR2 (20) default 0,
Wednesday VARCHAR2 (20) default 0,
Thursday VARCHAR2 (20) default 0,
Friday VARCHAR2 (20) default 0,
Saturday VARCHAR2 (20) default 0,
Sunday VARCHAR2 (20) default 0,
TWEEK VARCHAR2 (10 ),
ADMIN VARCHAR2 (50 ),
FDATE VARCHAR2 (20)
)