Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Simple trunc function not working...

577702Nov 24 2008 — edited Nov 25 2008
Hi,

i've created this function which takes a TIMESTAMP as a parameter and returns a truncated TIMESTAMP (truncated on 30 minutes).

I receive an error ORA-01843 Not a valid date. I haven't got a clue what's going wrong?
create or replace function trunc30 (p_timestamp timestamp) return timestamp
as 
    p_result    timestamp;
begin 
    SELECT 
      CASE WHEN (to_number(to_char(p_timestamp,'MI')) < 15 OR to_number(to_char(p_timestamp,'MI')) >= 45) THEN
        to_char(trunc(p_timestamp,'HH'),'HH24:MI') 
      ELSE 
        to_char(trunc(p_timestamp,'HH') + 30/(60*24),'HH24:MI') 
      END
    into p_result from dual; 
    return p_result; 
end;
I use this code to test the function:
DECLARE
  P_TIMESTAMP TIMESTAMP;
  v_Return TIMESTAMP;
BEGIN
  P_TIMESTAMP := TO_DATE('10/15/2008 15:44','MM/dd/yyyy HH24:MI');

  v_Return := TRUNC30(
    P_TIMESTAMP => P_TIMESTAMP
  );
  DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;
This post has been answered by Satyaki_De on Nov 24 2008
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 23 2008
Added on Nov 24 2008
7 comments
586 views