File: sp-record.result

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (775 lines) | stat: -rw-r--r-- 15,513 bytes parent folder | download | duplicates (2)
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
# Start of 11.8 tests
# 
# MDEV-34317 DECLARE TYPE type_name IS RECORD (..) with scalar members in stored routines
# 
set sql_mode=oracle;
#
# Basic RECORD
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4),
dept_name  VARCHAR2(30),
mgr_id     NUMBER(6),
loc_id     NUMBER(4)
);
dept_rec DeptRecTyp:= DeptRecTyp(11,'a',201,1700);
str VARCHAR(1024);
BEGIN
str:= 
'dept_id:   ' || dept_rec.dept_id   || '; ' ||
'dept_name: ' || dept_rec.dept_name || '; ' ||
'mgr_id:    ' || dept_rec.mgr_id    || '; ' ||
'loc_id:    ' || dept_rec.loc_id;
SELECT str;
END;
$$
str
dept_id:   11; dept_name: a; mgr_id:    201; loc_id:    1700
#
# RECORD fields with anchored type
#
CREATE TABLE t1
(
dept_id    NUMBER(4),
dept_name  VARCHAR2(30),
mgr_id     NUMBER(6),
loc_id     NUMBER(4)
);
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    t1.dept_id%TYPE,
dept_name  t1.dept_name%TYPE,
mgr_id     t1.mgr_id%TYPE,
loc_id     t1.loc_id%TYPE
);
dept_rec DeptRecTyp:= DeptRecTyp(11,'a',201,1700);
str VARCHAR(1024);
BEGIN
str:= 
'dept_id:   ' || dept_rec.dept_id   || '; ' ||
'dept_name: ' || dept_rec.dept_name || '; ' ||
'mgr_id:    ' || dept_rec.mgr_id    || '; ' ||
'loc_id:    ' || dept_rec.loc_id;
SELECT str;
END;
$$
str
dept_id:   11; dept_name: a; mgr_id:    201; loc_id:    1700
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(5) CHARACTER SET utf8mb4, b INT, c DOUBLE);
CREATE OR REPLACE PROCEDURE p1 AS
TYPE RecT IS RECORD (
a t1.a%TYPE,
b t1.b%TYPE,
c t1.c%TYPE
);
rec RecT:= RecT('a',2,3.5);
BEGIN
CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c;
SHOW CREATE TABLE t2;
SELECT * FROM t2;
DROP TABLE t2;
END;
$$
CALL p1;
Table	Create Table
t2	CREATE TABLE "t2" (
  "rec.a" varchar(5) DEFAULT NULL,
  "rec.b" int(11) DEFAULT NULL,
  "rec.c" double DEFAULT NULL
)
rec.a	rec.b	rec.c
a	2	3.5
DROP PROCEDURE p1;
DROP TABLE t1;
#
# RECORD using SUBTYPE
# This is not supported yet
#
CREATE TABLE t1
(
dept_id    NUMBER(4),
dept_name  VARCHAR2(30),
mgr_id     NUMBER(6),
loc_id     NUMBER(4)
);
DECLARE
SUBTYPE DeptRecTyp IS t1%ROWTYPE;
dept_rec DeptRecTyp;
str VARCHAR(1024);
BEGIN
dept_rec.dept_id  := 11;
dept_rec.dept_name:= 'a';
dept_rec.mgr_id   := 201;
dept_rec.loc_id   := 1700;
str:= 
'dept_id:   ' || dept_rec.dept_id   || '; ' ||
'dept_name: ' || dept_rec.dept_name || '; ' ||
'mgr_id:    ' || dept_rec.mgr_id    || '; ' ||
'loc_id:    ' || dept_rec.loc_id;
SELECT str;
END;
$$
ERROR HY000: Unknown data type: 'DeptRecTyp'
DROP TABLE t1;
#
# RECORD with NOT NULL or default clauses
# This is not supported yet
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4) NOT NULL := 10,
dept_name  VARCHAR2(30) NOT NULL := 'Administration',
mgr_id     NUMBER(6) := 200,
loc_id     NUMBER(4) := 1700
);
dept_rec DeptRecTyp;
str VARCHAR(1024);
BEGIN
str:= 
'dept_id:   ' || dept_rec.dept_id   || '; ' ||
'dept_name: ' || dept_rec.dept_name || chr(13) ||
'mgr_id:    ' || dept_rec.mgr_id    || chr(13) ||
'loc_id:    ' || dept_rec.loc_id;
SELECT str;
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL := 10,
dept_name  VARCHAR2(30) NOT NULL := 'Administration',
mgr_id ...' at line 3
#
# Nested RECORDs
# This is not supported yet
#
DECLARE
TYPE name_rec IS RECORD (
first  VARCHAR(64),
last   VARCHAR(64)
);
TYPE contact IS RECORD (
name  name_rec,     -- a nested record
phone VARCHAR(32)
);
person contact;
str VARCHAR(1024);
BEGIN
person.name.first := 'John';
person.name.last := 'Brown';
person.phone := '1-654-222-1234';
str:= 
person.name.first  || ' ' ||
person.name.last   || ', ' ||
person.phone;
SELECT str;
END;
$$
ERROR HY000: Unknown data type: 'name_rec'
#
# RECORD duplicate type declaration
#
DECLARE
TYPE RcType IS RECORD (
a NUMBER(4)
);
TYPE RcType IS RECORD (
b NUMBER(4)
);
BEGIN
END;
$$
ERROR HY000: Duplicate declaration: 'RcType'
#
# RECORD with no field
#
DECLARE
TYPE RcType IS RECORD (
);
rec RcType;
str VARCHAR(1024);
BEGIN
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ');
rec RcType;
str VARCHAR(1024);
BEGIN
END' at line 3
#
# RECORD field test
#
DECLARE
TYPE RcType IS RECORD (
int11 INT,
dec103 DECIMAL(10,3),
flt0 FLOAT,
dbl0 DOUBLE,
enum0 ENUM('a','b'),
bit3 BIT(3),
varchar10 VARCHAR(10),
text1 TEXT,
tinytext1 TINYTEXT,
mediumtext1 MEDIUMTEXT CHARACTER SET utf8,
longtext1 LONGTEXT,
time3 TIME(3),
datetime4 DATETIME(4),
timestamp5 TIMESTAMP(5),
date0 DATE
);
rec1,rec2 RcType:= RcType(4, 11.2, 6.7, 111.43234663, 'a', b'101',
'bbbb', 'TEXT', 'TINY', 'MEDIUM', 'LONG',
'10:14:22','2001-07-22 10:14:22', '2001-07-22 12:12:12', '2001-07-22');
rec3 RcType;
BEGIN
SELECT rec1.int11, rec2.timestamp5, rec3.date0;
END;
$$
rec1.int11	rec2.timestamp5	rec3.date0
4	2001-07-22 12:12:12.00000	NULL
#
# RECORD with field manipulations
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
dept_rec DeptRecTyp;
test INT:=4;
BEGIN
dept_rec.dept_id:= 2;
test:= test + dept_rec.dept_id;
dept_rec.dept_id:= 5;
SELECT dept_rec.dept_id, test;
END;
$$
dept_rec.dept_id	test
5	6
#
# RECORD comparison
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4),
dept_name  VARCHAR(20)
);
dept_rec1 DeptRecTyp := DeptRecTyp(1,'a');
dept_rec2 DeptRecTyp := DeptRecTyp(1,'a');
BEGIN
SELECT dept_rec1 = dept_rec2;
dept_rec2.dept_id:= 2;
SELECT dept_rec1 = dept_rec2;
END;
$$
dept_rec1 = dept_rec2
1
dept_rec1 = dept_rec2
0
#
# RECORD comparison
# RECORD type comparison is not supported for records with only
# one field (bug, see MDEV-35274)
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
dept_rec1 DeptRecTyp;
dept_rec2 DeptRecTyp;
BEGIN
SELECT dept_rec1 = dept_rec2;
END;
$$
ERROR 21000: Operand should contain 1 column(s)
#
# RECORD assignment with the same type
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
dept_rec1 DeptRecTyp:= DeptRecTyp(11);
dept_rec2 DeptRecTyp:= DeptRecTyp(12);
BEGIN
dept_rec1:= dept_rec2;
SELECT dept_rec1.dept_id, dept_rec2.dept_id;
END;
$$
dept_rec1.dept_id	dept_rec2.dept_id
12	12
#
# RECORD assignment with different types, but the same fields
# This fails in ORACLE TODO
#
DECLARE
TYPE DeptRecTyp1 IS RECORD (
dept_id    NUMBER(4)
);
TYPE DeptRecTyp2 IS RECORD (
dept_id    NUMBER(4)
);
dept_rec1 DeptRecTyp1:= DeptRecTyp1(11);
dept_rec2 DeptRecTyp2:= DeptRecTyp2(12);
BEGIN
dept_rec1:= dept_rec2;
SELECT dept_rec1.dept_id, dept_rec2.dept_id;
END;
$$
dept_rec1.dept_id	dept_rec2.dept_id
12	12
#
# RECORD assignment with different types
# This fails in ORACLE with
# PLS-00382: expression is of wrong type
# In MariaDB we need to set sql_mode='strict_all_tables'
# to get a similar effect. Otherwise we only get a warning.
#
DECLARE
TYPE DeptRecTyp1 IS RECORD (
dept_id    NUMBER(4)
);
TYPE DeptRecTyp2 IS RECORD (
dept_id    VARCHAR2(30)
);
dept_rec1 DeptRecTyp1:= DeptRecTyp1(11);
dept_rec2 DeptRecTyp2:= DeptRecTyp2('a');
BEGIN
dept_rec1:= dept_rec2;
SELECT dept_rec1.dept_id, dept_rec2.dept_id;
END;
$$
dept_rec1.dept_id	dept_rec2.dept_id
0	a
Warnings:
Warning	1366	Incorrect decimal value: 'a' for column ``.``.`dept_id` at row 0
#
# RECORD assignment with anchored ROWTYPE from table
#
CREATE TABLE t1
(
dept_id    NUMBER(4)
);
INSERT INTO t1 VALUES(12);
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
dept_rec1 DeptRecTyp:= DeptRecTyp(11);
dept_rec2 t1%ROWTYPE;
BEGIN
SELECT dept_id INTO dept_rec2 FROM t1 WHERE ROWNUM < 2;
dept_rec1:= dept_rec2;
SELECT dept_rec1.dept_id, dept_rec2.dept_id;
END;
$$
dept_rec1.dept_id	dept_rec2.dept_id
12	12
DROP TABLE t1;
#
# RECORD assignment with anchored ROWTYPE from cursor (1)
#
CREATE TABLE t1
(
dept_id    NUMBER(4)
);
INSERT INTO t1 VALUES(12);
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
CURSOR c1 IS SELECT * FROM t1;
dept_rec1 DeptRecTyp:= DeptRecTyp(11);
BEGIN
DECLARE
dept_rec2 c1%ROWTYPE;
BEGIN
SELECT dept_id INTO dept_rec2 FROM t1 WHERE ROWNUM < 2;
dept_rec1:= dept_rec2;
SELECT dept_rec1.dept_id, dept_rec2.dept_id;
END;
END;
$$
dept_rec1.dept_id	dept_rec2.dept_id
12	12
DROP TABLE t1;
#
# RECORD assignment with anchored ROWTYPE from cursor (2)
#
CREATE TABLE t1 (a INT, b VARCHAR(10));
CREATE PROCEDURE p1()
AS
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4),
b VARCHAR(10)
);
CURSOR cur1 IS SELECT * FROM t1;
BEGIN
DECLARE
rec1 DeptRecTyp:=DeptRecTyp(11,'a');
rec2 cur1%ROWTYPE;
BEGIN
rec2.a:= 10;
rec2.b:= 'bbb';
rec1:= rec2;
SELECT rec1.dept_id, rec2.a;
END;
END;
$$
CALL p1();
rec1.dept_id	rec2.a
10	10
DROP TABLE t1;
DROP PROCEDURE p1;
#
# RECORD within stored procedures
#
CREATE OR REPLACE PROCEDURE p1() AS
TYPE DeptRecTyp IS RECORD(dept_id    NUMBER(4));
dept_rec DeptRecTyp;
BEGIN
END;
$$
DROP PROCEDURE p1;
#
# SELECT INTO RECORD (??)
#
CREATE TABLE t1
(
dept_id    NUMBER(4),
dept_name  VARCHAR2(30),
mgr_id     NUMBER(6),
loc_id     NUMBER(4)
);
INSERT INTO t1 VALUES(12, 'b',202,2000);
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    t1.dept_id%TYPE,
dept_name  t1.dept_name%TYPE,
mgr_id     t1.mgr_id%TYPE,
loc_id     t1.loc_id%TYPE
);
dept_rec DeptRecTyp:= DeptRecTyp(11,'a',201,1700);
str VARCHAR(1024);
BEGIN
SELECT * INTO dept_rec FROM t1 WHERE ROWNUM <= 1;
str:= 
'dept_id:   ' || dept_rec.dept_id   || '; ' ||
'dept_name: ' || dept_rec.dept_name || '; ' ||
'mgr_id:    ' || dept_rec.mgr_id    || '; ' ||
'loc_id:    ' || dept_rec.loc_id;
SELECT str;
END;
$$
str
dept_id:   12; dept_name: b; mgr_id:    202; loc_id:    2000
DROP TABLE t1;
#
# INSERT RECORDs INTO table
# Not supported (?)
# This is supported in Oracle with `VALUES row_constructor_list`
CREATE TABLE t1
(
dept_id    NUMBER(4),
dept_name  VARCHAR2(30),
mgr_id     NUMBER(6),
loc_id     NUMBER(4)
);
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    t1.dept_id%TYPE,
dept_name  t1.dept_name%TYPE,
mgr_id     t1.mgr_id%TYPE,
loc_id     t1.loc_id%TYPE
);
dept_rec DeptRecTyp:= DeptRecTyp(11,'a',201,1700);
str VARCHAR(1024);
BEGIN
INSERT INTO t1 VALUES dept_rec;
SELECT * FROM t1;
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'dept_rec;
SELECT * FROM t1;
END' at line 11
DROP TABLE t1;
#
# UPDATE table using RECORD
# This is supported in Oracle
CREATE TABLE t1
(
dept_id    NUMBER(4)
);
INSERT INTO t1 VALUES(12);
DECLARE
TYPE DeptRecTyp IS RECORD(dept_id    NUMBER(4));
dept_rec DeptRecTyp:= DeptRecTyp(11);
BEGIN
UPDATE t1 SET ROW = dept_rec WHERE dept_id = 12;
END;
$$
ERROR 42S22: Unknown column 'ROW' in 'SET'
DROP TABLE t1;
#
# Wrong parameter count to RECORD's constructor (actual < expected)
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4),
dept_name  VARCHAR2(30),
mgr_id     NUMBER(6),
loc_id     NUMBER(4)
);
dept_rec DeptRecTyp:= DeptRecTyp(11,'a',201);
str VARCHAR(1024);
BEGIN
str:= 
'dept_id:   ' || dept_rec.dept_id   || '; ' ||
'dept_name: ' || dept_rec.dept_name || '; ' ||
'mgr_id:    ' || dept_rec.mgr_id    || '; ' ||
'loc_id:    ' || dept_rec.loc_id;
select str;
END;
$$
ERROR 21000: Operand should contain 4 column(s)
#
# Wrong parameter count to RECORD's constructor (actual > expected)
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4),
dept_name  VARCHAR2(30),
mgr_id     NUMBER(6),
loc_id     NUMBER(4)
);
dept_rec DeptRecTyp:= DeptRecTyp(11,'a',201,1700,2000);
str VARCHAR(1024);
BEGIN
str:= 
'dept_id:   ' || dept_rec.dept_id   || '; ' ||
'dept_name: ' || dept_rec.dept_name || '; ' ||
'mgr_id:    ' || dept_rec.mgr_id    || '; ' ||
'loc_id:    ' || dept_rec.loc_id;
SELECT str;
END;
$$
ERROR 21000: Operand should contain 4 column(s)
#
# Case insensitivity test for RECORD variable
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
dept_rec DeptRecTyp:= DeptRecTyp(11);
str VARCHAR(1024);
BEGIN
SELECT DEPT_rec.DEPT_id;
END;
$$
DEPT_rec.DEPT_id
11
#
# Quoted indentifier test for RECORD variable
#
DECLARE
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
"dept/rec" DeptRecTyp:= DeptRecTyp(11);
str VARCHAR(1024);
BEGIN
SELECT "dept/rec".dept_id;
END;
$$
"dept/rec".dept_id
11
#
# RECORD type used in a stored PROCEDURE
#
CREATE PROCEDURE p1(v NUMBER) AS
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
dept_rec DeptRecTyp:= DeptRecTyp(11);
BEGIN
SELECT dept_rec.dept_id + v;
END;
$$
CALL p1(4);
dept_rec.dept_id + v
15
DROP PROCEDURE p1;
#
# RECORD type used in a stored FUNCTION
#
CREATE FUNCTION f1(v NUMBER)
RETURN NUMBER IS
TYPE DeptRecTyp IS RECORD (
dept_id    NUMBER(4)
);
dept_rec DeptRecTyp:= DeptRecTyp(11);
BEGIN
RETURN dept_rec.dept_id + v;
END;
$$
SELECT f1(4);
f1(4)
15
DROP FUNCTION f1;
#
# RECORD keyword as identifier (sp var name)
#
DECLARE
RECORD NUMBER(4);
BEGIN
SELECT RECORD;
END;
$$
RECORD
NULL
#
# RECORD keyword as identifier (function name)
#
CREATE FUNCTION RECORD(a IN NUMBER) 
RETURN NUMBER 
IS b NUMBER(11,2);
BEGIN
b:= a;
RETURN(b); 
END;
$$
DROP FUNCTION RECORD;
SET sql_mode=default;
#
# Basic RECORD, anonymous block sql_mode=default;
#
BEGIN NOT ATOMIC
DECLARE TYPE DeptRecTyp IS RECORD (
dept_id    INT
);
DECLARE dept_rec DeptRecTyp DEFAULT DeptRecTyp(11);
SELECT dept_rec.dept_id;
END;
$$
ERROR HY000: Unknown data type: 'DeptRecTyp'
#
# Basic RECORD, stored procedure sql_mode=default;
#
CREATE OR REPLACE PROCEDURE p1()
BEGIN
DECLARE TYPE DeptRecTyp IS RECORD (
dept_id    INT
);
DECLARE dept_rec DeptRecTyp DEFAULT DeptRecTyp(11);
SELECT dept_rec.dept_id;
END;
$$
ERROR HY000: Unknown data type: 'DeptRecTyp'
CALL p1();
ERROR 42000: PROCEDURE test.p1 does not exist
DROP PROCEDURE p1;
ERROR 42000: PROCEDURE test.p1 does not exist
#
# Basic RECORD, stored function sql_mode=default;
#
CREATE OR REPLACE FUNCTION f1() RETURNS INT
BEGIN
DECLARE TYPE DeptRecTyp IS RECORD (
dept_id    INT
);
DECLARE dept_rec DeptRecTyp DEFAULT DeptRecTyp(11);
RETURN dept_rec.dept_id;
END;
$$
ERROR HY000: Unknown data type: 'DeptRecTyp'
SELECT f1();
ERROR 42000: FUNCTION test.f1 does not exist
DROP FUNCTION f1;
ERROR 42000: FUNCTION test.f1 does not exist
SET sql_mode=ORACLE;
#
# Ensure keyword TYPE can still be used when sql_mode=ORACLE
# for DATABASE
#
CREATE DATABASE TYPE;
DROP DATABASE TYPE;
#
# Ensure keyword TYPE can still be used when sql_mode=ORACLE
# for TABLE
#
CREATE TABLE TYPE(a INTEGER);
INSERT INTO TYPE VALUES (1);
SELECT * FROM TYPE;
a
1
DROP TABLE TYPE;
#
# Ensure keyword TYPE can still be used when sql_mode=ORACLE
# for COLUMN name
#
CREATE TABLE t1(TYPE INTEGER);
INSERT INTO t1 VALUES (1);
SELECT TYPE FROM t1 WHERE TYPE=1;
TYPE
1
SELECT b.TYPE FROM t1 b WHERE b.TYPE=1;
TYPE
1
DROP TABLE t1;
#
# Ensure that DATE field of a record maps correctly to MariaDB
# DATETIME
#
DECLARE
TYPE rec_t IS RECORD (
a INT,
b DATE
);
rec rec_t:= rec_t(1,'2021-01-01 10:20:30');
BEGIN
CREATE TABLE t1 AS SELECT rec.a, rec.b;
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
END;
$$
Table	Create Table
t1	CREATE TABLE "t1" (
  "rec.a" int(11) DEFAULT NULL,
  "rec.b" datetime DEFAULT NULL
)
rec.a	rec.b
1	2021-01-01 10:20:30
#
# Ensure that nested record types are properly parsed (without crash, etc)
#
SET sql_mode=ORACLE;
DECLARE
TYPE rec_t IS RECORD (
a INT,
b DATE
);
rec rec_t:= rec_t(1,'2021-01-01 10:20:30');
TYPE rec2_t IS RECORD
(
a INT,
b rec_t
);
BEGIN
NULL;
END;
$$
ERROR HY000: Unknown data type: 'rec_t'
#
# Multiple RECORD variable declaration+initialization test
#
DECLARE
TYPE rec_t IS RECORD (
a  NUMBER(4),
b  VARCHAR2(30)
);
rec0, rec1, rec2 rec_t := rec_t(1,'a'); BEGIN
SELECT rec0.a || rec0.b AS r0, rec1.a || rec1.b AS t1, rec2.a || rec2.b AS r2; END;
$$
r0	t1	r2
1a	1a	1a
# End of 11.8 tests