summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/compat/oracle/r/sp-code.result
blob: 0fc980a3b8432a736ed9a393dc107941a439f355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
SET sql_mode=ORACLE;
#
# Testing exceptions in the top-level blocks
#
# No HANDLER declarations, no exceptions
CREATE FUNCTION f1 RETURN INT
AS
BEGIN
RETURN 10;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	freturn int 10
SELECT f1();
f1()
10
DROP FUNCTION f1;
# No HANDLER declarations, no code, no exceptions
CREATE PROCEDURE p1 ()
IS
BEGIN
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	jump 2
CALL p1;
DROP PROCEDURE p1;
# No HANDLER declarations, no code, some exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
EXCEPTION
WHEN 1002 THEN v:=225;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	jump 1
1	hpush_jump 4 1 EXIT
2	set v@0 225
3	hreturn 0 4
4	hpop 1
set @v= 10;
CALL p1(@v);
SELECT @v;
@v
10
DROP PROCEDURE p1;
# No HANDLER declarations, some code, some exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=224;
EXCEPTION
WHEN 1002 THEN v:=225;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	jump 3
1	set v@0 224
2	jump 6
3	hpush_jump 1 1 EXIT
4	set v@0 225
5	hreturn 0 6
6	hpop 1
set @v= 10;
CALL p1(@v);
SELECT @v;
@v
224
DROP PROCEDURE p1;
# Some HANDLER declarations, no code, no exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
EXIT HANDLER FOR 1000
BEGIN
v:=123;
END;
BEGIN
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	hpush_jump 3 1 EXIT
1	set v@0 123
2	hreturn 0 3
3	hpop 1
set @v= 10;
CALL p1(@v);
SELECT @v;
@v
10
DROP PROCEDURE p1;
# Some HANDLER declarations, no code, some exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
EXIT HANDLER FOR 1000
BEGIN
v:=123;
END;
BEGIN
EXCEPTION
WHEN 1002 THEN v:=225;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	hpush_jump 3 1 EXIT
1	set v@0 123
2	hreturn 0 6
3	hpush_jump 6 1 EXIT
4	set v@0 225
5	hreturn 0 6
6	hpop 2
set @v= 10;
CALL p1(@v);
SELECT @v;
@v
10
DROP PROCEDURE p1;
# Some HANDLER declarations, some code, no exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
EXIT HANDLER FOR 1000
BEGIN
v:=123;
END;
BEGIN
v:=223;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	hpush_jump 3 1 EXIT
1	set v@0 123
2	hreturn 0 4
3	set v@0 223
4	hpop 1
set @v= 10;
CALL p1(@v);
SELECT @v;
@v
223
DROP PROCEDURE p1;
# Some HANDLER declarations, some code, some exceptions
CREATE PROCEDURE p1 (v IN OUT VARCHAR2(20))
IS
EXIT HANDLER FOR 1000
BEGIN
v:=123;
END;
CONTINUE HANDLER FOR 1001
BEGIN
SET v=223;
END;
BEGIN
v:= 1;
EXCEPTION
WHEN 1002 THEN SET v=225;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	hpush_jump 3 1 EXIT
1	set v@0 123
2	hreturn 0 12
3	hpush_jump 8 1 CONTINUE
4	set v@0 223
5	hreturn 1
6	set v@0 1
7	jump 12
8	hpush_jump 6 1 EXIT
9	set v@0 225
10	hreturn 0 12
11	jump 6
12	hpop 3
DROP PROCEDURE p1;
#
# Testing EXCEPTIONS in internal blocks
#
# No HANDLER declarations, no code, no exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
BEGIN
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	jump 5
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
123
DROP PROCEDURE p1;
# No HANDLER declarations, no code, some exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
BEGIN
EXCEPTION
WHEN 20002 THEN v:=335;
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	jump 2
2	hpush_jump 5 1 EXIT
3	set v@0 335
4	hreturn 0 5
5	hpop 1
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
123
DROP PROCEDURE p1;
# No HANDLER declarations, some code, no exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
BEGIN
v:=223;
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	set v@0 223
2	jump 6
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
223
DROP PROCEDURE p1;
# No HANDLER declarations, some code, some exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
BEGIN
v:=223;
EXCEPTION
WHEN 20002 THEN v:=335;
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	jump 4
2	set v@0 223
3	jump 7
4	hpush_jump 2 1 EXIT
5	set v@0 335
6	hreturn 0 7
7	hpop 1
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
223
DROP PROCEDURE p1;
# Some HANDLER declarations, no code, no exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
DECLARE
EXIT HANDLER FOR 1000
BEGIN
v:=323;
END;
BEGIN
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	hpush_jump 4 1 EXIT
2	set v@0 323
3	hreturn 0 4
4	hpop 1
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
123
DROP PROCEDURE p1;
# Some HANDLER declarations, no code, some exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
DECLARE
EXIT HANDLER FOR 1000
BEGIN
v:=323;
END;
BEGIN
EXCEPTION
WHEN 20002 THEN v:=335;
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	hpush_jump 4 1 EXIT
2	set v@0 323
3	hreturn 0 7
4	hpush_jump 7 1 EXIT
5	set v@0 335
6	hreturn 0 7
7	hpop 2
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
123
DROP PROCEDURE p1;
# Some HANDLER declarations, some code, no exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
DECLARE
EXIT HANDLER FOR 1000
BEGIN
v:=323;
END;
BEGIN
v:= 324;
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	hpush_jump 4 1 EXIT
2	set v@0 323
3	hreturn 0 5
4	set v@0 324
5	hpop 1
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
324
DROP PROCEDURE p1;
# Some HANDLER declarations, some code, some exceptions
CREATE PROCEDURE p1 (v IN OUT INT)
IS
BEGIN
v:=123;
DECLARE
EXIT HANDLER FOR 1000
BEGIN
v:=323;
END;
BEGIN
v:= 324;
EXCEPTION WHEN 2002 THEN v:= 325;
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v@0 123
1	hpush_jump 6 1 EXIT
2	set v@0 323
3	hreturn 0 9
4	set v@0 324
5	jump 9
6	hpush_jump 4 1 EXIT
7	set v@0 325
8	hreturn 0 9
9	hpop 2
SET @v=10;
CALL p1(@v);
SELECT @v;
@v
324
DROP PROCEDURE p1;
#
# Testing EXIT statement
#
CREATE FUNCTION f1 RETURN INT
IS
i INT := 0;
BEGIN
LOOP
i:= i + 1;
IF i >= 5 THEN
EXIT;
END IF;
END LOOP;
RETURN i;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set i@0 0
1	set i@0 i@0 + 1
2	jump_if_not 1(1) i@0 >= 5
3	jump 4
4	freturn int i@0
SELECT f1() FROM DUAL;
f1()
5
DROP FUNCTION f1;
CREATE FUNCTION f1 RETURN INT
IS
i INT := 0;
BEGIN
LOOP
i:= i + 1;
EXIT WHEN i >=5;
END LOOP;
RETURN i;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set i@0 0
1	set i@0 i@0 + 1
2	jump_if_not 1(0) i@0 >= 5
3	jump 4
4	freturn int i@0
SELECT f1() FROM DUAL;
f1()
5
DROP FUNCTION f1;
CREATE FUNCTION f1 RETURN INT
IS
i INT := 0;
BEGIN
LOOP
BEGIN
i:= i + 1;
IF i >= 5 THEN
EXIT;
END IF;
EXCEPTION
WHEN OTHERS THEN i:= 1000;
END;
END LOOP;
RETURN i;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set i@0 0
1	jump 5
2	set i@0 i@0 + 1
3	jump_if_not 8(8) i@0 >= 5
4	jump 10
5	hpush_jump 2 1 EXIT
6	set i@0 1000
7	hreturn 0 8
8	hpop 1
9	jump 5
10	freturn int i@0
SELECT f1() FROM DUAL;
f1()
5
DROP FUNCTION f1;
CREATE PROCEDURE p1(a IN OUT INT)
IS
i INT := 0;
BEGIN
LOOP
LOOP
BEGIN
i:= i + 1;
IF i >=5 THEN
EXIT;
END IF;
EXCEPTION
WHEN OTHERS THEN a:=1000;
END;
END LOOP;
i:= i + 100;
EXIT;
END LOOP;
a:= i;
EXCEPTION
WHEN OTHERS THEN a:=11;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set i@1 0
1	jump 14
2	set i@1 i@1 + 1
3	jump_if_not 8(8) i@1 >= 5
4	jump 10
5	hpush_jump 2 2 EXIT
6	set a@0 1000
7	hreturn 0 8
8	hpop 1
9	jump 5
10	set i@1 i@1 + 100
11	jump 12
12	set a@0 i@1
13	jump 17
14	hpush_jump 5 2 EXIT
15	set a@0 11
16	hreturn 0 17
17	hpop 1
set @v= 10;
CALL p1(@v);
SELECT @v;
@v
105
DROP PROCEDURE p1;
# Testing RETURN in procedures
CREATE PROCEDURE p1 (a IN OUT INT)
AS
BEGIN
IF a < 10 THEN
BEGIN
a:= a + 1;
RETURN;
END;
END IF;
a:= 200;
EXCEPTION
WHEN OTHERS THEN
BEGIN
a:= 100;
RETURN;
END;
END;
/
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	jump 6
1	jump_if_not 4(4) a@0 < 10
2	set a@0 a@0 + 1
3	preturn
4	set a@0 200
5	jump 9
6	hpush_jump 1 1 EXIT
7	set a@0 100
8	preturn
9	hpop 1
DROP PROCEDURE p1;
# Testing FOR loop statement
CREATE FUNCTION f1 (a INT, b INT) RETURN INT
AS
total INT := 0;
BEGIN
FOR i IN 1 .. a
LOOP
total:= total + i;
IF i = b THEN
EXIT;
END IF;
END LOOP;
RETURN total;
END
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set total@2 0
1	set i@3 1
2	set [target_bound]@4 a@0
3	jump_if_not 9(9) i@3 <= [target_bound]@4
4	set total@2 total@2 + i@3
5	jump_if_not 7(7) i@3 = b@1
6	jump 9
7	set i@3 i@3 + 1
8	jump 3
9	freturn int total@2
SELECT f1(3, 100) FROM DUAL;
f1(3, 100)
6
SELECT f1(3, 2) FROM DUAL;
f1(3, 2)
3
DROP FUNCTION f1;
CREATE FUNCTION f1 (a INT, b INT) RETURN INT
AS
total INT := 0;
BEGIN
FOR i IN REVERSE 1..a
LOOP
total:= total + i;
IF i = b THEN
EXIT;
END IF;
END LOOP;
RETURN total;
END
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set total@2 0
1	set i@3 a@0
2	set [target_bound]@4 1
3	jump_if_not 9(9) i@3 >= [target_bound]@4
4	set total@2 total@2 + i@3
5	jump_if_not 7(7) i@3 = b@1
6	jump 9
7	set i@3 i@3 + -1
8	jump 3
9	freturn int total@2
SELECT f1(3, 100) FROM DUAL;
f1(3, 100)
6
SELECT f1(3, 2) FROM DUAL;
f1(3, 2)
5
DROP FUNCTION f1;
# Testing labeled FOR LOOP statement
CREATE FUNCTION f1 (a INT, limita INT, b INT, limitb INT) RETURN INT
AS
total INT := 0;
BEGIN
<<la>>
FOR ia IN 1 .. a
LOOP
total:= total + 1000;
<<lb>>
FOR ib IN 1 .. b
LOOP
total:= total + 1;
EXIT lb WHEN ib = limitb;
EXIT la WHEN ia = limita;
END LOOP lb;
END LOOP la;
RETURN total;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set total@4 0
1	set ia@5 1
2	set [target_bound]@6 a@0
3	jump_if_not 17(17) ia@5 <= [target_bound]@6
4	set total@4 total@4 + 1000
5	set ib@7 1
6	set [target_bound]@8 b@2
7	jump_if_not 15(15) ib@7 <= [target_bound]@8
8	set total@4 total@4 + 1
9	jump_if_not 11(0) ib@7 = limitb@3
10	jump 15
11	jump_if_not 13(0) ia@5 = limita@1
12	jump 17
13	set ib@7 ib@7 + 1
14	jump 7
15	set ia@5 ia@5 + 1
16	jump 3
17	freturn int total@4
SELECT f1(2, 1, 2, 2) FROM DUAL;
f1(2, 1, 2, 2)
1001
SELECT f1(2, 2, 2, 2) FROM DUAL;
f1(2, 2, 2, 2)
2003
SELECT f1(2, 3, 2, 3) FROM DUAL;
f1(2, 3, 2, 3)
2004
DROP FUNCTION f1;
# Testing labeled ITERATE in a labeled FOR LOOP
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
<<li>>
FOR i IN 1 .. a
LOOP
total:= total + 1000;
IF i = 5 THEN
ITERATE li;
END IF;
total:= total + 1;
END LOOP;
RETURN total;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set total@1 0
1	set i@2 1
2	set [target_bound]@3 a@0
3	jump_if_not 11(11) i@2 <= [target_bound]@3
4	set total@1 total@1 + 1000
5	jump_if_not 8(8) i@2 = 5
6	set i@2 i@2 + 1
7	jump 3
8	set total@1 total@1 + 1
9	set i@2 i@2 + 1
10	jump 3
11	freturn int total@1
SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3)	f1(4)	f1(5)	f1(6)
3003	4004	5004	6005
DROP FUNCTION f1;
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
<<li>>
FOR i IN 1 .. a
LOOP
FOR j IN 1 .. 2
LOOP
total:= total + 1000;
IF i = 5 THEN
ITERATE li;
END IF;
total:= total + 1;
END LOOP;
END LOOP;
RETURN total;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set total@1 0
1	set i@2 1
2	set [target_bound]@3 a@0
3	jump_if_not 16(16) i@2 <= [target_bound]@3
4	set j@4 1
5	set [target_bound]@5 2
6	jump_if_not 14(14) j@4 <= [target_bound]@5
7	set total@1 total@1 + 1000
8	jump_if_not 11(11) i@2 = 5
9	set i@2 i@2 + 1
10	jump 3
11	set total@1 total@1 + 1
12	set j@4 j@4 + 1
13	jump 6
14	set i@2 i@2 + 1
15	jump 3
16	freturn int total@1
SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3)	f1(4)	f1(5)	f1(6)
6006	8008	9008	11010
DROP FUNCTION f1;
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
<<lj>>
FOR j IN 1 .. 2
LOOP
<<li>>
FOR i IN 1 .. a
LOOP
total:= total + 1000;
IF i = 5 THEN
ITERATE li;
END IF;
total:= total + 1;
END LOOP;
END LOOP;
RETURN total;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set total@1 0
1	set j@2 1
2	set [target_bound]@3 2
3	jump_if_not 16(16) j@2 <= [target_bound]@3
4	set i@4 1
5	set [target_bound]@5 a@0
6	jump_if_not 14(14) i@4 <= [target_bound]@5
7	set total@1 total@1 + 1000
8	jump_if_not 11(11) i@4 = 5
9	set i@4 i@4 + 1
10	jump 6
11	set total@1 total@1 + 1
12	set i@4 i@4 + 1
13	jump 6
14	set j@2 j@2 + 1
15	jump 3
16	freturn int total@1
SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3)	f1(4)	f1(5)	f1(6)
6006	8008	10008	12010
DROP FUNCTION f1;
# Testing CONTINUE statement
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
FOR i IN 1 .. a
LOOP
CONTINUE WHEN i=5;
total:= total + 1;
END LOOP;
RETURN total;
END;
/
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set total@1 0
1	set i@2 1
2	set [target_bound]@3 a@0
3	jump_if_not 10(10) i@2 <= [target_bound]@3
4	jump_if_not 7(0) i@2 = 5
5	set i@2 i@2 + 1
6	jump 3
7	set total@1 total@1 + 1
8	set i@2 i@2 + 1
9	jump 3
10	freturn int total@1
SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3)	f1(4)	f1(5)	f1(6)
3	4	4	5
DROP FUNCTION f1;
#
# Start of MDEV-10597 Cursors with parameters
#
CREATE PROCEDURE p1(arg_value_a VARCHAR, arg_value_b VARCHAR,
arg_pattern_a VARCHAR, arg_pattern_b VARCHAR)
AS
v_a VARCHAR(10);
v_b VARCHAR(20);
CURSOR c (p_value_a VARCHAR,
p_value_b VARCHAR,
p_pattern_a VARCHAR,
p_pattern_b VARCHAR,
p_limit_a INT,
p_limit_b INT,
p_unused TEXT) IS
(SELECT p_value_a, p_value_b FROM DUAL
WHERE p_value_a LIKE p_pattern_a LIMIT p_limit_a)
UNION
(SELECT p_value_b, p_value_a FROM DUAL
WHERE p_value_b LIKE p_pattern_b LIMIT p_limit_b);
BEGIN
OPEN c(arg_value_a, (SELECT arg_value_b),
arg_pattern_a, arg_pattern_b, 100, 101, 'x');
LOOP
FETCH c INTO v_a, v_b;
EXIT WHEN c%NOTFOUND;
SELECT v_a, v_b;
END LOOP;
CLOSE c;
END;
$$
CALL p1('aaa','bbb','aaa','bbb');
v_a	v_b
aaa	bbb
v_a	v_b
bbb	aaa
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set v_a@4 NULL
1	set v_b@5 NULL
2	cpush c@0
3	set p_value_a@6 arg_value_a@0
4	set p_value_b@7 (select arg_value_b@1)
5	set p_pattern_a@8 arg_pattern_a@2
6	set p_pattern_b@9 arg_pattern_b@3
7	set p_limit_a@10 100
8	set p_limit_b@11 101
9	set p_unused@12 'x'
10	copen c@0
11	cfetch c@0 v_a@4 v_b@5
12	jump_if_not 14(0) "c"%NOTFOUND
13	jump 16
14	stmt 0 "SELECT v_a, v_b"
15	jump 11
16	cclose c@0
17	cpop 1
DROP PROCEDURE p1;
#
# End of MDEV-10597 Cursors with parameters
#
#
# MDEV-10914 ROW data type for stored routine variables
#
CREATE FUNCTION f1() RETURN INT
AS
a ROW(a INT, b INT);
BEGIN
a.b:= 200;
RETURN a.b;
END;
$$
SHOW FUNCTION CODE f1;
Pos	Instruction
0	set a@0 NULL
1	set a.b@0[1] 200
2	freturn int a.b@0[1]
SELECT f1();
f1()
200
DROP FUNCTION f1;
CREATE PROCEDURE p1
AS
rec ROW(a INT,b DOUBLE,c DECIMAL(10,3),d VARCHAR(10));
BEGIN
rec:= ROW(10,20.123456,30.123,'test');
SELECT rec.a, rec.b, rec.c, rec.d;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set rec@0 NULL
1	set rec@0 (10,20.123456,30.123,'test')
2	stmt 0 "SELECT rec.a, rec.b, rec.c, rec.d"
CALL p1;
rec.a	rec.b	rec.c	rec.d
10	20.123456	30.123	test
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
rec ROW(a INT,b DOUBLE,c DECIMAL(10,3),d VARCHAR(10)) :=
ROW(10,20.123456,30.123,'test');
BEGIN
SELECT rec.a, rec.b, rec.c, rec.d;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set rec@0 (10,20.123456,30.123,'test')
1	stmt 0 "SELECT rec.a, rec.b, rec.c, rec.d"
CALL p1;
rec.a	rec.b	rec.c	rec.d
10	20.123456	30.123	test
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
rec1 ROW(a INT,b DOUBLE,c DECIMAL(10,3),d VARCHAR(10));
rec2 ROW(a INT,b DOUBLE,c DECIMAL(10,3),d VARCHAR(10));
BEGIN
rec1:= ROW(10,20.123456,30.123,'test');
rec2:= rec1;
SELECT rec2.a, rec2.b, rec2.c, rec2.d;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set rec1@0 NULL
1	set rec2@1 NULL
2	set rec1@0 (10,20.123456,30.123,'test')
3	set rec2@1 rec1@0
4	stmt 0 "SELECT rec2.a, rec2.b, rec2.c, rec2.d"
CALL p1;
rec2.a	rec2.b	rec2.c	rec2.d
10	20.123456	30.123	test
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
rec1 ROW(a INT,b DOUBLE,c DECIMAL(10,3),d VARCHAR(10)) :=
ROW(10,20.123456,30.123,'test');
rec2 ROW(a INT,b DOUBLE,c DECIMAL(10,3),d VARCHAR(10)) := rec1;
BEGIN
SELECT rec2.a, rec2.b, rec2.c, rec2.d;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set rec1@0 (10,20.123456,30.123,'test')
1	set rec2@1 rec1@0
2	stmt 0 "SELECT rec2.a, rec2.b, rec2.c, rec2.d"
CALL p1;
rec2.a	rec2.b	rec2.c	rec2.d
10	20.123456	30.123	test
DROP PROCEDURE p1;
#
# End of MDEV-10914 ROW data type for stored routine variables
#
#
# MDEV-12133 sql_mode=ORACLE: table%ROWTYPE in variable declarations
#
CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,2));
CREATE PROCEDURE p1()
AS
rec1 t1%ROWTYPE;
BEGIN
rec1.a:= 10;
rec1.b:= 'bbb';
rec1.c:= 10e2;
rec1.d:= 10.12;
rec1.c:= rec1.d;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set rec1@0 NULL
1	set rec1.a@0["a"] 10
2	set rec1.b@0["b"] 'bbb'
3	set rec1.c@0["c"] 10e2
4	set rec1.d@0["d"] 10.12
5	set rec1.c@0["c"] rec1.d@0["d"]
DROP PROCEDURE p1;
DROP TABLE t1;
#
# MDEV-12011 sql_mode=ORACLE: cursor%ROWTYPE in variable declarations
#
CREATE TABLE t1 (a INT, b VARCHAR(10));
CREATE PROCEDURE p1()
AS
CURSOR cur1 IS SELECT * FROM t1;
CURSOR cur2 IS SELECT * FROM t1;
BEGIN
DECLARE
rec1,rec2 cur1%ROWTYPE;
rec3 cur2%ROWTYPE;
BEGIN
rec1.a:= 10;
rec1.b:= 'bbb';
END;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	cpush cur1@0
1	cpush cur2@1
2	cursor_copy_struct cur1 rec1@0
3	cursor_copy_struct cur1 rec2@1
4	set rec1@0 NULL
5	set rec2@1 NULL
6	cursor_copy_struct cur2 rec3@2
7	set rec3@2 NULL
8	set rec1.a@0["a"] 10
9	set rec1.b@0["b"] 'bbb'
10	jump 11
11	cpop 2
DROP PROCEDURE p1;
DROP TABLE t1;
#
# MDEV-10581 sql_mode=ORACLE: Explicit cursor FOR LOOP
#
CREATE PROCEDURE p1
AS
CURSOR cur0 IS SELECT 10 AS a, 'b0' AS b;
CURSOR cur1 IS SELECT 10 AS a, 'b0' AS b;
CURSOR cur2 IS SELECT 10 AS a, 'b0' AS b;
BEGIN
FOR rec1 IN cur1
LOOP
SELECT rec1.a, rec1.b;
rec1.a:= 11;
rec1.b:= 'b1';
SELECT rec1.a, rec1.b;
END LOOP;
FOR rec0 IN cur0
LOOP
rec0.a:= 10;
rec0.b:='b0';
END LOOP;
FOR rec2 IN cur2
LOOP
rec2.a:= 10;
rec2.b:='b0';
END LOOP;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	cpush cur0@0
1	cpush cur1@1
2	cpush cur2@2
3	cursor_copy_struct cur1 rec1@0
4	copen cur1@1
5	cfetch cur1@1 rec1@0
6	jump_if_not 13(13) "cur1"%FOUND
7	stmt 0 "SELECT rec1.a, rec1.b"
8	set rec1.a@0["a"] 11
9	set rec1.b@0["b"] 'b1'
10	stmt 0 "SELECT rec1.a, rec1.b"
11	cfetch cur1@1 rec1@0
12	jump 6
13	cclose cur1@1
14	cursor_copy_struct cur0 rec0@1
15	copen cur0@0
16	cfetch cur0@0 rec0@1
17	jump_if_not 22(22) "cur0"%FOUND
18	set rec0.a@1["a"] 10
19	set rec0.b@1["b"] 'b0'
20	cfetch cur0@0 rec0@1
21	jump 17
22	cclose cur0@0
23	cursor_copy_struct cur2 rec2@2
24	copen cur2@2
25	cfetch cur2@2 rec2@2
26	jump_if_not 31(31) "cur2"%FOUND
27	set rec2.a@2["a"] 10
28	set rec2.b@2["b"] 'b0'
29	cfetch cur2@2 rec2@2
30	jump 26
31	cclose cur2@2
32	cpop 3
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
CURSOR cur0 IS SELECT 10 AS a, 'b0' AS b;
BEGIN
FOR rec0 IN cur0
LOOP
DECLARE
CURSOR cur1 IS SELECT 11 AS a, 'b1' AS b;
BEGIN
rec0.a:= 11;
rec0.b:= 'b0';
FOR rec1 IN cur1
LOOP
rec1.a:= 11;
rec1.b:= 'b1';
DECLARE
CURSOR cur2 IS SELECT 12 AS a, 'b2' AS b;
BEGIN
FOR rec2 IN cur2
LOOP
rec2.a:=12;
rec2.b:='b2';
END LOOP;
END;
END LOOP;
END;
END LOOP;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	cpush cur0@0
1	cursor_copy_struct cur0 rec0@0
2	copen cur0@0
3	cfetch cur0@0 rec0@0
4	jump_if_not 31(31) "cur0"%FOUND
5	cpush cur1@1
6	set rec0.a@0["a"] 11
7	set rec0.b@0["b"] 'b0'
8	cursor_copy_struct cur1 rec1@1
9	copen cur1@1
10	cfetch cur1@1 rec1@1
11	jump_if_not 27(27) "cur1"%FOUND
12	set rec1.a@1["a"] 11
13	set rec1.b@1["b"] 'b1'
14	cpush cur2@2
15	cursor_copy_struct cur2 rec2@2
16	copen cur2@2
17	cfetch cur2@2 rec2@2
18	jump_if_not 23(23) "cur2"%FOUND
19	set rec2.a@2["a"] 12
20	set rec2.b@2["b"] 'b2'
21	cfetch cur2@2 rec2@2
22	jump 18
23	cclose cur2@2
24	cpop 1
25	cfetch cur1@1 rec1@1
26	jump 11
27	cclose cur1@1
28	cpop 1
29	cfetch cur0@0 rec0@0
30	jump 4
31	cclose cur0@0
32	cpop 1
DROP PROCEDURE p1;
#
# MDEV-12098 sql_mode=ORACLE: Implicit cursor FOR loop
#
CREATE PROCEDURE p1
AS
BEGIN
FOR rec1 IN (SELECT 11 AS a, 'b1' AS b)
LOOP
SELECT rec1.a, rec1.b;
rec1.a:= 11;
rec1.b:= 'b1';
SELECT rec1.a, rec1.b;
END LOOP;
FOR rec0 IN (SELECT 10 AS a, 'b0' AS b)
LOOP
rec0.a:= 10;
rec0.b:='b0';
END LOOP;
FOR rec2 IN (SELECT 12 AS a, 'b2' AS b)
LOOP
rec2.a:= 10;
rec2.b:='b0';
END LOOP;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	cpush [implicit_cursor]@0
1	cursor_copy_struct [implicit_cursor] rec1@0
2	copen [implicit_cursor]@0
3	cfetch [implicit_cursor]@0 rec1@0
4	jump_if_not 11(11) "[implicit_cursor]"%FOUND
5	stmt 0 "SELECT rec1.a, rec1.b"
6	set rec1.a@0["a"] 11
7	set rec1.b@0["b"] 'b1'
8	stmt 0 "SELECT rec1.a, rec1.b"
9	cfetch [implicit_cursor]@0 rec1@0
10	jump 4
11	cpop 1
12	cpush [implicit_cursor]@0
13	cursor_copy_struct [implicit_cursor] rec0@1
14	copen [implicit_cursor]@0
15	cfetch [implicit_cursor]@0 rec0@1
16	jump_if_not 21(21) "[implicit_cursor]"%FOUND
17	set rec0.a@1["a"] 10
18	set rec0.b@1["b"] 'b0'
19	cfetch [implicit_cursor]@0 rec0@1
20	jump 16
21	cpop 1
22	cpush [implicit_cursor]@0
23	cursor_copy_struct [implicit_cursor] rec2@2
24	copen [implicit_cursor]@0
25	cfetch [implicit_cursor]@0 rec2@2
26	jump_if_not 31(31) "[implicit_cursor]"%FOUND
27	set rec2.a@2["a"] 10
28	set rec2.b@2["b"] 'b0'
29	cfetch [implicit_cursor]@0 rec2@2
30	jump 26
31	cpop 1
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
BEGIN
FOR rec0 IN (SELECT 10 AS a, 'b0' AS b)
LOOP
rec0.a:= 11;
rec0.b:= 'b0';
FOR rec1 IN (SELECT 11 AS a, 'b1' AS b)
LOOP
rec1.a:= 11;
rec1.b:= 'b1';
FOR rec2 IN (SELECT 12 AS a, 'b2' AS b)
LOOP
rec2.a:=12;
rec2.b:='b2';
END LOOP;
END LOOP;
END LOOP;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	cpush [implicit_cursor]@0
1	cursor_copy_struct [implicit_cursor] rec0@0
2	copen [implicit_cursor]@0
3	cfetch [implicit_cursor]@0 rec0@0
4	jump_if_not 29(29) "[implicit_cursor]"%FOUND
5	set rec0.a@0["a"] 11
6	set rec0.b@0["b"] 'b0'
7	cpush [implicit_cursor]@1
8	cursor_copy_struct [implicit_cursor] rec1@1
9	copen [implicit_cursor]@1
10	cfetch [implicit_cursor]@1 rec1@1
11	jump_if_not 26(26) "[implicit_cursor]"%FOUND
12	set rec1.a@1["a"] 11
13	set rec1.b@1["b"] 'b1'
14	cpush [implicit_cursor]@2
15	cursor_copy_struct [implicit_cursor] rec2@2
16	copen [implicit_cursor]@2
17	cfetch [implicit_cursor]@2 rec2@2
18	jump_if_not 23(23) "[implicit_cursor]"%FOUND
19	set rec2.a@2["a"] 12
20	set rec2.b@2["b"] 'b2'
21	cfetch [implicit_cursor]@2 rec2@2
22	jump 18
23	cpop 1
24	cfetch [implicit_cursor]@1 rec1@1
25	jump 11
26	cpop 1
27	cfetch [implicit_cursor]@0 rec0@0
28	jump 4
29	cpop 1
DROP PROCEDURE p1;
#
# MDEV-10598 sql_mode=ORACLE: Variable declarations can go after cursor declarations
#
#
# Cursor declaration and cursor%ROWTYPE declaration in the same block
#
CREATE TABLE t1 (a INT, b VARCHAR(10));
INSERT INTO t1 VALUES (1,'a');
CREATE PROCEDURE p1()
AS
CURSOR cur1 IS SELECT a FROM t1;
rec1 cur1%ROWTYPE;
BEGIN
rec1.a:= 10;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	cursor_copy_struct cur1 rec1@0
1	set rec1@0 NULL
2	cpush cur1@0
3	set rec1.a@0["a"] 10
4	cpop 1
CALL p1;
DROP PROCEDURE p1;
DROP TABLE t1;
#
# Recursive cursor and cursor%ROWTYPE declarations in the same block
#
CREATE PROCEDURE p1
AS
a INT:=10;
CURSOR cur1 IS SELECT a;
rec1 cur1%ROWTYPE;
CURSOR cur2 IS SELECT rec1.a + 1  "a";
rec2 cur2%ROWTYPE;
BEGIN
OPEN cur1;
FETCH cur1 INTO rec1;
CLOSE cur1;
SELECT rec1.a;
open cur2;
FETCH cur2 INTO rec2;
CLOSE cur2;
SELECT rec2.a;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set a@0 10
1	cursor_copy_struct cur1 rec1@1
2	set rec1@1 NULL
3	cursor_copy_struct cur2 rec2@2
4	set rec2@2 NULL
5	cpush cur1@0
6	cpush cur2@1
7	copen cur1@0
8	cfetch cur1@0 rec1@1
9	cclose cur1@0
10	stmt 0 "SELECT rec1.a"
11	copen cur2@1
12	cfetch cur2@1 rec2@2
13	cclose cur2@1
14	stmt 0 "SELECT rec2.a"
15	cpop 2
CALL p1();
rec1.a
10
rec2.a
11
DROP PROCEDURE p1;
#
# MDEV-12441 Variables declared after cursors with parameters lose values
#
CREATE PROCEDURE p1() AS
x0 INT:=100;
CURSOR cur(cp1 INT, cp2 INT) IS SELECT cp1+cp2;
x1 INT:=101;
BEGIN
OPEN cur(10,11);
CLOSE cur;
SELECT x0, x1;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set x0@0 100
1	set x1@3 101
2	cpush cur@0
3	set cp1@1 10
4	set cp2@2 11
5	copen cur@0
6	cclose cur@0
7	stmt 0 "SELECT x0, x1"
8	cpop 1
CALL p1();
x0	x1
100	101
DROP PROCEDURE p1;
CREATE PROCEDURE p1() AS
x0 INT:=100;
CURSOR cur0(cp1 INT, cp2 INT) IS SELECT cp1+cp2;
x1 INT:=101;
CURSOR cur1(cp1 INT, cp2 INT) IS SELECT cp1+cp2;
x2 INT:=102;
CURSOR cur2(cp1 INT, cp2 INT) IS SELECT cp1+cp2;
x3 INT:=103;
BEGIN
OPEN cur0(0,1);
CLOSE cur0;
SELECT x0, x1, x2, x3;
OPEN cur1(10,11);
CLOSE cur1;
SELECT x0, x1, x2, x3;
OPEN cur2(20,21);
CLOSE cur2;
SELECT x0, x1, x2, x3;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set x0@0 100
1	set x1@3 101
2	set x2@6 102
3	set x3@9 103
4	cpush cur0@0
5	cpush cur1@1
6	cpush cur2@2
7	set cp1@1 0
8	set cp2@2 1
9	copen cur0@0
10	cclose cur0@0
11	stmt 0 "SELECT x0, x1, x2, x3"
12	set cp1@4 10
13	set cp2@5 11
14	copen cur1@1
15	cclose cur1@1
16	stmt 0 "SELECT x0, x1, x2, x3"
17	set cp1@7 20
18	set cp2@8 21
19	copen cur2@2
20	cclose cur2@2
21	stmt 0 "SELECT x0, x1, x2, x3"
22	cpop 3
CALL p1();
x0	x1	x2	x3
100	101	102	103
x0	x1	x2	x3
100	101	102	103
x0	x1	x2	x3
100	101	102	103
DROP PROCEDURE p1;
CREATE TABLE t1 (a INT);
CREATE PROCEDURE p1() AS
x0 INT:=100;
CURSOR cur(cp1 INT, cp2 INT) IS SELECT cp1+cp2;
x1 t1.a%TYPE:=101;
BEGIN
OPEN cur(10,11);
CLOSE cur;
SELECT x0, x1;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set x0@0 100
1	set x1@3 101
2	cpush cur@0
3	set cp1@1 10
4	set cp2@2 11
5	copen cur@0
6	cclose cur@0
7	stmt 0 "SELECT x0, x1"
8	cpop 1
CALL p1();
x0	x1
100	101
DROP PROCEDURE p1;
DROP TABLE t1;
CREATE PROCEDURE p1() AS
x0 INT:=100;
CURSOR cur(cp1 INT, cp2 INT) IS SELECT cp1+cp2;
x1 ROW(a INT,b INT):=ROW(101,102);
BEGIN
OPEN cur(10,11);
CLOSE cur;
SELECT x0, x1.a, x1.b;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	set x0@0 100
1	set x1@3 (101,102)
2	cpush cur@0
3	set cp1@1 10
4	set cp2@2 11
5	copen cur@0
6	cclose cur@0
7	stmt 0 "SELECT x0, x1.a, x1.b"
8	cpop 1
CALL p1();
x0	x1.a	x1.b
100	101	102
DROP PROCEDURE p1;
#
# MDEV-19640 Wrong SHOW PROCEDURE output for SET GLOBAL sysvar1=expr, sysvar2=expr
#
CREATE OR REPLACE PROCEDURE p1() AS
BEGIN
SET GLOBAL max_allowed_packet=16000000, max_error_count=60;
SELECT @@GLOBAL.max_allowed_packet, @@GLOBAL.max_error_count;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	stmt 31 "SET GLOBAL max_allowed_packet=16000000"
1	stmt 31 "SET GLOBAL max_error_count=60"
2	stmt 0 "SELECT @@GLOBAL.max_allowed_packet, @..."
DROP PROCEDURE p1;
#
# MDEV-19639 sql_mode=ORACLE: Wrong SHOW PROCEDURE output for sysvar:=expr
#
CREATE OR REPLACE PROCEDURE p1() AS
BEGIN
max_error_count:=10;
END;
$$
SHOW PROCEDURE CODE p1;
Pos	Instruction
0	stmt 31 "max_error_count:=10"
DROP PROCEDURE p1;