Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output a MySQL formatted string

Tags:

mysql

Suppose I have a query likes:

SELECT name FROM product WHERE id = 28;

The result is "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?

like image 808
Charles Yeung Avatar asked Sep 06 '11 04:09

Charles Yeung


People also ask

How do I get output from MySQL?

Save MySQL Results to a File There's a built-in MySQL output to file feature as part of the SELECT statement. We simply add the words INTO OUTFILE, followed by a filename, to the end of the SELECT statement. For example: SELECT id, first_name, last_name FROM customer INTO OUTFILE '/temp/myoutput.

How do I print vertically in MySQL?

Vertical format is more readable where longer text lines are part of the output. To get this output format, start MySQL Shell with the --result-format=vertical command line option (or its alias --vertical ), or set the MySQL Shell configuration option resultFormat to vertical .

Does MySQL have print?

MySQL Shell can print results in table, tabbed, or vertical format, or as pretty or raw JSON output.

What is Find_in_set in MySQL?

The FIND_IN_SET() function returns the position of a string within a list of strings.


1 Answers

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 image 160
paxdiablo Avatar answered Nov 15 '22 10:11

paxdiablo