Details
-
Technical task
-
Status: Stalled (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.3(EOL), 10.4(EOL), 10.5
-
None
Description
As of version 10.4, MariaDB supports package variables in CREATE PACKAGE BODY only.
Under terms of this task we'll also allow package wide declarations in the CREATE PACKAGE statement:
- TYPE type_name IS REF CURSOR – weak and strong cursor types
- TYPE type_name IS RECORD (..) – record types
- TYPE .. TABLE OF .. INDEX BY – collection types
- Variables (all kinds of, including RECORD, TABLE OF, REF CURSOS, SYS_REFCURSOR)
- Exceptions
Example (a variable declaration):
DROP PACKAGE pkg1; |
DELIMITER $$
|
CREATE PACKAGE pkg1 |
AS
|
m_count INT:= 0; |
FUNCTION get_count RETURN INT; |
PROCEDURE set_count(new_count INT); |
END; |
$$
|
CREATE PACKAGE BODY pkg1 |
AS
|
FUNCTION get_count RETURN INT |
AS |
BEGIN |
m_count:= m_count + 1;
|
RETURN m_count; |
END; |
PROCEDURE set_count(new_count INT) |
AS |
BEGIN |
m_count:= new_count;
|
END; |
END; |
$$
|
DELIMITER ;
|
SELECT pkg1.get_count() FROM dual; -- this returns 1 |
SELECT pkg1.get_count() FROM dual; -- this returns 2 |
CALL pkg1.set_count(30);
|
SELECT pkg1.get_count() FROM dual; -- this returns 31 |
Note, unlike stored routines parameters, package-wide VARCHAR variables must be declared with length.
Package variables are initialized on the first package invocation in the current session.
Variable declarations may not refer to functions declared in the same package. So this script will return an error:
DROP PACKAGE pkg1; |
DELIMITER $$
|
CREATE PACKAGE pkg1 |
AS
|
m_count INT:= init_count(); |
FUNCTION init_count RETURN INT; |
END; |
$$
|
Attachments
Issue Links
- blocks
-
MDEV-34323 Oracle compatibility project 3
- Open
- is blocked by
-
MDEV-13292 Move the code from sp_head::init() to sp_head::sp_head()
- Closed
-
MDEV-34317 DECLARE TYPE type_name IS RECORD (..) with scalar members in stored routines
- In Testing
-
MDEV-34319 DECLARE TYPE .. TABLE OF .. INDEX BY in stored routines
- Open
- is duplicated by
-
MDEV-27248 Support for global package variables
- Closed