Oracle substr () and SUBSTRB () ____oracle

Source: Internet
Author: User
Tags oracle substr

has been used substr () to intercept a part of the string, although know that there are SUBSTRB (), but did not use, also do not understand where to use them, today just test the two functions, do some summary:

Let's start by introducing the two functions

Function Name Description

SUBSTR (C1, N1) from the starting position specified in the string to get the following string

SUBSTRB (C1, N1)

SUBSTR (C1, N1, N2) A string that obtains the specified number of characters from the starting position specified in the string

SUBSTRB (c1, n1,n2) gets a string of the specified number of bytes from the start position specified in the string

The "argument" C1 is a string, N1 is the starting position, and N2 is the number of characters/sections

From the above you can see that the difference between substr () and SUBSTRB () is that substr () is the number of characters to get the string, SUBSTRB () is the number of bytes to get the string.

For example:

1 Get string "It's a nice day," the 3rd character begins with a string

Select substr (' The weather is very good today ', 3) from dual;

The result of the output is: The weather is very good

2 Get String "Today is a nice day," the 3rd byte begins with a string

Select SUBSTRB (' The weather is very good today ', 3) from dual;

The result of the output is: It's a nice day.

3 Get the string "Today is a nice day", the 3rd character begins with a 2 character string

Select substr (' The weather is very good today ', 3,2) from dual;

The result of the output is: weather

4 Get the string "Today is a nice day", the 3rd byte begins with a 2-byte string

Select SUBSTRB (' The weather is very good today ', 3,2) from dual;

The output is: Day

Note: When the start position is set to a negative number, it is retrieved from the end of the string.

Similar to these two functions are:
Length and LENGTHB calculation function

Select Length (' Weather ') from dual;

Output: 2

Select LENGTHB (' Hello ') from dual;

Output: 4

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.