Oracle SQL determines whether a string is a function in the target string

Source: Internet
Author: User

Oracle SQL writes a method to determine whether a string is a function in the target string based on requirements. Used to identify the following situations: Determine whether string A exists in string B separated by commas (,), for example: www.2cto.com v_str_a = aa; v_str_ B = aa, bb, dd, cc; as shown above, returns Y; otherwise, returns N. Some verifications are added. You can extract strings Based on the specified delimiter as needed. After all, Oracle's String Parsing is troublesome and can be encapsulated. SQL code uses create or replace function compute (p_target varchar2, p_str_array varchar2) return varchar2 is v_flag varchar2 (1); v_comma_loc int; v_cut_string varchar2 (300); v_rest_string varchar2 (2000 ); begin ------------------------ -- p_target cannot contain ","!!! Note !! -- Info: This function is used to identify the target string. whether to use "," to separate the strings ---------------------- v_flag: = 'n'; v_comma_loc: = instr (p_str_array ,', '); -- if the comparison string is null, false is returned if nvl (p_str_array, '') = ''then return 'n'; end if; -- if there is no comma, directly compare if length (p_str_array)> 0 and v_comma_loc = 0 then if p_target = p_str_array then return 'y'; else return 'n'; end if; v_rest_string: = p_str_array; while v_comma_loc> 0 loop v_cut_string: = substr (v_rest_string, 0, v_comma_loc-1); v_rest_string: = substr (v_rest_string, v_comma_loc + 1, length (v_rest_string) -1); if p_target = v_cut_string then v_flag: = 'y'; end if; v_comma_loc: = instr (v_rest_string ,','); if v_comma_loc = 0 and length (v_rest_string)> 0 then if p_target = v_rest_string then v_flag: = 'y'; end if; end loop; return v_flag; end;

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.