MYSQL存储过程根据分隔符截取

开始

1、建立存储过程

CREATE OR REPLACE PROCEDURE pro_testcom (p_string IN VARCHAR2,p_string_size IN NUMBER)
IS
   p_start NUMBER := 1;
   p_subLength NUMBER := 1;
   sub_string VARCHAR2(256);
BEGIN
   WHILE(p_start < p_string_size + 1) LOOP
     p_subLength := INSTR(p_string,'.',p_start);
     IF p_subLength = 0 THEN
       p_subLength := p_string_size + 1;
     END IF ;
     sub_string := SUBSTR(p_string , p_start , p_subLength - p_start);
     -- 打印结果
     DBMS_OUTPUT.PUT_LINE(sub_string);
     p_start := p_subLength + 1;

   END LOOP;
END pro_testcom;

 2、执行存储过程

       我这里使用的plsql工具,在工具中创建命令窗口。

       首先执行:

-- 打开日志输出
set serveroutput on;

       然后执行存储过程:

exec pro_testcom('555.555.555.555' , 15);

       执行结果如下: 

555
555
555
555
PL/SQL procedure successfully completed

结束

结尾:仅供自己学习,记录问题和参考,若有带来误解和不便请见谅,共勉!

猜你喜欢

转载自blog.csdn.net/liguoqingxjxcc/article/details/81627028