Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQL character operation

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

-- ltrim (string) the first character clears select 'OK' + ltrim (' left and right') + 'OK'-- rtrim (string) the last character clears select' OK' + rtrim ('left and right') + 'OK'-- replace (string,' looks for characters in string' from the space count to the left) 'replace found characters') select 'OK' + replace (' left and right', 'left', 'replace') + 'OK'-- Left (string, positive integer) returns the specified number of characters in the string starting from the left. Select left ('ABCDEF',3)-- ABC-- Right (string, positive integer) returns the number of characters select Right (' ABCDEF',3)-- DEF-- Len (string) starting at the right of the string, without trailing spaces. Select LEN ('123456789')-- 9 select LEN (' 123456789')-- 9 select LEN ('123456789')-- 12 select LEN (' 123456789')-- 12-- Lower ('uppercase letters') converts uppercase character data to lowercase character data and returns a character expression. Select Lower ('AB')-- ab--Upper (' lowercase letters') returns a character expression that converts lowercase character data to uppercase. Select Upper ('abc')-ABC-- defines the string type declare @ _ char char (15) =' ABCDEF', @ _ nchar nchar (15) = 'who I am and what I do', @ _ varchar varchar (15) = 'ABCDEF', @ _ nvarchar nvarchar (15) =' who I am and what I do 'select replace (@ _ char,'' '*') as' char'-- ABCDEF*, replace (@ _ nchar,'','*') as' nchar'-- who I am, what to do *, replace (@ _ nvarchar,'','*') as' nvarchar'-- who I am, what to do, replace (@ _ varchar,'') '*') as' varchar'-- ABCDEF-- returns the starting position of the first occurrence of a pattern in the specified expression Returns zero if the pattern is not found in all valid text and character data types. Select patindex ('% abb%','abcaabbeeabb')-- returns 5select patindex ('abb%','abcaabbeeabb')-- returns 0select patindex ('% abb','abcaabbeeabb')-- returns 10select patindex ('% abc%','abcaabbeeabb')-- returns 1-- Replicate to repeat the string value a specified number of times. Select Replicate ('ABC',2)-- ABCABC select Replicate (' ABC',0)-- Blank select Replicate ('ABC',-1)-- NULL-- Reverse returns the inverse of the string value. Select Reverse ('FEDBCA')-- ACBDEF-- Space () returns a string of repeating spaces. Select 'A'+space (10) +' A'- An A muri-converts a numeric type to a string of specified length / * the first parameter is the numeric value to be converted, and the second parameter is the total length after conversion (including decimal point, plus or minus sign). The third argument is decimal * /-- the decimal band rounding select'A string + STR (12345.633 # 8P0)-the A 12346--STUFF function inserts the string into another string. It removes the specified length of characters from the start position in the first string -- then insert the second string into the start position of the first string select Stuff ('ABCD',2,2,'123')-- A123D-- the string is the extracted character-- the second bit refers to the second bit B from the left-- the third bit refers to the extraction of 3 characters from B (' ABCDEF',2,3)-- BCD

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report