Oracle character Functions

Source: Internet
Author: User

Oracle character Functions
1. String truncation select substr ('abcdef', 1, 3) from dual 2, find the sub-string position select instr ('abcfdgfdhd', 'fd ') from dual 3, string connection select 'hello' | 'Hello world' from dual; 4, 1) Remove the space in the string select ltrim ('abc') s1, rtrim ('zhang ') s2, trim ('zhang ') s3 from dual 2) Remove the leading and suffix select trim (leading 9 from 9998767999) s1, trim (trailing 9 from 9998767999) s2, trim (9 from 9998767999) s3 from dual; 5, returns the Ascii value of the first letter of the string select ascii ('A') fr Om dual 6, returns the ascii value corresponding to the letter select chr (97) from dual 7, calculates the string length select length ('abcdef ') from dual 8, initcap (uppercase first letter ), lower, upper select lower ('abc') s1, upper ('def') s2, initcap ('efg') s3 from dual; 9, replace select replace ('abc', 'B', 'xy') from dual; 10, translate select translate ('abc', 'B', 'xx') from dual; -- x is 1-bit 11, and decode [implements if .. then logic] Note: the first is the expression, and the last is the select deptno, decode (dept No, 10, '1', 20, '2', 30, '3', 'others') from dept; example: select seed, account_name, decode (seed, 111,1000, 111, 1000, 0) from t_userInfo // If seed is 200, take 2000; 111, take; other take 0 select seed, account_name, decode (sign (seed ), 1, 'Big seed',-1, 'Little seed', 'equal seed') from t_userInfo // If seed> 111, it is large; if it is 200, it is small; others are displayed as equal to 12. case [implements switch .. case Logic] select case X-FIELD WHEN X-FIELD <40 THEN 'x-FIELD less than 40' WHEN X-FIELD <50 THEN 'x-FIELD less than 50' WHEN X-FIELD <60 THEN 'x-FIELD less than 60' ELSE 'unbeknown 'end from dual Note: CASE statements are very flexible in dealing with similar issues. Decode is more concise to match a small number of values.

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.