Type:
Technical task
Priority:
Major
Resolution:
Fixed
Affects Version/s:
None
Sprint:
10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18
When running in sql_mode=ORACLE , MariaDB should support %TYPE in variable declarations, in function and procedure parameter delcarations, and function RETURN clauses:
The above statement declares a variable that has the same data type with the column a in the table t1 .
Example:
DROP TABLE t1;
CREATE TABLE t1 (a INT );
INSERT INTO t1 VALUES (10);
INSERT INTO t1 VALUES (20);
DROP FUNCTION f1;
CREATE FUNCTION f1(prm t1.a%TYPE) RETURN t1.a%TYPE
AS
tmp t1.a%TYPE;
BEGIN
SELECT MAX (a) INTO tmp FROM t1;
RETURN tmp + prm;
END ;
/
SELECT f1(5) FROM DUAL;
Scope of this task
This task will implement %TYPE only for local variables and parameters. Using %TYPE in stored function RETURN clause will be done under terms of MDEV-11210 .
Oracle behavior
1. %TYPE and missing tables during routine CREATE time
Oracle checks if the referenced table exists during the routine CREATE time. If the referenced table does not exists, a warning is issued, but the routine is created.
DROP TABLE t1;
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
a t1.a%TYPE := 123;
BEGIN
EXECUTE IMMEDIATE 'INSERT INTO t1 (a) VALUES(:a)' USING a;
END ;
/
SHOW ERRORS;
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/4 PL/SQL: Item ignored
3/4 PLS-00201: identifier 'T1.A' must be declared
5/3 PL/SQL: Statement ignored
5/59 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
The routine created with a missing identifier warning can be used as soon as the referenced table is created:
CREATE TABLE t1 (a INT);
CALL p1();
SELECT * FROM t1;
Notice, the CALL statement inserted 123 into t1 .
2. Dropping the referenced table before the routine execution leads to an error on CALL
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR (10));
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
a t1.a%TYPE:= 'xxx' ;
BEGIN
NULL ;
END ;
/
CALL p1();
DROP TABLE t1;
CALL p1();
SELECT * FROM user_errors;
NAME TYPE SEQUENCE LINE POSITION
------------------------------ ------------ ---------- ---------- ----------
TEXT
--------------------------------------------------------------------------------
ATTRIBUTE MESSAGE_NUMBER
--------- --------------
P1 PROCEDURE 2 3 5
PL/SQL: Item ignored
ERROR 0
P1 PROCEDURE 1 3 5
PLS-00201: identifier 'T1.A' must be declared
ERROR 201
NAME TYPE SEQUENCE LINE POSITION
------------------------------ ------------ ---------- ---------- ----------
TEXT
--------------------------------------------------------------------------------
ATTRIBUTE MESSAGE_NUMBER
--------- --------------
3. Dropping the referenced table during the routine execution does not affect %TYPE variables
DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1 (a VARCHAR (10));
CREATE TABLE t2 (a VARCHAR (10));
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE t1' ;
DECLARE
a t1.a%TYPE:= 'xxx' ;
BEGIN
EXECUTE IMMEDIATE 'INSERT INTO t2 VALUES (:1)' USING a;
END ;
END ;
/
CALL p1();
SELECT * FROM t2;
Notice, the variable was declared after DROP TABLE .
MariaDB behavior
To make MariaDB reproduce Oracle's behavior as close as possible, we'll assing data type to %TYPE variables at sp_rcontext::create() time.
Like Oracle, we'll not require the referenced tables to exists at the routine CREATE time. Unlike Oracle, we won't check the referenced tables and won't generate warnings.
{"report":{"fcp":2253.5,"ttfb":718.8000001907349,"pageVisibility":"visible","entityId":57677,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"48625fb2-9c35-4a5b-a914-7b0a4c32be68","navigationType":0,"readyForUser":2369.4000005722046,"redirectCount":0,"resourceLoadedEnd":2602.1000003814697,"resourceLoadedStart":725,"resourceTiming":[{"duration":964.4000005722046,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":725,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":725,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1689.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":964.8000001907349,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":725.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":725.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1690.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":1028.0999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":725.4000005722046,"connectEnd":725.4000005722046,"connectStart":725.4000005722046,"domainLookupEnd":725.4000005722046,"domainLookupStart":725.4000005722046,"fetchStart":725.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":725.4000005722046,"responseEnd":1753.5,"responseStart":1753.5,"secureConnectionStart":725.4000005722046},{"duration":1147.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":725.6000003814697,"connectEnd":725.6000003814697,"connectStart":725.6000003814697,"domainLookupEnd":725.6000003814697,"domainLookupStart":725.6000003814697,"fetchStart":725.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":725.6000003814697,"responseEnd":1873.1000003814697,"responseStart":1873.1000003814697,"secureConnectionStart":725.6000003814697},{"duration":1166.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":725.8000001907349,"connectEnd":725.8000001907349,"connectStart":725.8000001907349,"domainLookupEnd":725.8000001907349,"domainLookupStart":725.8000001907349,"fetchStart":725.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":725.8000001907349,"responseEnd":1892.1000003814697,"responseStart":1892.1000003814697,"secureConnectionStart":725.8000001907349},{"duration":1167.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":726.1000003814697,"connectEnd":726.1000003814697,"connectStart":726.1000003814697,"domainLookupEnd":726.1000003814697,"domainLookupStart":726.1000003814697,"fetchStart":726.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":726.1000003814697,"responseEnd":1893.2000007629395,"responseStart":1893.2000007629395,"secureConnectionStart":726.1000003814697},{"duration":1167.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":726.2000007629395,"connectEnd":726.2000007629395,"connectStart":726.2000007629395,"domainLookupEnd":726.2000007629395,"domainLookupStart":726.2000007629395,"fetchStart":726.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":726.2000007629395,"responseEnd":1893.8000001907349,"responseStart":1893.8000001907349,"secureConnectionStart":726.2000007629395},{"duration":1193.3000001907349,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":726.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":726.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1919.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":1167.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":726.5,"connectEnd":726.5,"connectStart":726.5,"domainLookupEnd":726.5,"domainLookupStart":726.5,"fetchStart":726.5,"redirectEnd":0,"redirectStart":0,"requestStart":726.5,"responseEnd":1894.3000001907349,"responseStart":1894.3000001907349,"secureConnectionStart":726.5},{"duration":1193.1999998092651,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":726.7000007629395,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":726.7000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1919.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":1168,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":727,"connectEnd":727,"connectStart":727,"domainLookupEnd":727,"domainLookupStart":727,"fetchStart":727,"redirectEnd":0,"redirectStart":0,"requestStart":727,"responseEnd":1895,"responseStart":1895,"secureConnectionStart":727},{"duration":1743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":732.4000005722046,"connectEnd":732.4000005722046,"connectStart":732.4000005722046,"domainLookupEnd":732.4000005722046,"domainLookupStart":732.4000005722046,"fetchStart":732.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":732.4000005722046,"responseEnd":2475.4000005722046,"responseStart":2475.300000190735,"secureConnectionStart":732.4000005722046},{"duration":1869.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":732.4000005722046,"connectEnd":732.4000005722046,"connectStart":732.4000005722046,"domainLookupEnd":732.4000005722046,"domainLookupStart":732.4000005722046,"fetchStart":732.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":732.4000005722046,"responseEnd":2602.1000003814697,"responseStart":2602.1000003814697,"secureConnectionStart":732.4000005722046},{"duration":559.8999996185303,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1933.4000005722046,"connectEnd":1933.4000005722046,"connectStart":1933.4000005722046,"domainLookupEnd":1933.4000005722046,"domainLookupStart":1933.4000005722046,"fetchStart":1933.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":1933.4000005722046,"responseEnd":2493.300000190735,"responseStart":2493.300000190735,"secureConnectionStart":1933.4000005722046}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":525,"responseStart":718,"responseEnd":723,"domLoading":722,"domInteractive":2625,"domContentLoadedEventStart":2625,"domContentLoadedEventEnd":2678,"domComplete":4448,"loadEventStart":4448,"loadEventEnd":4450,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2603.9000005722046},{"name":"bigPipe.sidebar-id.end","time":2604.800000190735},{"name":"bigPipe.activity-panel-pipe-id.start","time":2605},{"name":"bigPipe.activity-panel-pipe-id.end","time":2607.6000003814697},{"name":"activityTabFullyLoaded","time":2687.9000005722046}],"measures":[],"correlationId":"74b89d803fb15b","effectiveType":"4g","downlink":9.9,"rtt":0,"serverDuration":112,"dbReadsTimeInMs":19,"dbConnsTimeInMs":28,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}