Oracle Database string cutting split

Source: Internet
Author: User


1 create Database type SQL code CREATE or replace type STR_SPLIT as table of varchar2 (50) 2 create function www.2cto.com SQL code CREATE OR REPLACE FUNCTION SPLITSTR (P_STRING
IN VARCHAR2, P_DELIMITER IN VARCHAR2) RETURN STR_SPLIT pipelined is V_LENGTH NUMBER: = LENGTH (P_STRING); V_START NUMBER: = 1; V_INDEX NUMBER; begin while (V_START <= V_LENGTH) LOOP V_INDEX: = INSTR (P_STRING, P_DELIMITER, V_START); IF V_INDEX = 0 then pipe row (SUBSTR (P_STRING, V_START); V_START: = V_LENGTH + 1; else pipe row (SUBSTR (P_STRING, V_START, V_INDEX-V_START); V_START: = V_INDEX + 1; END IF; end loop; RETURN; end splitstr; 3 test www.2cto.com SQL code select * from table (splitstr ('hello, Cnblogs! ',', '); Converts rows into columns for display: SQL code select. column_value v1, B. column_value v2 from (select * from (select rownum rn, t. * from table (splitstr
('Hello, Cnblogs! ',', ') T) a, (select * from (select rownum rn, t. * from table (splitstr
('Hello, Cnblogs! ',', ') T) B where a. rn = 1 and B. rn = 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.