当前位置:网站首页>Replace() function
Replace() function
2022-07-04 10:57:00 【ths512】
grammar
REPLACE ( string_expression , string_pattern , string_replacement )
Parameters
string_expression String expression to search .string_expression It can be character or binary data type .
string_pattern Is the substring to find .string_pattern It can be character or binary data type .string_pattern It cannot be an empty string ('').
string_replacement Replace string .string_replacement It can be character or binary data type .
Return type
If the data type of one of the input parameters is nvarchar, Then return to nvarchar; otherwise REPLACE return varchar.
If any parameter is NULL, Then return to NULL.
It's all Mandarin , Not easy to understand ! Turn into vernacular :
REPLACE(String,from_str,to_str) namely : take String All of the from_str Replace with to_str.
One 、 Prepare the experimental environment
1.1 Create table :
CREATE TABLE `test_tb` (
`id` int(10) unsigned NOT NULL auto_increment COMMENT ' The primary key increases automatically ',
`name` char(30) default NULL COMMENT ' full name ',
`address` char(60) default NULL COMMENT ' Address ',
`country` char(200) default NULL COMMENT ' Country ',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=' The test table '
1.2 insert data :
insert into test_tb(name,address,country) values
('zhangsan',' Beijing Chaoyang District ',' China '),
('lisi',' Shanghai Pudong district ',' China '),
('wangwu',' Zhengzhou Jinshui District ',' China '),
('zhaoliu',' Kowloon, Hong Kong ',' Hong Kong, China, '),
('Q7',' California beef ',' The United States '),
('wangba',' New Kyushu Island ',' Japan ')
Two 、 Search for replacement
2.1 take address In the field “ District ” Replace with “ Vomit ” Show , as follows
select *,replace(address,' District ',' Vomit ') AS rep from test_tb
2.2 take address In the field “ Nine ” Replace with “ Ten ” Show , as follows
select *,replace(address,' Nine ',' Ten ') AS rep from test_tb where id in (4,6)
summary :
I think I mentioned earlier Use IF(expr1,expr2,expr3) And CASE...WHEN...THEN...END The alias display of query results can be realized, but the difference is : These two are the alias display of the query result value as a whole , and replace You can replace and display the local string of the query result ( Output ).
3、 ... and 、 Update and replace
3.1 take address In the field “ In the east ” Replace with “ In the west ” , as follows
update test_tb set address=replace(address,' In the east ',' In the west ') where id=2
summary : Update and replace the local string in the field .
Four 、 Insert replace
4.1 take id=6 Of name The field value is changed to wokou
replace into test_tb VALUES(6,'wokou',' New Kyushu Island ',' Japan ')
summary : Go to the table “ Replace insert ” A piece of data , If there is no in the original table id=6 This data is inserted as new data ( amount to insert into effect ); If there is... In the original table id=6 This data is replaced ( amount to update effect ). For fields that are not specified, the default value is inserted .
边栏推荐
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
- Personal thoughts on the development of game automation protocol testing tool
- [Galaxy Kirin V10] [desktop] can't be started or the screen is black
- Advanced order of function
- [untitled]
- Function introduction of canbedded component
- Basic function exercises
- Oracle11g | getting started with database. It's enough to read this 10000 word analysis
- F12 clear the cookies of the corresponding web address
猜你喜欢
Quick sort (C language)
Add t more space to your computer (no need to add hard disk)
Introduction to tree and binary tree
Elevator dispatching (pairing project) ③
Seven examples to understand the storage rules of shaped data on each bit
Software sharing: the best PDF document conversion tool and PDF Suite Enterprise version sharing | with sharing
Deepmind proposed a Zuan AI, which specially outputs network attack language
[Galaxy Kirin V10] [server] system partition expansion
Huge number (C language)
C language structure to realize simple address book
随机推荐
iptables导致Heartbeat脑裂
JMeter correlation technology
[testing theory] thinking about testing profession
Write a program to judge whether the two arrays are equal, and then write a similar program to compare the two vectors.
Performance features focus & JMeter & LoadRunner advantages and disadvantages
[machine] [server] Taishan 200
[Galaxy Kirin V10] [server] NFS setup
Dictionaries and collections
Basic function exercises
Personal thoughts on the development of game automation protocol testing tool
Installation of ES plug-in in Google browser
Const's constant member function after the function; Form, characteristics and use of inline function
DNS hijacking
The last month before a game goes online
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
VI text editor and user rights management, group management and time management
For and while loops
Canoe - the third simulation project - bus simulation-1 overview
Student achievement management system (C language)
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology