Error in return of PLSQL ORACLE Not Working












0















This Code is:



CREATE OR REPLACE
PROCEDURE Actualiza_Saldo(fecha_ini IN DATE, fecha_fin IN DATE) RETURN NUMBER
AS
fechaTemp DATE;
diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
BEGIN
diasLaborables:= diastotales;

FOR i IN 0..diasTotales LOOP
fechaTemp := fecha_ini + i;
DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
diaslaborables := diaslaborables-1;
END IF;
END LOOP;
dbms_output.put_line(diaslaborables);
RETURN diasLaborables;
END Actualiza_Saldo;


If I execute without returning it works, if I try to return a value it fails, I do not know what could be happening.



The error of oracle is:



Warning: la ejecución ha terminado con advertencias
PROCEDURE Actualiza_Saldo(fecha_ini Compilado.

Error que empieza en la línea 1 del comando:
EXEC Actualiza_Saldo();
Informe de error:
ORA-06550: línea 1, columna 7:
PLS-00905: el objeto HR.ACTUALIZA_SALDO no es válido
ORA-06550: línea 1, columna 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:


The code with constant value:



CREATE OR REPLACE
PROCEDURE Actualiza_Saldo(fecha_ini IN DATE DEFAULT '10/08/2018', fecha_fin IN DATE DEFAULT '30/08/2018')
AS
fechaTemp DATE;
diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
BEGIN
diasLaborables:= diastotales;

FOR i IN 0..diasTotales LOOP
fechaTemp := fecha_ini + i;
DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
diaslaborables := diaslaborables-1;
END IF;
END LOOP;
dbms_output.put_line(diaslaborables);
END Actualiza_Saldo;

EXEC Actualiza_Saldo();


And the exit of the code without the returns and the test values ​​is a route from the start date and the final date subtracting the days Saturday and Sunday.



PROCEDURE Actualiza_Saldo(fecha_ini Compilado.
anonymous block completed
10/08/18
11/08/18
12/08/18
13/08/18
14/08/18
15/08/18
16/08/18
17/08/18
18/08/18
19/08/18
20/08/18
21/08/18
22/08/18
23/08/18
24/08/18
25/08/18
26/08/18
27/08/18
28/08/18
29/08/18
30/08/18
14


But if I try to return the value the algorithm dies.
I have no idea what I am doing wrong or where is the fault, if you could help me I would greatly appreciate it.










share|improve this question



























    0















    This Code is:



    CREATE OR REPLACE
    PROCEDURE Actualiza_Saldo(fecha_ini IN DATE, fecha_fin IN DATE) RETURN NUMBER
    AS
    fechaTemp DATE;
    diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
    sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
    BEGIN
    diasLaborables:= diastotales;

    FOR i IN 0..diasTotales LOOP
    fechaTemp := fecha_ini + i;
    DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
    diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
    IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
    diaslaborables := diaslaborables-1;
    END IF;
    END LOOP;
    dbms_output.put_line(diaslaborables);
    RETURN diasLaborables;
    END Actualiza_Saldo;


    If I execute without returning it works, if I try to return a value it fails, I do not know what could be happening.



    The error of oracle is:



    Warning: la ejecución ha terminado con advertencias
    PROCEDURE Actualiza_Saldo(fecha_ini Compilado.

    Error que empieza en la línea 1 del comando:
    EXEC Actualiza_Saldo();
    Informe de error:
    ORA-06550: línea 1, columna 7:
    PLS-00905: el objeto HR.ACTUALIZA_SALDO no es válido
    ORA-06550: línea 1, columna 7:
    PL/SQL: Statement ignored
    06550. 00000 - "line %s, column %s:n%s"
    *Cause: Usually a PL/SQL compilation error.
    *Action:


    The code with constant value:



    CREATE OR REPLACE
    PROCEDURE Actualiza_Saldo(fecha_ini IN DATE DEFAULT '10/08/2018', fecha_fin IN DATE DEFAULT '30/08/2018')
    AS
    fechaTemp DATE;
    diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
    sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
    BEGIN
    diasLaborables:= diastotales;

    FOR i IN 0..diasTotales LOOP
    fechaTemp := fecha_ini + i;
    DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
    diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
    IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
    diaslaborables := diaslaborables-1;
    END IF;
    END LOOP;
    dbms_output.put_line(diaslaborables);
    END Actualiza_Saldo;

    EXEC Actualiza_Saldo();


    And the exit of the code without the returns and the test values ​​is a route from the start date and the final date subtracting the days Saturday and Sunday.



    PROCEDURE Actualiza_Saldo(fecha_ini Compilado.
    anonymous block completed
    10/08/18
    11/08/18
    12/08/18
    13/08/18
    14/08/18
    15/08/18
    16/08/18
    17/08/18
    18/08/18
    19/08/18
    20/08/18
    21/08/18
    22/08/18
    23/08/18
    24/08/18
    25/08/18
    26/08/18
    27/08/18
    28/08/18
    29/08/18
    30/08/18
    14


    But if I try to return the value the algorithm dies.
    I have no idea what I am doing wrong or where is the fault, if you could help me I would greatly appreciate it.










    share|improve this question

























      0












      0








      0








      This Code is:



      CREATE OR REPLACE
      PROCEDURE Actualiza_Saldo(fecha_ini IN DATE, fecha_fin IN DATE) RETURN NUMBER
      AS
      fechaTemp DATE;
      diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
      sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
      BEGIN
      diasLaborables:= diastotales;

      FOR i IN 0..diasTotales LOOP
      fechaTemp := fecha_ini + i;
      DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
      diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
      IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
      diaslaborables := diaslaborables-1;
      END IF;
      END LOOP;
      dbms_output.put_line(diaslaborables);
      RETURN diasLaborables;
      END Actualiza_Saldo;


      If I execute without returning it works, if I try to return a value it fails, I do not know what could be happening.



      The error of oracle is:



      Warning: la ejecución ha terminado con advertencias
      PROCEDURE Actualiza_Saldo(fecha_ini Compilado.

      Error que empieza en la línea 1 del comando:
      EXEC Actualiza_Saldo();
      Informe de error:
      ORA-06550: línea 1, columna 7:
      PLS-00905: el objeto HR.ACTUALIZA_SALDO no es válido
      ORA-06550: línea 1, columna 7:
      PL/SQL: Statement ignored
      06550. 00000 - "line %s, column %s:n%s"
      *Cause: Usually a PL/SQL compilation error.
      *Action:


      The code with constant value:



      CREATE OR REPLACE
      PROCEDURE Actualiza_Saldo(fecha_ini IN DATE DEFAULT '10/08/2018', fecha_fin IN DATE DEFAULT '30/08/2018')
      AS
      fechaTemp DATE;
      diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
      sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
      BEGIN
      diasLaborables:= diastotales;

      FOR i IN 0..diasTotales LOOP
      fechaTemp := fecha_ini + i;
      DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
      diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
      IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
      diaslaborables := diaslaborables-1;
      END IF;
      END LOOP;
      dbms_output.put_line(diaslaborables);
      END Actualiza_Saldo;

      EXEC Actualiza_Saldo();


      And the exit of the code without the returns and the test values ​​is a route from the start date and the final date subtracting the days Saturday and Sunday.



      PROCEDURE Actualiza_Saldo(fecha_ini Compilado.
      anonymous block completed
      10/08/18
      11/08/18
      12/08/18
      13/08/18
      14/08/18
      15/08/18
      16/08/18
      17/08/18
      18/08/18
      19/08/18
      20/08/18
      21/08/18
      22/08/18
      23/08/18
      24/08/18
      25/08/18
      26/08/18
      27/08/18
      28/08/18
      29/08/18
      30/08/18
      14


      But if I try to return the value the algorithm dies.
      I have no idea what I am doing wrong or where is the fault, if you could help me I would greatly appreciate it.










      share|improve this question














      This Code is:



      CREATE OR REPLACE
      PROCEDURE Actualiza_Saldo(fecha_ini IN DATE, fecha_fin IN DATE) RETURN NUMBER
      AS
      fechaTemp DATE;
      diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
      sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
      BEGIN
      diasLaborables:= diastotales;

      FOR i IN 0..diasTotales LOOP
      fechaTemp := fecha_ini + i;
      DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
      diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
      IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
      diaslaborables := diaslaborables-1;
      END IF;
      END LOOP;
      dbms_output.put_line(diaslaborables);
      RETURN diasLaborables;
      END Actualiza_Saldo;


      If I execute without returning it works, if I try to return a value it fails, I do not know what could be happening.



      The error of oracle is:



      Warning: la ejecución ha terminado con advertencias
      PROCEDURE Actualiza_Saldo(fecha_ini Compilado.

      Error que empieza en la línea 1 del comando:
      EXEC Actualiza_Saldo();
      Informe de error:
      ORA-06550: línea 1, columna 7:
      PLS-00905: el objeto HR.ACTUALIZA_SALDO no es válido
      ORA-06550: línea 1, columna 7:
      PL/SQL: Statement ignored
      06550. 00000 - "line %s, column %s:n%s"
      *Cause: Usually a PL/SQL compilation error.
      *Action:


      The code with constant value:



      CREATE OR REPLACE
      PROCEDURE Actualiza_Saldo(fecha_ini IN DATE DEFAULT '10/08/2018', fecha_fin IN DATE DEFAULT '30/08/2018')
      AS
      fechaTemp DATE;
      diasTotales NUMBER := fecha_fin- fecha_ini;diasLaborables NUMBER;
      sab VARCHAR2(10) := 'SÁBADO';dom VARCHAR2(10) := 'DOMINGO';diasTemp VARCHAR2(10);
      BEGIN
      diasLaborables:= diastotales;

      FOR i IN 0..diasTotales LOOP
      fechaTemp := fecha_ini + i;
      DBMS_OUTPUT.PUT_LINE(to_char(fechaTemp));
      diasTemp := TO_CHAR(fechaTemp, 'DAY', 'NLS_DATE_LANGUAGE=SPANISH');
      IF (TRIM(diasTemp)=sab or TRIM(diasTemp)=dom) THEN
      diaslaborables := diaslaborables-1;
      END IF;
      END LOOP;
      dbms_output.put_line(diaslaborables);
      END Actualiza_Saldo;

      EXEC Actualiza_Saldo();


      And the exit of the code without the returns and the test values ​​is a route from the start date and the final date subtracting the days Saturday and Sunday.



      PROCEDURE Actualiza_Saldo(fecha_ini Compilado.
      anonymous block completed
      10/08/18
      11/08/18
      12/08/18
      13/08/18
      14/08/18
      15/08/18
      16/08/18
      17/08/18
      18/08/18
      19/08/18
      20/08/18
      21/08/18
      22/08/18
      23/08/18
      24/08/18
      25/08/18
      26/08/18
      27/08/18
      28/08/18
      29/08/18
      30/08/18
      14


      But if I try to return the value the algorithm dies.
      I have no idea what I am doing wrong or where is the fault, if you could help me I would greatly appreciate it.







      sql oracle plsql compiler-errors plsqldeveloper






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 1:53









      Yined Milanyela Molina BarriosYined Milanyela Molina Barrios

      34




      34
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Procedures cannot return a value, in Oracle, You can have out-parameters which would be visible after the procedure runs.



          But here is another option you can try, instead of writing code to generate dates between two, try to do it using a single select query and open a out cursor to have the values populated after the proc completes



          An example as follows



          create or replace procedure generate_dates(start_date in date, end_date in date, result_set out sys_refcursor)
          as
          begin
          open result_set for
          select trunc(start_date)+level as output_dates
          from dual
          connect by level<=trunc(end_date)-trunc(start_date);
          end;


          if you are using sqlplus to connect to your database



          you would call the proc as follows



          var x refcursor

          begin
          generate_dates(date '2018-01-01',date '2018-12-31',:x);
          end;

          print x;





          share|improve this answer































            0














            My mistake was that I was not doing a function but a procedure solved.



            CREATE OR REPLACE
            FUNCTION HR.Actualiza_Saldo(fecha_ini IN DATE/* DEFAULT '10/08/2018'*/, fecha_fin IN DATE/* DEFAULT '30/08/2018'*/) RETURN NUMBER
            AS





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439801%2ferror-in-return-of-plsql-oracle-not-working%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Procedures cannot return a value, in Oracle, You can have out-parameters which would be visible after the procedure runs.



              But here is another option you can try, instead of writing code to generate dates between two, try to do it using a single select query and open a out cursor to have the values populated after the proc completes



              An example as follows



              create or replace procedure generate_dates(start_date in date, end_date in date, result_set out sys_refcursor)
              as
              begin
              open result_set for
              select trunc(start_date)+level as output_dates
              from dual
              connect by level<=trunc(end_date)-trunc(start_date);
              end;


              if you are using sqlplus to connect to your database



              you would call the proc as follows



              var x refcursor

              begin
              generate_dates(date '2018-01-01',date '2018-12-31',:x);
              end;

              print x;





              share|improve this answer




























                1














                Procedures cannot return a value, in Oracle, You can have out-parameters which would be visible after the procedure runs.



                But here is another option you can try, instead of writing code to generate dates between two, try to do it using a single select query and open a out cursor to have the values populated after the proc completes



                An example as follows



                create or replace procedure generate_dates(start_date in date, end_date in date, result_set out sys_refcursor)
                as
                begin
                open result_set for
                select trunc(start_date)+level as output_dates
                from dual
                connect by level<=trunc(end_date)-trunc(start_date);
                end;


                if you are using sqlplus to connect to your database



                you would call the proc as follows



                var x refcursor

                begin
                generate_dates(date '2018-01-01',date '2018-12-31',:x);
                end;

                print x;





                share|improve this answer


























                  1












                  1








                  1







                  Procedures cannot return a value, in Oracle, You can have out-parameters which would be visible after the procedure runs.



                  But here is another option you can try, instead of writing code to generate dates between two, try to do it using a single select query and open a out cursor to have the values populated after the proc completes



                  An example as follows



                  create or replace procedure generate_dates(start_date in date, end_date in date, result_set out sys_refcursor)
                  as
                  begin
                  open result_set for
                  select trunc(start_date)+level as output_dates
                  from dual
                  connect by level<=trunc(end_date)-trunc(start_date);
                  end;


                  if you are using sqlplus to connect to your database



                  you would call the proc as follows



                  var x refcursor

                  begin
                  generate_dates(date '2018-01-01',date '2018-12-31',:x);
                  end;

                  print x;





                  share|improve this answer













                  Procedures cannot return a value, in Oracle, You can have out-parameters which would be visible after the procedure runs.



                  But here is another option you can try, instead of writing code to generate dates between two, try to do it using a single select query and open a out cursor to have the values populated after the proc completes



                  An example as follows



                  create or replace procedure generate_dates(start_date in date, end_date in date, result_set out sys_refcursor)
                  as
                  begin
                  open result_set for
                  select trunc(start_date)+level as output_dates
                  from dual
                  connect by level<=trunc(end_date)-trunc(start_date);
                  end;


                  if you are using sqlplus to connect to your database



                  you would call the proc as follows



                  var x refcursor

                  begin
                  generate_dates(date '2018-01-01',date '2018-12-31',:x);
                  end;

                  print x;






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 2:09









                  George JosephGeorge Joseph

                  1,46559




                  1,46559

























                      0














                      My mistake was that I was not doing a function but a procedure solved.



                      CREATE OR REPLACE
                      FUNCTION HR.Actualiza_Saldo(fecha_ini IN DATE/* DEFAULT '10/08/2018'*/, fecha_fin IN DATE/* DEFAULT '30/08/2018'*/) RETURN NUMBER
                      AS





                      share|improve this answer




























                        0














                        My mistake was that I was not doing a function but a procedure solved.



                        CREATE OR REPLACE
                        FUNCTION HR.Actualiza_Saldo(fecha_ini IN DATE/* DEFAULT '10/08/2018'*/, fecha_fin IN DATE/* DEFAULT '30/08/2018'*/) RETURN NUMBER
                        AS





                        share|improve this answer


























                          0












                          0








                          0







                          My mistake was that I was not doing a function but a procedure solved.



                          CREATE OR REPLACE
                          FUNCTION HR.Actualiza_Saldo(fecha_ini IN DATE/* DEFAULT '10/08/2018'*/, fecha_fin IN DATE/* DEFAULT '30/08/2018'*/) RETURN NUMBER
                          AS





                          share|improve this answer













                          My mistake was that I was not doing a function but a procedure solved.



                          CREATE OR REPLACE
                          FUNCTION HR.Actualiza_Saldo(fecha_ini IN DATE/* DEFAULT '10/08/2018'*/, fecha_fin IN DATE/* DEFAULT '30/08/2018'*/) RETURN NUMBER
                          AS






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 23 '18 at 2:22









                          Yined Milanyela Molina BarriosYined Milanyela Molina Barrios

                          34




                          34






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439801%2ferror-in-return-of-plsql-oracle-not-working%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Wiesbaden

                              Marschland

                              Dieringhausen