开发者

Output a MySQL formatted string

开发者 https://www.devze.com 2023-04-02 10:05 出处:网络
Suppose I have a query likes: SELECT name FROM product WHERE id = 28; The result is 开发者_Go百科\"HTC Desire HD\"

Suppose I have a query likes:

SELECT name FROM product WHERE id = 28;

The result is 开发者_Go百科"HTC Desire HD"

I want this result to be replaced with XX in the string "I Like XX", after replacing, the string is "I Like HTC Desire HD"

Likes the PHP printf function, can I use MySQL to do that?


That would be:

select 'I Like ' || name from product where id = 28;

in regular SQL. I'm not entirely certain that will work in MySQL unless you have PIPES_AS_CONCAT configured, but the equivalent:

select CONCAT('I Like ', name) from product where id = 28;

should be fine.


Like a CONCAT()?

SELECT CONCAT('I Like ',name)
FROM   product
WHERE  id = 28;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号