当前位置:网站首页>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 .
边栏推荐
- unit testing
- [advantages and disadvantages of outsourcing software development in 2022]
- Solaris 10网络服务
- [Galaxy Kirin V10] [desktop and server] FRP intranet penetration
- Elevator dispatching (pairing project) ②
- Using Lua to realize 99 multiplication table
- Fundamentals of database operation
- Canoe - the third simulation project - bus simulation-1 overview
- Introduction to canoe automatic test system
- Software sharing: the best PDF document conversion tool and PDF Suite Enterprise version sharing | with sharing
猜你喜欢
JMeter common configuration components and parameterization
JMeter Foundation
Ten key performance indicators of software applications
Function introduction of canbedded component
JMeter correlation technology
Hidden C2 tunnel -- use of icmpsh of ICMP
Canoe - the second simulation project -xvihicle1 bus database design (operation)
Discussion | has large AI become autonomous? Lecun, chief scientist of openai
Seven examples to understand the storage rules of shaped data on each bit
Appscan installation error: unable to install from Net runtime security policy logout appscan solution
随机推荐
[testing theory] thinking about testing profession
[Galaxy Kirin V10] [server] KVM create Bridge
Introduction to canoe automatic test system
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
[Galaxy Kirin V10] [server] system partition expansion
/*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/
PHP programming language (1) - operators
Performance test overview
Learning XML DOM -- a typical model for parsing XML documents
Student achievement management system (C language)
Day06 list job
Summary of automated testing framework
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
Ten key performance indicators of software applications
Discussion | has large AI become autonomous? Lecun, chief scientist of openai
Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)
[Galaxy Kirin V10] [desktop] printer
[Galaxy Kirin V10] [server] NFS setup
Const's constant member function after the function; Form, characteristics and use of inline function