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?
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.
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 .
MySQL Shell can print results in table, tabbed, or vertical format, or as pretty or raw JSON output.
The FIND_IN_SET() function returns the position of a string within a list of strings.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With