存储过程实现oracle的instr函数

CREATE PROCEDURE instr(vchar varchar(250),chr VARCHAR(250),num INTEGER)
returning integer;
DEFINE out_number INTEGER;
DEFINE here_length INTEGER;
DEFINE end_length INTEGER;
DEFINE here_char VARCHAR(250);
DEFINE num_flag INTEGER;
LET num_flag = 1;
LET here_length = 1;
LET end_length = length(chr);
LET out_number = -10000;
while here_length + end_length - 1 <= length(vchar)
LET here_char = substr(vchar,here_length,end_length);
IF here_char = chr AND num_flag = num THEN
LET out_number = here_length;
LET here_length = length(vchar) + 1;
ELIF here_char = chr AND num_flag != num THEN
LET num_flag = num_flag + 1;
END IF;
LET here_length = here_length + 1;
END WHILE;
RETURN out_number;
END PROCEDURE;

你可能感兴趣的:(存储过程实现oracle的instr函数)