Sprint:
10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18
This task will implement Oracle-stype %ROWTYPE declaration for cursors, for sql_mode=ORACLE .
Example:
CURSOR cur IS SELECT a,b FROM t1;
rec cur%ROWTYPE;
The record rec can store the entire row of data fetched from the cursor cur . There is no a need to specify column names and data types. They're automatically copied from the result set of the cursor cur .
A complete working example:
SET sql_mode=ORACLE;
DROP TABLE t1;
CREATE TABLE t1 (a INT , b VARCHAR (32));
INSERT INTO t1 VALUES (10, 'b10' );
INSERT INTO t1 VALUES (20, 'b20' );
INSERT INTO t1 VALUES (30, 'b30' );
DROP PROCEDURE p1;
DELIMITER $$
CREATE PROCEDURE p1 AS
CURSOR c IS SELECT a,b FROM t1;
BEGIN
DECLARE
rec c%ROWTYPE;
BEGIN
OPEN c;
LOOP
FETCH c INTO rec;
EXIT WHEN c%NOTFOUND;
SELECT 'rec=(' || rec.a || ',' || rec.b|| ')' AS c FROM dual;
END LOOP;
CLOSE c;
END ;
END ;
$$
DELIMITER ;
CALL p1();
Note, in Oracle it's possible to use %ROWTYPE variables before opening the referenced cursor, or even without opening it. Also, record variables declared with %ROWTYPE can be initialized by the assignment operator instead of FETCH .
SET sql_mode=ORACLE;
DROP PROCEDURE p1;
DELIMITER $$
CREATE PROCEDURE p1 AS
CURSOR c IS SELECT 10 AS a,20 AS b FROM t1;
BEGIN
DECLARE
rec c%ROWTYPE;
BEGIN
rec.a:= 10;
rec.b:= 20;
SELECT 'rec=(' || rec.a || ',' || rec.b|| ')' AS c;
END ;
END ;
$$
DELIMITER ;
CALL p1();
%ROWTYPE can be used with open and closed cursors
Also, in MariaDB it's now not possible to declare a variable after cursors (see MDEV-10598 ). So this won't work:
DECLARE
CURSOR cur IS SELECT a,b FROM t1;
rec cur%ROWTYPE;
BEGIN
-- statements
END ;
One will have to use an additional nested block:
DECLARE
CURSOR cur IS SELECT a,b FROM t1;
DECLARE
rec cur%ROWTYPE;
BEGIN
-- statements
END ;
END ;
{"report":{"fcp":1196,"ttfb":261.39999997615814,"pageVisibility":"visible","entityId":60146,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ecd354e3-c54a-4c74-9000-f023e5bc7329","navigationType":0,"readyForUser":1315.2999999523163,"redirectCount":0,"resourceLoadedEnd":1298.7999999523163,"resourceLoadedStart":266.39999997615814,"resourceTiming":[{"duration":321.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":266.39999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":266.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":587.5,"responseStart":0,"secureConnectionStart":0},{"duration":321.2000000476837,"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":266.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":266.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":587.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":379.39999997615814,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":266.7999999523163,"connectEnd":266.7999999523163,"connectStart":266.7999999523163,"domainLookupEnd":266.7999999523163,"domainLookupStart":266.7999999523163,"fetchStart":266.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":266.7999999523163,"responseEnd":646.1999999284744,"responseStart":646.1999999284744,"secureConnectionStart":266.7999999523163},{"duration":453.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":267,"connectEnd":267,"connectStart":267,"domainLookupEnd":267,"domainLookupStart":267,"fetchStart":267,"redirectEnd":0,"redirectStart":0,"requestStart":267,"responseEnd":720.5,"responseStart":720.5,"secureConnectionStart":267},{"duration":458.5,"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":267.1999999284744,"connectEnd":267.1999999284744,"connectStart":267.1999999284744,"domainLookupEnd":267.1999999284744,"domainLookupStart":267.1999999284744,"fetchStart":267.1999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":267.1999999284744,"responseEnd":725.6999999284744,"responseStart":725.6999999284744,"secureConnectionStart":267.1999999284744},{"duration":458.89999997615814,"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":267.39999997615814,"connectEnd":267.39999997615814,"connectStart":267.39999997615814,"domainLookupEnd":267.39999997615814,"domainLookupStart":267.39999997615814,"fetchStart":267.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":267.39999997615814,"responseEnd":726.2999999523163,"responseStart":726.2999999523163,"secureConnectionStart":267.39999997615814},{"duration":459.8000000715256,"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":267.59999990463257,"connectEnd":267.59999990463257,"connectStart":267.59999990463257,"domainLookupEnd":267.59999990463257,"domainLookupStart":267.59999990463257,"fetchStart":267.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":267.59999990463257,"responseEnd":727.3999999761581,"responseStart":727.3999999761581,"secureConnectionStart":267.59999990463257},{"duration":540.3999999761581,"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":267.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":267.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":808.1999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":460,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":268,"connectEnd":268,"connectStart":268,"domainLookupEnd":268,"domainLookupStart":268,"fetchStart":268,"redirectEnd":0,"redirectStart":0,"requestStart":268,"responseEnd":728,"responseStart":727.8999999761581,"secureConnectionStart":268},{"duration":540.3000000715256,"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":268.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":268.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":808.3999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":460.60000002384186,"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":268.2999999523163,"connectEnd":268.2999999523163,"connectStart":268.2999999523163,"domainLookupEnd":268.2999999523163,"domainLookupStart":268.2999999523163,"fetchStart":268.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":268.2999999523163,"responseEnd":728.8999999761581,"responseStart":728.8999999761581,"secureConnectionStart":268.2999999523163},{"duration":929.7999999523163,"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":274.39999997615814,"connectEnd":274.39999997615814,"connectStart":274.39999997615814,"domainLookupEnd":274.39999997615814,"domainLookupStart":274.39999997615814,"fetchStart":274.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":274.39999997615814,"responseEnd":1204.1999999284744,"responseStart":1204.1999999284744,"secureConnectionStart":274.39999997615814},{"duration":1024.2999999523163,"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":274.5,"connectEnd":274.5,"connectStart":274.5,"domainLookupEnd":274.5,"domainLookupStart":274.5,"fetchStart":274.5,"redirectEnd":0,"redirectStart":0,"requestStart":274.5,"responseEnd":1298.7999999523163,"responseStart":1298.7999999523163,"secureConnectionStart":274.5},{"duration":380.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":825,"connectEnd":825,"connectStart":825,"domainLookupEnd":825,"domainLookupStart":825,"fetchStart":825,"redirectEnd":0,"redirectStart":0,"requestStart":825,"responseEnd":1205.0999999046326,"responseStart":1205.0999999046326,"secureConnectionStart":825},{"duration":263.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1189.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1189.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1452.5999999046326,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":83,"responseStart":261,"responseEnd":268,"domLoading":265,"domInteractive":1494,"domContentLoadedEventStart":1494,"domContentLoadedEventEnd":1546,"domComplete":3048,"loadEventStart":3048,"loadEventEnd":3050,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1462.7999999523163},{"name":"bigPipe.sidebar-id.end","time":1463.6999999284744},{"name":"bigPipe.activity-panel-pipe-id.start","time":1463.8999999761581},{"name":"bigPipe.activity-panel-pipe-id.end","time":1467.2999999523163},{"name":"activityTabFullyLoaded","time":1555.5999999046326}],"measures":[],"correlationId":"fc15e47fb94eeb","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":109,"dbReadsTimeInMs":17,"dbConnsTimeInMs":26,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}