当前位置:网站首页>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 .
边栏推荐
- regular expression
- Remove linked list elements
- Collection of practical string functions
- Strings and characters
- [Galaxy Kirin V10] [server] set time synchronization of intranet server
- [Galaxy Kirin V10] [server] grub default password
- Discussion | has large AI become autonomous? Lecun, chief scientist of openai
- Communication layer of csframework
- SSH原理和公钥认证
- shell awk
猜你喜欢

Canoe - the second simulation project -xvihicle1 bus database design (operation)

Open the neural network "black box"! Unveil the mystery of machine learning system with natural language

On binary tree (C language)
![[Galaxy Kirin V10] [server] NFS setup](/img/ed/bd7f1a1e4924a615cb143a680a2ac7.jpg)
[Galaxy Kirin V10] [server] NFS setup

C language - stack

Learning XML DOM -- a typical model for parsing XML documents

Huge number multiplication (C language)

F12 clear the cookies of the corresponding web address
![[Galaxy Kirin V10] [server] FTP introduction and common scenario construction](/img/ef/f0f722aaabdc2d98723cad63d520e0.jpg)
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction

Introduction to tree and binary tree
随机推荐
DCL statement of MySQL Foundation
How to quickly parse XML documents through C (in fact, other languages also have corresponding interfaces or libraries to call)
Write a program to judge whether the two arrays are equal, and then write a similar program to compare the two vectors.
Canoe test: two ways to create CAPL test module
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Fundamentals of database operation
Locust installation
How to use diff and patch to update the source code
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Summary of automated testing framework
Four characteristics and isolation levels of database transactions
Using Lua to realize 99 multiplication table
[Galaxy Kirin V10] [server] iSCSI deployment
2、 Operators and branches
Remove linked list elements
C language structure to realize simple address book
Introduction to tree and binary tree
Snake (C language)
Interview and lecture summary 1
CAPL: on sysVar_ Update difference on sysvar