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

Syntax error on a CURSOR..IS declaration in PACKAGE BODY

Details

    Description

      This script return a syntax error near 'CURSOR cur IS...':

      SET sql_mode=ORACLE;
      DROP PACKAGE pkg;
      DELIMITER /
      CREATE PACKAGE pkg AS
        FUNCTION f1 RETURN INT;
      END;
      /
      CREATE PACKAGE BODY pkg AS
        vc INT := 0;
        CURSOR cur IS SELECT 1 AS c FROM DUAL; -- Error is raised incorectly
        FUNCTION f1 RETURN INT AS
        BEGIN
          OPEN cur;
          FETCH cur INTO vc;
          CLOSE cur;
          RETURN vc;
        END;
      END;
      /
      DELIMITER ;
      SELECT pkg.f1() FROM DUAL;
      

      ERROR 1064 (42000): You have an error in your SQL syntax; ... 'CURSOR cur IS SELECT 1 AS c FROM DUAL..';
      

      If I run a similar script in Oracle, it works fine and returns "1" as expected:

      DROP PACKAGE pkg;
      CREATE PACKAGE pkg AS
        FUNCTION f1 RETURN INT;
      END;
      /
      CREATE PACKAGE BODY pkg AS
        vc INT := 0;
        CURSOR cur IS SELECT 1 AS c FROM DUAL;
        FUNCTION f1 RETURN INT AS
        BEGIN
          OPEN cur;
          FETCH cur INTO vc;
          CLOSE cur;
          RETURN vc;
        END;
      END;
      /
      SELECT pkg.f1() FROM DUAL;
      

      PKG.F1()
      1
      

      Attachments

        Issue Links

          Activity

            No workflow transitions have been executed yet.

            People

              bar Alexander Barkov
              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.