Required SQL statements (7) string functions, time functions, and SQL statements

Source: Internet
Author: User

Required SQL statements (7) string functions, time functions, and SQL statements

String Functions
 
1. case-insensitive Conversion
-- Convert upper to uppercase
-- Lower to lowercase
Select upper ('asar ')
 
2. Length
-- Len words
-- Datalength bytes
 
3. Remove leading and trailing Spaces
-- Remove spaces on the Right of rtrim
-- Ltrim remove left space
 
4. String Truncation
-- Left ('string', 15) truncates 15 bytes from the Left
-- Right ('string', 15) truncates 15 bytes from the right
-- SubString ('string', 5, 5) captures 5 bytes starting from the left-side 5th bytes
 
5. String replacement
-- Replace ('you', 'you', 'I') to replace you with us
 
Time Functions
 
1. Get the current date
-- Getdate ()
 
2.100 days later
-- Dateadd (day, 100, getdate ())
 
3. Time Difference Function
-- Dateiff (year, '2014/1/11', getdate ())
 
4. query year, month, and day
-- Year (time) Get year
-- Month (time) Get month
-- Get day (time)
----------------
-- Calculate the number of people born in each year
Select year (birthday), count (*)
From table
Group by year ([birthday])
 
5. Obtain the year, month, day, hour, minute, and second of the date.
Datepart (year, date)
Datepart (month, date)
Datepart (day, date)
Datepart (hour, date)
Datepart (minute, date)
Datepart (second, date)

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.