We help IT Professionals succeed at work.
Get Started

cursor not returning

orauser
orauser asked
on
337 Views
Last Modified: 2012-05-10
I have to test a function that finds a date's year and week number based on the company fiscal year.  It works for the first record but not the second, even though they both pass the same date.  What is wrong?  DBMS output results in attachment.

        OK_DATE := VERIF_DATE (to_Date(to_char(R.WKL_DATE), 'DD-MON-YYYY'));
---
      FUNCTION VERIF_DATE (P_DATE DATE)
         RETURN VARCHAR2 IS
         CURSOR C (X_DATE DATE) IS
            SELECT ZMER0002 (X_DATE)
                 , ZMER0001 (X_DATE)
                 , ZMER0029 (ZMER0002 (X_DATE)
                           , ZMER0001 (X_DATE)
                           , 'WEK'
                           , 'E')
                 , 'Y'
              FROM DUAL;

         CURSOR D IS
            SELECT TO_CHAR (P_DATE, 'D') FROM DUAL;

         V_WEEK_DAY   VARCHAR2 (30);
         V_DATE           DATE;
         DUMMY            VARCHAR2 (1);
         --new
         s_40                date;
         
      BEGIN
     
      --new
       DUMMY := 'N';
      s_40 := (to_date(to_char(sysdate),'DD-MON-YYYY') - 40);
     
        dbms_output.put_line('dummy start = ' || DUMMY);
       dbms_output.put_line('P_DATE = ' || P_DATE);
           dbms_output.put_line('s_40 = ' ||s_40);
           
        IF ((P_DATE > SYSDATE)  or (p_date < s_40)) THEN
        dbms_output.put_line('here');
            V_YYYY := NULL;
           V_WEEK := NULL;
           DUMMY := 'N';
        ELSE
            V_DATE := P_DATE;
           --             V_DATE := TO_DATE(P_DATE,'DD-MON-RRRR');

       dbms_output.put_line('V_DATE = ' || V_DATE);
       
            OPEN D;
            FETCH D INTO V_WEEK_DAY;
            CLOSE D;

            IF V_WEEK_DAY = '1' THEN -- sunday means celui de la semaine precedente
               V_DATE := V_DATE - 1;
            END IF;

            OPEN C (V_DATE);
            FETCH C INTO V_YYYY, V_WEEK, V_CAL_END_DATE, DUMMY;
           
                                 dbms_output.put_line('dummy1 = ' || DUMMY);
                      dbms_output.put_line('year1 = ' || V_YYYY);
                                            dbms_output.put_line('week1 = ' ||V_WEEK);

            IF C%NOTFOUND THEN
                V_YYYY := NULL;
                V_WEEK := NULL;
                DUMMY := 'N';
            END IF;

            CLOSE C;            
         END IF;
         
                     dbms_output.put_line('dummy2 = ' || DUMMY);
                      dbms_output.put_line('year2 = ' || V_YYYY);
                                            dbms_output.put_line('week2 = ' ||V_WEEK);
  dbms_output.put_line('end');
         RETURN (DUMMY);
      END;

toad-dbms-output.doc
Comment
Watch Question
Senior Oracle DBA
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE