Oracle simple string sharding Function

Source: Internet
Author: User

 

When writing a stored procedure, a split string is used. The first input parameter is a string with a delimiter and the second parameter is the number of delimiters. The following is a single-Proposed string splitting method,

 

 

Create or replace procedure split (
I _pageids in varchar2, -- the original page pageid group, which is passed in as a string, for example, 1001,1511,
I _pageidscount in number -- number of pageids (also the number of comma separators, remember to add a comma at the end of the string)
)

Is
V_pageid number (20); -- save the value in the split string
V_ I number (20); -- index in the loop
V_strlength number (20); -- truncates the string length.
V_startindex number (20); -- start position of the truncated string
V_tempindex number (20); -- start position of the last string to be truncated

Begin

-- Obtain all pageids in the pageid string cyclically
For V_ I in 1 .. I _pageidscount Loop
If (V_ I = 1)
Then
V_startindex: = 1;
V_strlength: = instr (I _pageids, ',', 1, 1)-1;
Else
V_tempindex: = instr (I _pageids, ',', 1, v_i-1 );
V_strlength: = instr (I _pageids, ',', 1, V_ I)-v_tempIndex-1;
V_startindex: = v_tempindex + 1;
End if;

-- Get the pageid value in the page Array
V_pageid: = to_number (substr (I _pageids, v_startindex, v_strlength ));

-- V_pageid is the value after splitting.

End loop;

End split;

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.