Conversion timestamp vers date
Salut a tous,
oracle 11g sous linux
Soit une table TEST avec un champ fecha(date) de type NUMBER
Dans le champs
Code:
1 2 3 4 5
| SQL> select fecha "date" from test;
date
----------
1,0819E+12 |
Ce que je voudrais c'est faire une select et dortir la date qui corespond.
J'ai Googeler un peu et j'ai trouvé la fonction suivante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| SQL> CREATE OR REPLACE
2 FUNCTION unixts_to_date(unixts IN PLS_INTEGER) RETURN DATE IS
3 /**
4 * Converts a UNIX timestamp into an Oracle DATE
5 */
6 unix_epoch DATE := TO_DATE('19700101000000','YYYYMMDDHH24MISS');
7 max_ts PLS_INTEGER := 2145916799; -- 2938-12-31 23:59:59
8 min_ts PLS_INTEGER := -2114380800; -- 1903-01-01 00:00:00
9 oracle_date DATE;
10
11 BEGIN
12
13 IF unixts> max_ts THEN
14 RAISE_APPLICATION_ERROR(
15 -20901,
16 'UNIX timestamp too large for 32 bit limit'
17 );
18 ELSIF unixts <min_ts THEN
19 RAISE_APPLICATION_ERROR(
20 -20901,
21 'UNIX timestamp too small for 32 bit limit' );
22 ELSE
23 oracle_date := unix_epoch + NUMTODSINTERVAL(unixts, 'SECOND');
24 END IF;
25
26 RETURN (oracle_date);
27
28 END;
29 / |
Function created.
Mais...ça donne l'erreur que vous pouvez voir:
Code:
1 2 3 4 5 6
| SQL> select unixts_to_date(1081936800000) from dual;
select unixts_to_date(1081936800000) from dual
*
ERROR at line 1:
ORA-20901: UNIX timestamp too large for 32 bit limit
ORA-06512: en "EXPLO.UNIXTS_TO_DATE", linea 13 |
Ça serait plus facil avec un champ de type timestamp mais la base n'a pas ete faite comme ça. Existe t'il une solution?
D'avance merci