PL/SQL parser - Phase 2 (MDEV-10764)

[MDEV-10576] sql_mode=ORACLE: Functions with no parameters can be called without parentheses Created: 2016-08-17  Updated: 2021-05-11

Status: Open
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: None
Fix Version/s: None

Type: Technical task Priority: Major
Reporter: Alexander Barkov Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: Compatibility

Issue Links:
Relates
relates to MDEV-10578 sql_mode=ORACLE: SP control functions... Closed
relates to MDEV-11022 sql_mode=ORACLE: SQLERRM(errcode) Open

 Description   

When running with sql_mode=ORACLE, MariaDB should allow calling stored functions that have no parameters without having to type parentheses after the function name.

DROP FUNCTION f1;
CREATE FUNCTION f1 RETURN INT
AS
BEGIN
  RETURN 10;
END;
/
SELECT f1 FROM DUAL;
SELECT f1() FROM DUAL;

Notice, the above two SELECT queries return the same result:

SQL> 
	F1
----------
	10
 
SQL> 
      F1()
----------
	10

Name resolution will follow Oracle rules. For example, table columns shadow stored functions:

DROP FUNCTION f1;
CREATE FUNCTION f1 RETURN VARCHAR
AS
BEGIN
  RETURN 10;
END;
/
DROP TABLE t1;
CREATE TABLE t1 (f1 INT);
INSERT INTO t1 VALUES (20);
SELECT f1 FROM t1;

SQL> 
	F1
----------
	20

Notice, it returned the value of the column t1.f1 rather than the function f1.

Under terms of this task we'll also allow calling SP control functions SQLCODE and SQLERRM with empty parentheses:

DROP FUNCTION f1;
CREATE FUNCTION f1 RETURN INT
AS
BEGIN
  EXECUTE IMMEDIATE 'xxx';
  RETURN 0;
EXCEPTION
  WHEN OTHERS THEN RETURN SQLCODE();
END;
/
SELECT f1 FROM DUAL;


Generated at Thu Feb 08 07:43:16 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.