Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-33399

Package variables return a wrong result when changed inside a function

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL), 10.11, 11.0(EOL), 11.1(EOL), 11.2(EOL), 11.3(EOL), 11.4, 11.5(EOL)
    • 10.5
    • Stored routines
    • None

    Description

      I create the following package in Oracle-19.0 and call its procedure:

      CREATE OR REPLACE PACKAGE pkg AS
        PROCEDURE p1;
      END;
      /
       
      CREATE OR REPLACE PACKAGE BODY pkg AS
        a INT:=11;
        b INT:=10;
        FUNCTION f1 RETURN INT AS
        BEGIN
          a:=a-1;
          RETURN a;
        END;
        PROCEDURE p1 AS
          res VARCHAR(1024):= a || ' ' || f1() || ' ' || a;
        BEGIN
          DBMS_OUTPUT.PUT_LINE(res);
        END;
      BEGIN
        a:=a-b;
      END;
      /
       
      CALL pkg.p1();
      

      Statement processed.
      0 0 0
      

      Now I create the same package in MariaDB (in Oracle compatibility mode) and call its procedure:

      SET sql_mode=ORACLE;
      DELIMITER /
       
      CREATE OR REPLACE PACKAGE pkg AS
        PROCEDURE p1;
      END;
      /
       
      CREATE OR REPLACE PACKAGE BODY pkg AS
        a INT:=11;
        b INT:=10;
        FUNCTION f1 RETURN INT AS
        BEGIN
          a:=a-1;
          RETURN a;
        END;
        PROCEDURE p1 AS
          res VARCHAR(1024):= a || ' ' || f1() || ' ' || a;
        BEGIN
          SELECT res;
        END;
      BEGIN
        a:=a-b;
      END;
      /
       
      DELIMITER ;
      CALL pkg.p1();
      

      +-------+
      | res   |
      +-------+
      | 1 0 1 |
      +-------+
      

      Notice, it returns a different result.

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov created issue -
            bar Alexander Barkov made changes -
            Field Original Value New Value
            bar Alexander Barkov made changes -
            bar Alexander Barkov added a comment - - edited

            If I slightly change the script for Oracle-19.0 as follows, it still returns the same result with the first script version for Oracle:

            CREATE OR REPLACE PACKAGE pkg AS
              PROCEDURE p1;
            END;
            /
             
            CREATE OR REPLACE PACKAGE BODY pkg AS
              a INT:=11;
              b INT:=10;
              FUNCTION f1 RETURN INT AS
              BEGIN
                a:=a-1;
                RETURN a;
              END;
              PROCEDURE p1 AS
              BEGIN
                -- No variable, just print
                DBMS_OUTPUT.PUT_LINE(a || ' ' || f1() || ' ' || a);
              END;
            BEGIN
              a:=a-b;
            END;
            /
             
            CALL pkg.p1();
            

            Statement processed.
            0 0 0
            

            If I change the script for MariaDB the same way, it returns a different result (comparing to Oracle and comparing to the first MariaDB script):

            SET sql_mode=ORACLE;
            DELIMITER /
             
            CREATE OR REPLACE PACKAGE pkg AS
              PROCEDURE p1;
            END;
            /
             
            CREATE OR REPLACE PACKAGE BODY pkg AS
              a INT:=11;
              b INT:=10;
              FUNCTION f1 RETURN INT AS
              BEGIN
                a:=a-1;
                RETURN a;
              END;
              PROCEDURE p1 AS
              BEGIN
                -- No variable, just print it
                SELECT a || ' ' || f1() || ' ' || a;
              END;
            BEGIN
              a:=a-b;
            END;
            /
             
            DELIMITER ;
            CALL pkg.p1();
            

            +------------------------------+
            | a || ' ' || f1() || ' ' || a |
            +------------------------------+
            | 1 0 1                        |
            +------------------------------+
            

            bar Alexander Barkov added a comment - - edited If I slightly change the script for Oracle-19.0 as follows, it still returns the same result with the first script version for Oracle: CREATE OR REPLACE PACKAGE pkg AS PROCEDURE p1; END ; /   CREATE OR REPLACE PACKAGE BODY pkg AS a INT :=11; b INT :=10; FUNCTION f1 RETURN INT AS BEGIN a:=a-1; RETURN a; END ; PROCEDURE p1 AS BEGIN -- No variable, just print DBMS_OUTPUT.PUT_LINE(a || ' ' || f1() || ' ' || a); END ; BEGIN a:=a-b; END ; /   CALL pkg.p1(); Statement processed. 0 0 0 If I change the script for MariaDB the same way, it returns a different result (comparing to Oracle and comparing to the first MariaDB script): SET sql_mode=ORACLE; DELIMITER /   CREATE OR REPLACE PACKAGE pkg AS PROCEDURE p1; END ; /   CREATE OR REPLACE PACKAGE BODY pkg AS a INT :=11; b INT :=10; FUNCTION f1 RETURN INT AS BEGIN a:=a-1; RETURN a; END ; PROCEDURE p1 AS BEGIN -- No variable, just print it SELECT a || ' ' || f1() || ' ' || a; END ; BEGIN a:=a-b; END ; /   DELIMITER ; CALL pkg.p1(); +------------------------------+ | a || ' ' || f1() || ' ' || a | +------------------------------+ | 1 0 1 | +------------------------------+
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 11.5 [ 29506 ]

            People

              Unassigned Unassigned
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.