Oracle uses the instr or like method to determine whether the string is contained. oracleinstr

Source: Internet
Author: User

Oracle uses the instr or like method to determine whether the string is contained. oracleinstr

The first thought is contains. The usage of contains is as follows:

select * from students where contains(address, 'beijing')

However, a condition for using the ins predicate is that the column must be indexed. That is to say, if the address column of the students table in the preceding statement is not indexed, an error is returned.

Fortunately, there is another way to use instr. The usage of instr is as follows:

select * from students where instr(address, 'beijing') > 0

In addition, there is a stupid way, that is, to use like. Here we should know how to do it:

select * from students where address like '%beijing%'

Oracle determines whether the character is in the string

INSTR (C1, C2, I, J)
Searches for a specified character in a string and returns the location where the specified character is found;
String searched by C1
String to be searched by C2
The start position of the I search. The default value is 1.
Where J appears. The default value is 1.
SQL> select instr ('oracle traning', 'A', 1, 2) instring from dual; INSTRING
---------
9. You can determine if instr ('123', lx, 1356)> 0 then ...... else ...... end if;

In oracle, how does one determine whether a character exists in a string?

Declare aa varchar2: = 'wkressdfdf ';
Begin
If instr (aa,'s ')> 0 then
Dbms_output.put_line ('s character ');
Else
Dbms_output.put_line ('no s character ');
End if;
End;

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.