Oracle Multi_like Function

Source: Internet
Author: User


The Oracle Multi_like function is in VFP, and a disgusting function is called inlist (). It can be used as the Vfp code inlist ('% A %', '% B %', '% C %') to like several times at A time, or like an array. Well, because of business needs, our SQL also has such requirements. To meet this requirement, I wrote a Multi_like function. Input two strings for comparison. Want to use the function code. Www.2cto.com SQL code create or replace function func_multi_like (p_src varchar2, p_str varchar2) return number is v_result number default 0; v_str varchar2 (200); v_posistion number; v_sub_str varchar2 (200 ); -- STR v_tmp_str varchar2 (200); -- the remaining str begin after the interception -- returns v_str: = REPLACE (p_str, '); v_str: = trim (v_str); v_posistion: = instr (v_str, ','); -- determines if there is a comma? If v_posistion> 0 then -- str v_sub_str: = trim (substr (v_str, 0, v_posistion) with commas (,); -- str v_tmp_str: = trim (substr (v_str, v_posistion + 1, LENGTH (v_str)-v_posistion); www.2cto.com -- exit while v_posistion <> 0 loop -- reset v_posistion: = 0 if no comma is found; -- if not only a comma is intercepted, the data is intercepted and judged. -- If one of the matches is successful, result> 0 if LENGTH (v_sub_str)> 1 and instr (p_src, trim (substr (v_sub_str, 0, LENGTH (v_sub_str) -1)> 0 then v_result: = instr (p_src, trim (substr (v_sub_str, 0, LENGTH (v_sub_str)-1); end if; v_posistion: = instr (v_tmp_str, ','); v_sub_str: = trim (substr (v_tmp_str, 0, v_posistion); v_tmp_str: = trim (substr (v_tmp_str, v_posistion + 1, LENGTH (v_tmp_str)-v_posistion); www.2cto.com end loop; if instr (p_s Rc, trim (v_tmp_str)> 0 then v_result: = instr (p_src, trim (v_tmp_str); end if; else -- no comma, directly match v_result: = instr (p_src, v_str); end if; return v_result; -- if 0 is returned, the matching fails. if 0 is returned, the matching succeeds. End; enter two parameters for matching. For example, to match google, baidu, and sina, you can use the SQL code select * from media_table where func_multi_like (media_name, 'Google, baidu, sina ')> 0 www.2cto.com, that is, if media_name like google, like baidu, or like sina, a value greater than 0 is returned. Note: here is like, not =. If it is =, use IN.

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.