Commit 0040b0f3 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-10411 Providing compatibility for basic PL/SQL constructs

Part 13: RETURN vs RETURNS in function definition:

  CREATE FUNCTION f1(a INT) RETURN INT ...

Part 12:  No parentheses if no arguments:

  CREATE FUNCTION f1 RETURN INT ...
parent bd76d445
SET sql_mode=ORACLE; SET sql_mode=ORACLE;
# Testing routines with no parameters # Testing routines with no parameters
CREATE FUNCTION f1 RETURN INT
AS
BEGIN
RETURN 10;
END;
/
SHOW CREATE FUNCTION f1;
Function f1
sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER
Create Function CREATE DEFINER="root"@"localhost" FUNCTION "f1"() RETURN int(11)
AS
BEGIN
RETURN 10;
END
character_set_client latin1
collation_connection latin1_swedish_ci
Database Collation latin1_swedish_ci
SELECT f1();
f1()
10
DROP FUNCTION f1;
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
BEGIN BEGIN
...@@ -24,7 +45,7 @@ SELECT @a; ...@@ -24,7 +45,7 @@ SELECT @a;
10 10
DROP PROCEDURE p1; DROP PROCEDURE p1;
# Testing ":=" to set the default value of a variable # Testing ":=" to set the default value of a variable
CREATE FUNCTION f1 () RETURNS NUMBER(10) AS CREATE FUNCTION f1 () RETURN NUMBER(10) AS
a NUMBER(10) := 10; a NUMBER(10) := 10;
BEGIN BEGIN
DECLARE DECLARE
...@@ -39,7 +60,7 @@ f1() ...@@ -39,7 +60,7 @@ f1()
13 13
DROP FUNCTION f1; DROP FUNCTION f1;
# Testing labels # Testing labels
CREATE FUNCTION f1 (a INT) RETURNS CLOB AS CREATE FUNCTION f1 (a INT) RETURN CLOB AS
BEGIN BEGIN
<<label1>> <<label1>>
BEGIN BEGIN
...@@ -58,7 +79,7 @@ SELECT f1(2); ...@@ -58,7 +79,7 @@ SELECT f1(2);
f1(2) f1(2)
IS NOT 1 IS NOT 1
DROP FUNCTION f1; DROP FUNCTION f1;
CREATE FUNCTION f1 (a INT) RETURNS INT IS CREATE FUNCTION f1 (a INT) RETURN INT IS
BEGIN BEGIN
<<label1>> <<label1>>
LOOP LOOP
...@@ -74,7 +95,7 @@ SELECT f1(4); ...@@ -74,7 +95,7 @@ SELECT f1(4);
f1(4) f1(4)
2 2
DROP FUNCTION f1; DROP FUNCTION f1;
CREATE FUNCTION f1 (a INT) RETURNS INT AS CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN BEGIN
<<label1>> <<label1>>
WHILE a>0 DO WHILE a>0 DO
...@@ -90,7 +111,7 @@ SELECT f1(4); ...@@ -90,7 +111,7 @@ SELECT f1(4);
f1(4) f1(4)
2 2
DROP FUNCTION f1; DROP FUNCTION f1;
CREATE FUNCTION f1 (a INT) RETURNS INT AS CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN BEGIN
<<label1>> <<label1>>
REPEAT REPEAT
...@@ -320,7 +341,7 @@ SELECT @p1; ...@@ -320,7 +341,7 @@ SELECT @p1;
@p1 @p1
p1new p1new
DROP PROCEDURE p1; DROP PROCEDURE p1;
CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURNS VARCHAR(20) CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20)
AS AS
p2 VARCHAR(10); p2 VARCHAR(10);
BEGIN BEGIN
...@@ -356,7 +377,7 @@ SELECT @p1; ...@@ -356,7 +377,7 @@ SELECT @p1;
@p1 @p1
p1new p1new
DROP PROCEDURE p1; DROP PROCEDURE p1;
CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURNS VARCHAR(20) CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20)
AS AS
BEGIN BEGIN
DECLARE DECLARE
......
SET sql_mode=ORACLE; SET sql_mode=ORACLE;
--echo # Testing routines with no parameters --echo # Testing routines with no parameters
DELIMITER /;
CREATE FUNCTION f1 RETURN INT
AS
BEGIN
RETURN 10;
END;
/
DELIMITER ;/
--vertical_results
SHOW CREATE FUNCTION f1;
--horizontal_results
SELECT f1();
DROP FUNCTION f1;
DELIMITER /; DELIMITER /;
CREATE PROCEDURE p1 CREATE PROCEDURE p1
AS AS
...@@ -19,7 +34,7 @@ DROP PROCEDURE p1; ...@@ -19,7 +34,7 @@ DROP PROCEDURE p1;
--echo # Testing ":=" to set the default value of a variable --echo # Testing ":=" to set the default value of a variable
DELIMITER /; DELIMITER /;
CREATE FUNCTION f1 () RETURNS NUMBER(10) AS CREATE FUNCTION f1 () RETURN NUMBER(10) AS
a NUMBER(10) := 10; a NUMBER(10) := 10;
BEGIN BEGIN
DECLARE DECLARE
...@@ -36,7 +51,7 @@ DROP FUNCTION f1; ...@@ -36,7 +51,7 @@ DROP FUNCTION f1;
--echo # Testing labels --echo # Testing labels
DELIMITER /; DELIMITER /;
CREATE FUNCTION f1 (a INT) RETURNS CLOB AS CREATE FUNCTION f1 (a INT) RETURN CLOB AS
BEGIN BEGIN
<<label1>> <<label1>>
BEGIN BEGIN
...@@ -55,7 +70,7 @@ DROP FUNCTION f1; ...@@ -55,7 +70,7 @@ DROP FUNCTION f1;
DELIMITER /; DELIMITER /;
CREATE FUNCTION f1 (a INT) RETURNS INT IS CREATE FUNCTION f1 (a INT) RETURN INT IS
BEGIN BEGIN
<<label1>> <<label1>>
LOOP LOOP
...@@ -73,7 +88,7 @@ DROP FUNCTION f1; ...@@ -73,7 +88,7 @@ DROP FUNCTION f1;
DELIMITER /; DELIMITER /;
CREATE FUNCTION f1 (a INT) RETURNS INT AS CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN BEGIN
<<label1>> <<label1>>
WHILE a>0 DO WHILE a>0 DO
...@@ -91,7 +106,7 @@ DROP FUNCTION f1; ...@@ -91,7 +106,7 @@ DROP FUNCTION f1;
DELIMITER /; DELIMITER /;
CREATE FUNCTION f1 (a INT) RETURNS INT AS CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN BEGIN
<<label1>> <<label1>>
REPEAT REPEAT
...@@ -345,7 +360,7 @@ SELECT @p1; ...@@ -345,7 +360,7 @@ SELECT @p1;
DROP PROCEDURE p1; DROP PROCEDURE p1;
DELIMITER /; DELIMITER /;
CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURNS VARCHAR(20) CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20)
AS AS
p2 VARCHAR(10); p2 VARCHAR(10);
BEGIN BEGIN
...@@ -384,7 +399,7 @@ SELECT @p1; ...@@ -384,7 +399,7 @@ SELECT @p1;
DROP PROCEDURE p1; DROP PROCEDURE p1;
DELIMITER /; DELIMITER /;
CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURNS VARCHAR(20) CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20)
AS AS
BEGIN BEGIN
DECLARE DECLARE
......
...@@ -2230,7 +2230,10 @@ show_create_sp(THD *thd, String *buf, ...@@ -2230,7 +2230,10 @@ show_create_sp(THD *thd, String *buf,
buf->append(')'); buf->append(')');
if (type == TYPE_ENUM_FUNCTION) if (type == TYPE_ENUM_FUNCTION)
{ {
buf->append(STRING_WITH_LEN(" RETURNS ")); if (sql_mode & MODE_ORACLE)
buf->append(STRING_WITH_LEN(" RETURN "));
else
buf->append(STRING_WITH_LEN(" RETURNS "));
buf->append(returns, returnslen); buf->append(returns, returnslen);
} }
buf->append('\n'); buf->append('\n');
......
...@@ -2363,6 +2363,11 @@ sp_no_param: ...@@ -2363,6 +2363,11 @@ sp_no_param:
} }
; ;
opt_sp_parenthesized_fdparam_list:
sp_no_param
| sp_parenthesized_fdparam_list
;
opt_sp_parenthesized_pdparam_list: opt_sp_parenthesized_pdparam_list:
sp_no_param sp_no_param
| sp_parenthesized_pdparam_list | sp_parenthesized_pdparam_list
...@@ -16034,8 +16039,8 @@ sf_tail: ...@@ -16034,8 +16039,8 @@ sf_tail:
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->spname= $3; Lex->spname= $3;
} }
sp_parenthesized_fdparam_list /* $5 */ opt_sp_parenthesized_fdparam_list /* $5 */
RETURNS_SYM /* $6 */ RETURN_SYM /* $6 */
{ /* $7 */ { /* $7 */
LEX *lex= Lex; LEX *lex= Lex;
lex->init_last_field(&lex->sphead->m_return_field_def, NULL, lex->init_last_field(&lex->sphead->m_return_field_def, NULL,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment