dbTalk Databases Forums  

CREATE OR REPLACE FUNCTION problem

comp.databases.oracle.server comp.databases.oracle.server


Discuss CREATE OR REPLACE FUNCTION problem in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chepurnykh
 
Posts: n/a

Default CREATE OR REPLACE FUNCTION problem - 06-30-2010 , 05:59 AM






Hello,

I need a function that converts date_to_unixtime.
I found a good select example in the post #4 by Mark Schrijver:
http://jehiah.cz/archive/oracle-date-to-unix-timestamp

I modified it a little and tried to make a function out of this
select. There is an error in the function, I can not figure it out.
Please help.

<pre>
CREATE OR REPLACE FUNCTION CURRENT_UNIXTIME_UTC_SEC RETURN number IS
xt number;
BEGIN
SELECT d * (24*60*60) + h * (60*60) + (m * 60) + s as unix_time
FROM (
SELECT to_number(rtrim(substr(dt, 2, instr(dt, ' ')-1))) d,
to_number(substr(dt, instr(dt, ' ')+1, 2)) h,
to_number(substr(dt, instr(dt, ':')+1, 2)) m,
to_number(substr(dt, instr(dt, '.')-2, 2)) s,
dt
FROM ( SELECT to_char(dt) dt
FROM (
SELECT (
sys_extract_utc(current_timestamp) -
TO_TIMESTAMP('01.01.1970','DD.MM.YYYY')) dt FROM dual
))) INTO xt;
RETURN xt;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20777,'An error encountered - '||
SQLCODE||' ERROR: '||SQLERRM);
END;
</pre>

Thank you!

Reply With Quote
  #2  
Old   
gazzag
 
Posts: n/a

Default Re: CREATE OR REPLACE FUNCTION problem - 06-30-2010 , 06:26 AM






On 30 June, 11:59, Chepurnykh <chepurn... (AT) gmail (DOT) com> wrote:
Quote:
Hello,

I need a function that converts date_to_unixtime.
I found a good select example in the post #4 by Mark Schrijver:http://jehiah.cz/archive/oracle-date-to-unix-timestamp

I modified it a little and tried to make a function out of this
select. There is an error in the function, I can not figure it out.
Please help.

pre
CREATE OR REPLACE FUNCTION CURRENT_UNIXTIME_UTC_SEC RETURN number IS
* *xt number;
BEGIN
* SELECT d * (24*60*60) + h * (60*60) + (m * 60) + s *as unix_time
FROM (
SELECT to_number(rtrim(substr(dt, 2, instr(dt, ' ')-1))) d,
* * to_number(substr(dt, instr(dt, ' ')+1, 2)) h,
* * to_number(substr(dt, instr(dt, ':')+1, 2)) m,
* * to_number(substr(dt, instr(dt, '.')-2, 2)) s,
* * dt
FROM ( SELECT to_char(dt) dt
FROM (
SELECT (
* * sys_extract_utc(current_timestamp) -
TO_TIMESTAMP('01.01.1970','DD.MM.YYYY')) dt FROM dual
* * ))) INTO xt;
RETURN xt;
EXCEPTION
WHEN OTHERS THEN
* * * raise_application_error(-20777,'An error encountered - '||
SQLCODE||' ERROR: '||SQLERRM);
END;
/pre

Thank you!
What error are you receiving?

HTH
-g

Reply With Quote
  #3  
Old   
Chepurnykh
 
Posts: n/a

Default Re: CREATE OR REPLACE FUNCTION problem - 06-30-2010 , 06:33 AM



Thank you :-)
Just fixed it. INTO was in a wrong place.

CREATE OR REPLACE FUNCTION CURRENT_UNIXTIME_UTC_SEC RETURN number IS
xt number;
BEGIN
SELECT (d * (24*60*60) + h * (60*60) + (m * 60) + s) as unix_time
into xt
FROM (
SELECT to_number(rtrim(substr(dt, 2, instr(dt, ' ')-1))) d,
to_number(substr(dt, instr(dt, ' ')+1, 2)) h,
to_number(substr(dt, instr(dt, ':')+1, 2)) m,
to_number(substr(dt, instr(dt, '.')-2, 2)) s,
dt
FROM ( SELECT to_char(dt) dt
FROM (
SELECT (
sys_extract_utc(current_timestamp) -
TO_TIMESTAMP('01.01.1970','DD.MM.YYYY')) dt FROM dual
)));
RETURN xt;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20777,'An error encountered - '||
SQLCODE||' ERROR: '||SQLERRM);
END;


On 30 июн, 15:26, gazzag <gar... (AT) jamms (DOT) org> wrote:
Quote:
What error are you receiving?

HTH
-g

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.