MYSQL如何替换部分字符串
2个回答
展开全部
mysql>
select
host,user
from
user
where
user='user';
+-----------------------+----------+
|
host
|
user
|
+-----------------------+----------+
|
localhost.localdomain
|
testuser
|
+-----------------------+----------+
update字段host的内容,把"main"改成"slave",用REPLACE
mysql>
update
user
set
host=REPLACE(host,'main','slave')
where
user='user';
Query
OK,
1
row
affected
(0.00
sec)
Rows
matched:
1
Changed:
1
Warnings:
0
mysql>
select
host,user
from
user
where
user='user';
+------------------------+----------+
|
host
|
user
|
+------------------------+----------+
|
localhost.localdoslave
|
testuser
|
+------------------------+----------+
select
host,user
from
user
where
user='user';
+-----------------------+----------+
|
host
|
user
|
+-----------------------+----------+
|
localhost.localdomain
|
testuser
|
+-----------------------+----------+
update字段host的内容,把"main"改成"slave",用REPLACE
mysql>
update
user
set
host=REPLACE(host,'main','slave')
where
user='user';
Query
OK,
1
row
affected
(0.00
sec)
Rows
matched:
1
Changed:
1
Warnings:
0
mysql>
select
host,user
from
user
where
user='user';
+------------------------+----------+
|
host
|
user
|
+------------------------+----------+
|
localhost.localdoslave
|
testuser
|
+------------------------+----------+
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
找了半天也没有找到可以实现这个功能的函数,
最后解决办法是:导入数据表,用awk处理里,再插入一个新表(数据结构一样)
mysql>select
*
from
表1
INTO
OUTFILE
'b.txt';
awk
-F'/'
'{print
$1"/"$2}'
b.txt
>a.txt
mysql>create
table
表2
like表1;
mysql>load
data
infile
'a.txt'
into
table
表2;
同时也坐着用函数或其它巧妙的办法来解决。
最后解决办法是:导入数据表,用awk处理里,再插入一个新表(数据结构一样)
mysql>select
*
from
表1
INTO
OUTFILE
'b.txt';
awk
-F'/'
$1"/"$2}'
b.txt
>a.txt
mysql>create
table
表2
like表1;
mysql>load
data
infile
'a.txt'
into
table
表2;
同时也坐着用函数或其它巧妙的办法来解决。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询