Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 587373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:12:20+00:00 2026-05-13T15:12:20+00:00

I’m having problems retrieving the time from a date field in a SP. If

  • 0

I’m having problems retrieving the time from a date field in a SP. If I run the query:

select TO_CHAR(HOR_HST_ATN,'YYYY/MM/DD HH24:MI:SS') AS HOR_HST_ATN FROM AAM0_DT_RSTCN ;

It returns the date and time ok.

But in the SP, the code:

SELECT   FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN, 
    TO_DATE(HOR_DSD_ATN ,'DD/MM/YYYY HH24:MI:SS') as  HOR_DSD_ATN,
    TO_DATE(HOR_HST_ATN,'DD/MM/YYYY HH24:MI:SS') as HOR_HST_ATN

returns just the date ok but the time is 00:00

If I try the select in the SP with TO_CHAR as in:

SELECT   FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN,
 TO_CHAR(HOR_DSD_ATN ,'YYYY/MM/DD HH24:MI:SS') as  HOR_DSD_ATN,
 TO_CHAR(HOR_HST_ATN,'YYYY/MM/DD HH24:MI:SS') as HOR_HST_ATN

I get the error: SQLCODE: -6502 SQLERRM: ORA-06502: PL/SQL: error …

Any clues ? BTW I must use a SP to retrieve this value.

Update: the column is type date. Here’s the full SP:

FUNCTION FN_AAM_EV_RSTCN ( 

I_NUM_CONTRATO            IN  AAM0_DT_RSTCN.NUM_CONTRATO%TYPE,
I_COD_PFL                  IN  AAM0_DT_RSTCN.COD_PFL%TYPE, 
I_COD_APL_PFM              IN  AAM0_DT_RSTCN.COD_APL_PFM%TYPE, 
I_COD_PTO                  IN  AAM0_DT_RSTCN.COD_PTO%TYPE, 
I_COD_FNC                  IN  AAM0_DT_RSTCN.COD_FNC%TYPE
) RETURN BOOLEAN
AS
T_FEC_DSD_ATN                   AAM0_DT_RSTCN.FEC_DSD_ATN%TYPE;
T_HOR_DSD_ATN                   AAM0_DT_RSTCN.HOR_DSD_ATN%TYPE;
T_FEC_HST_ATN                   AAM0_DT_RSTCN.FEC_HST_ATN%TYPE;
T_HOR_HST_ATN                   AAM0_DT_RSTCN.HOR_HST_ATN%TYPE;
T_NOM_SEM_DSD_ATN               AAM0_DT_RSTCN.NOM_SEM_DSD_ATN%TYPE;
T_NOM_SEM_HST_ATN               AAM0_DT_RSTCN.NOM_SEM_HST_ATN%TYPE;

 O_RESULTSET2          REST_REFCUR;

BEGIN
 OPEN O_RESULTSET2 FOR 

   SELECT   FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN, 
    TO_CHAR(HOR_DSD_ATN ,'DD/MM/YYYY HH24:MI:SS') as  HOR_DSD_ATN,
    TO_CHAR(HOR_HST_ATN,'DD/MM/YYYY HH24:MI:SS') as HOR_HST_ATN
    FROM    AAM0_DT_RSTCN
    WHERE ROWNUM <=1
    AND   NUM_CONTRATO          = NVL ( I_NUM_CONTRATO, NUM_CONTRATO )
    AND     COD_PFL               = NVL ( I_COD_PFL, COD_PFL )
    AND     COD_APL_PFM           = NVL ( I_COD_APL_PFM, COD_APL_PFM )
    AND     COD_PTO               = NVL ( I_COD_PTO, COD_PTO )
    AND     COD_FNC               = NVL ( I_COD_FNC, COD_FNC )    
    AND     FLG_RCS               = 'D'
    AND     COD_TPO_CDC           = 'PC'
    ;

   FETCH O_RESULTSET2 INTO T_FEC_DSD_ATN, T_FEC_HST_ATN, T_NOM_SEM_DSD_ATN, T_NOM_SEM_HST_ATN, T_HOR_DSD_ATN, T_HOR_HST_ATN ;

  IF (O_RESULTSET2%NOTFOUND) THEN
    RETURN TRUE;
  ELSE
   dbms_output.put_line('EVALUO RESTRICCIONES: T_FEC_DSD_ATN '  || T_FEC_DSD_ATN || ' T_FEC_HST_ATN : ' || T_FEC_HST_ATN || ' T_NOM_SEM_DSD_ATN: ' ||
                 T_NOM_SEM_DSD_ATN || ' T_NOM_SEM_HST_ATN: '  || T_NOM_SEM_HST_ATN || ' T_HOR_DSD_ATN: ' || TO_CHAR(T_HOR_DSD_ATN ,'DD/MM/YYYY HH24:MI:SS')  || 
                ' T_HOR_HST_ATN: ' || TO_CHAR(T_HOR_HST_ATN ,'DD/MM/YYYY HH24:MI:SS') );

     IF (NOT((T_FEC_DSD_ATN IS NULL) and (T_FEC_HST_ATN IS NULL)) ) THEN

       IF ( NOT ((T_FEC_DSD_ATN  <= SYSDATE) AND (T_FEC_HST_ATN >= SYSDATE ))) THEN
                RETURN FALSE;
        END IF ;

    END IF ;

  RETURN TRUE;

  END IF ;

