github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/function/function_instr.sql (about) 1 -- @suit 2 -- @case 3 -- @test function INSTR(str,SUBSTR) 4 -- @label:bvt 5 6 SELECT INSTR('ejwnqke','wn'); 7 SELECT INSTR('wn','ejwnqke'); 8 SELECT INSTR('hvjdke3qj','a'); 9 SELECT INSTR('今天是晴天ok.are yioeore;wmv','晴天'); 10 SELECT INSTR('ewhihjreiwhvrejw8344332¥#……@#@¥#@¥DSCSVRERGEWvefw',''); 11 SELECT INSTR('edhjw 38902&A**',' '); 12 SELECT INSTR('reuwYHWJMQ781///-+++','fe3232'); 13 SELECT INSTR('',''); 14 SELECT INSTR('','ehwj32'); 15 SELECT INSTR('251625%$#@*(ejf2f32f',''); 16 SELECT INSTR(NULL,'ewqe'); 17 SELECT INSTR('24e8w7/*37289',NULL); 18 SELECT INSTR(NULL,NULL); 19 20 21 -- @suite 22 -- @setup 23 DROP TABLE IF EXISTS instr_01; 24 CREATE TABLE instr_01(id int, 25 str1 CHAR, 26 str2 VARCHAR(30), 27 PRIMARY KEY(id)); 28 29 30 INSERT INTO instr_01 VALUES(1, 'a', 'dhehw'); 31 INSERT INTO instr_01 VALUES(2, '2', '372890932'); 32 INSERT INTO instr_01 VALUES(3, '*', 'fejkj4kl332342'); 33 INSERT INTO instr_01 VALUES(4, '-', ' 4ej348324*&&^*&*--++'); 34 INSERT INTO instr_01 VALUES(5, '.', '3h2h3kj2*()____ ))() '); 35 INSERT INTO instr_01 VALUES(6, '', NULL); 36 INSERT INTO instr_01 VALUES(7, NULL, ''); 37 INSERT INTO instr_01 VALUES(8, NULL, NULL); 38 39 40 SELECT INSTR(str2,str1) FROM instr_01; 41 SELECT INSTR(str2,'') FROM instr_01 WHERE str2 IS NOT NULL; 42 SELECT INSTR('',str1) FROM instr_01; 43 SELECT INSTR(NULL, str2) FROM instr_01; 44 SELECT INSTR(str1, NULL) FROM instr_01; 45 SELECT * FROM instr_01 WHERE instr(str2,'qke') = 5; 46 SELECT id,str1,str2 FROM instr_01 WHERE instr(str2, '32') = NULL; 47 48 49 -- subquries 50 SELECT * FROM instr_01 WHERE id = (SELECT id FROM instr_01 WHERE instr(str2,'qke') = 5); 51 SELECT(SELECT str2 FROM instr_01 WHERE instr(str1,'a') = 1),id FROM instr_01; 52 SELECT id ,str1, str2 FROM instr_01 WHERE id = (SELECT id FROM instr_01 WHERE instr(str2,'aaa') = NULL); 53 54 55 -- -- Nested with string functions 56 SELECT concat_ws('-',INSTR(str2,str1),INSTR('abc','a')) FROM instr_01; 57 SELECT find_in_set(INSTR(str2,str1),'hdkewqjfew-') FROM instr_01 WHERE id = 4; 58 SELECT oct(INSTR(str2,str1)) FROM instr_01 WHERE id = 4; 59 SELECT empty(instr(str2,str1)) FROM instr_01; 60 SELECT LENGTH(INSTR(str2,str1)) FROM instr_01; 61 SELECT INSTR(LTRIM(str2),'*&&^*&') FROM instr_01 WHERE id = 4; 62 SELECT INSTR(RTRIM(str2),'()____ )') FROM instr_01 WHERE str1 = '.'; 63 SELECT LPAD(INSTR(str2, str1), 10, '-') FROM instr_01; 64 SELECT RPAD(INSTR(str2, 3), 5, '***') FROM instr_01; 65 SELECT substring(instr(str1,'a'),'321421') FROM instr_01; 66 SELECT INSTR(REVERSE(str2), ' ') FROM instr_01; 67 SELECT bin(INSTR(str1, 'a')) FROM instr_01 WHERE id = 1; 68 SELECT hex(INSTR(str2, 'w')) FROM instr_01 WHERE id = 1; 69 70 71 -- @suite 72 -- @setup 73 DROP TABLE IF EXISTS instr_02; 74 CREATE TABLE instr_02(id int, 75 str1 mediumtext, 76 str2 VARCHAR(30) NOT NULL); 77 78 79 INSERT INTO instr_02 VALUES(1, '今天是很美好的一天 Today is a wonderful day!!!', '美好'); 80 INSERT INTO instr_02 VALUES(2, '4**-1+83982j4mfkerwvuh43oij3f42j4iuu32oi4ejf32j432YUDINWKJ<DJ>>A>欢迎使用mo',''); 81 INSERT INTO instr_02 VALUES(3, '', 'gchjewqhedjw'); 82 INSERT INTO instr_02 VALUES(4, '', ''); 83 INSERT INTO instr_02 VALUES(5, NULL,'abcd'); 84 INSERT INTO instr_02 VALUES(6, ' ewfew3324 ed_+_+ ', 'ew'); 85 86 87 SELECT * FROM instr_02 WHERE INSTR(str1,str2) = 5; 88 SELECT INSTR(str1, str2) FROM instr_02; 89 SELECT INSTR(str2, str1) FROM instr_02; 90 SELECT * FROM instr_02 WHERE id = (SELECT id FROM instr_02 WHERE INSTR(str1,'+8') = 6); 91 SELECT(SELECT str2 FROM instr_02 WHERE instr(str1,'a') = 1),id FROM instr_02; 92 93 94 -- Nested with string functions 95 SELECT concat_ws('-',INSTR(str2,str1),INSTR('abc','a')) FROM instr_02; 96 SELECT find_in_set(INSTR(str2,str1),'hdkewqjfew-') FROM instr_02 WHERE id = 4; 97 SELECT oct(INSTR(str2,str1)) FROM instr_02 WHERE id = 4; 98 SELECT empty(instr(str2,str1)) FROM instr_02; 99 SELECT LENGTH(INSTR(str2,str1)) FROM instr_02; 100 SELECT INSTR(LTRIM(str1),'ed_+_+') FROM instr_02 WHERE id = 6; 101 SELECT INSTR(RTRIM(str1),'3324') FROM instr_02 WHERE id = 6; 102 SELECT LPAD(INSTR(str2, str1), 6, 'abc') FROM instr_02; 103 SELECT RPAD(INSTR(str2, 3), 5, '') FROM instr_02; 104 SELECT INSTR(substring(str2, 1, 6), 'cd') FROM instr_02 WHERE id = 5; 105 SELECT INSTR(REVERSE(str1), '用使') FROM instr_02 WHERE id = 2; 106 SELECT bin(INSTR(str2, 'd')) FROM instr_02 WHERE id = 3; 107 SELECT hex(INSTR(str1, 'ed')) FROM instr_02 WHERE id = 6; 108 109 110 111 -- @suite 112 -- @setup 113 DROP TABLE IF EXISTS instr_03; 114 DROP TABLE IF EXISTS instr_04; 115 CREATE TABLE instr_03( 116 id int, 117 d1 CHAR, 118 str1 VARCHAR(50), 119 primary key (id)); 120 121 CREATE TABLE instr_04( 122 id int, 123 str1 mediumtext NOT NULL, 124 primary key (id)); 125 126 127 INSERT INTO instr_03 VALUES(1, 'a', 'zheshimeihaodeyitian,这是美好的一天'); 128 INSERT INTO instr_03 VALUES(2, '*', '明天更美好ehwqknjcw*^*qk67329&&*'); 129 INSERT INTO instr_03 VALUES(3, NULL, 'ewgu278wd-+ABNJDSK'); 130 INSERT INTO instr_03 VALUES(4, '', NULL); 131 132 INSERT INTO instr_04 VALUES(1, '盼望着,盼望着,东风来了,春天的脚步近了。 一切都像刚睡醒的样子,欣欣然张开了眼。山朗润起来了,水涨 起来了,太阳的脸红起来了。 小草偷偷地从土里钻出来,Choose to Be Alone on Purpose Here we are, all by ourselves, all 22 million of us by recent count, alone in our rooms'); 133 INSERT INTO instr_04 VALUES(2, 'zheshimeihaodeyitian,这是美好的一天'); 134 INSERT INTO instr_04 VALUES(3, 'ewgu278wd-+ABNJDSK'); 135 INSERT INTO instr_04 VALUES(4, 'hey32983..........,,'); 136 137 138 SELECT * FROM instr_03 WHERE id = (SELECT id FROM instr_04 WHERE INSTR(str1,'u27')); 139 SELECT instr_03.id AS id_3,instr_03.id AS id_4 FROM instr_03,instr_04 WHERE INSTR(instr_03.str1,'shi') = INSTR(instr_04.str1,'美好'); 140 SELECT instr_03.str1 AS str1_3,instr_03.str1 FROM instr_03,instr_04 WHERE INSTR(instr_03.str1,'meihao') = INSTR(instr_04.str1,'meihao'); 141 SELECT INSTR(instr_03.str1, 'ABNJDSK') FROM instr_03,instr_04 WHERE instr_03.str1 = instr_04.str1; 142 SELECT * FROM instr_03 WHERE str1 = (SELECT str1 FROM instr_04 WHERE INSTR(str1,'ABNJDSK') = 12); 143 144 145 -- join 146 SELECT INSTR(instr_03.str1, 'zheshi')AS tmp, instr_04.str1 AS temp FROM instr_03 join instr_04 ON instr_03.str1 = instr_04.str1; 147 SELECT instr_03.id AS id_3,instr_04.id AS id_4 FROM instr_03 left join instr_04 ON instr_03;