Three Common Oracle functions TRIM, TRUNC, and DECODE

Source: Internet
Author: User
Today, I met Oracle's TRIM, TRUNC, and DECODE functions. I will record my experiences for future reference.

Today, I met Oracle's TRIM, TRUNC, and DECODE functions. I will record my experiences for future reference.

Today, I met Oracle's TRIM, TRUNC, and DECODE functions. I will record my experiences for future reference.

1. TRIM function: used to remove spaces at the beginning and end of a string line.

Select trim ('yichangzyh') "TRIM e.g ."
FROM dual;

TRIM e.g.
YICHANGzyh

2. TRUNC function: truncation function.

SELECT trunc (sysdate) "truncated to the current day ",
Trunc (sysdate, 'Year') "trunc (sysdate, 'Year ",
Trunc (sysdate, 'month') "trunc (sysdate, 'month ",
Trunc (sysdate, 'day') "intercepts to the first day of the week ",
Trunc (sysdate, 'hh24') "truncated to hour (0 minutes 0 seconds )",
Trunc (sysdate, 'mi') "truncated to minute (0 s )"
FROM dual;

Truncate to the day, intercept to the first day of the year, intercept to the first day of the month, intercept to the first day of the week, intercept to the hour (0 minutes 0 seconds), intercept to the minute (0 seconds)
, 17:00:00

3. DECODE function: Condition judgment.

Decode (condition, value 1, return value 1, value 2, return value 2,... value n, return value n, default value)

The function has the following meanings:

IF condition = value 1 THEN
RETURN (translation value 1)
ELSIF condition = value 2 THEN
RETURN (translation value 2)
......
ELSIF condition = value n THEN
RETURN (translation value n)
ELSE
RETURN (default)
END IF

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.