EXCEPTION

  WHEN NO_DATA_FOUND THEN
    RETURN TRUE; 

  WHEN OTHERS THEN


    IF O_RESULTSET2%ISOPEN THEN

      CLOSE O_RESULTSET2;

    END IF;


    DBMS_OUTPUT.PUT_LINE('ERROR en FN_AAM_EV_RSTCN : '); 
    DBMS_OUTPUT.PUT_LINE('  SQLCODE: ' || SQLCODE );
    DBMS_OUTPUT.PUT_LINE('  SQLERRM: ' || SQLERRM );

    ROLLBACK;

 END FN_AAM_EV_RSTCN;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:12:20+00:00Added an answer on May 13, 2026 at 3:12 pm

    Since the TO_DATE function takes a VARCHAR as argument, you wouldn’t use this function on a DATE field. If you want to retrieve both the date and the time from a DATE field you would just SELECT the fields without functions:

    SELECT   FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN, 
             HOR_DSD_ATN, HOR_HST_ATN
       ...
    

    update

    The problem is that you are fetching TO_CHAR(HOR_DSD_ATN, 'DD/MM/YYYY HH24:MI:SS') into a DATE field. There is an implicit conversion that truncates your date. Use to_char on a DATE variable and use to_date on a CHAR variable.

    My suggestion:

    FUNCTION FN_AAM_EV_RSTCN(I_NUM_CONTRATO IN AAM0_DT_RSTCN.NUM_CONTRATO%TYPE,
                             I_COD_PFL      IN AAM0_DT_RSTCN.COD_PFL%TYPE,
                             I_COD_APL_PFM  IN AAM0_DT_RSTCN.COD_APL_PFM%TYPE,
                             I_COD_PTO      IN AAM0_DT_RSTCN.COD_PTO%TYPE,
                             I_COD_FNC      IN AAM0_DT_RSTCN.COD_FNC%TYPE) 
       RETURN BOOLEAN AS
    BEGIN
       FOR cc IN (SELECT FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, 
                         NOM_SEM_HST_ATN, HOR_DSD_ATN, HOR_HST_ATN
                    FROM AAM0_DT_RSTCN
                   WHERE ROWNUM <= 1
                     AND NUM_CONTRATO = NVL(I_NUM_CONTRATO, NUM_CONTRATO)
                     AND COD_PFL = NVL(I_COD_PFL, COD_PFL)
                     AND COD_APL_PFM = NVL(I_COD_APL_PFM, COD_APL_PFM)
                     AND COD_PTO = NVL(I_COD_PTO, COD_PTO)
                     AND COD_FNC = NVL(I_COD_FNC, COD_FNC)
                     AND FLG_RCS = 'D'
                     AND COD_TPO_CDC = 'PC') LOOP
          dbms_output.put_line(' T_HOR_DSD_ATN: ' || 
                               TO_CHAR(cc.HOR_DSD_ATN, 'DD/MM/YYYY HH24:MI:SS') ||
                               ' T_HOR_HST_ATN: ' || 
                               TO_CHAR(cc.HOR_HST_ATN, 'DD/MM/YYYY HH24:MI:SS'));
          -- your logic with return boolean
       END LOOP;
       -- no rows found
       RETURN TRUE;
    EXCEPTION
       WHEN OTHERS THEN
          DBMS_OUTPUT.PUT_LINE('ERROR en FN_AAM_EV_RSTCN : ');
          DBMS_OUTPUT.PUT_LINE('  SQLCODE: ' || SQLCODE);
          DBMS_OUTPUT.PUT_LINE('  SQLERRM: ' || SQLERRM);
          RAISE;
    END FN_AAM_EV_RSTCN;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 308k
  • Answers 308k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you can't drop the constraint, you can't use TRUNCATE… May 13, 2026 at 9:50 pm
  • Editorial Team
    Editorial Team added an answer For starters, I think the first query can probably be… May 13, 2026 at 9:50 pm
  • Editorial Team
    Editorial Team added an answer You can do this easily (and without jQuery) with element.offsetWidth… May 13, 2026 at 9:49 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.