I've read how to perform a find-replace in mysql,
UPDATE `table_name`
SET `field_name` = replace(same_field_name, 'unwanted_text', 'wanted_text')
but i'm stuck with a particular string (my unwanted_text), that is
<span style="font-size: 12pt;">
In order to prevent any unwanted result, i'm testing my query just finding the previous string.
I've tried to escape double quotes with \" and even blank spaces with \ but it doesn't work.
<span\ style=\"font-size:\ 12pt;\">
How should be unwanted_text?
Solved. It was Phpmyadmin through its search function converting: it was adding another \.
Through direct sql input everything works fine.
Related
I have a series of mysql scripts that run from a shell script. One of the queries includes
Select * from Table where FieldX Regex 'XYZ$'
in other words 'ends with XYZ'. However this is breaking the script. If I remove the $ or make it literal \$ it works but neither serves my purpose. Is there an altnerative character I can use that Regexp will understand as 'end of line' and Shell Script won't object to?
Since you're using single quotes to delimit the shell string, you need to use double quotes to delimit MySQL strings inside it.
'and FieldX Regex "XYZ$"
This failed in Java 13 (JDBC) code so I went to MySQL Workbench to duplicate problem.
I run a simple query as:
START TRANSACTION;
SET SESSION sql_mode = NO_BACKSLASH_ESCAPES;
SELECT *, "x\\x", "y\y" from dirs
WHERE d_pathname like 'E:\\\\BOOKS\\\\Dictionaries_and_Encyclopedias\\\\%' ORDER BY d_pathname;
and I get 400 rows returned. The issue is, that I do not want to use double-backslashes.
Rows returned show a single backslash, not a double backslash.
Interestingly, the x\\x and y\y clauses appear just as represented in the SELECT statement.
When I remove the double backslashes in the LIKE clause, I get zero rows!
Why? I'd rather not have to double-up the backslashes, and run simple and clean code.
The NO_BACKSLASH_ESCAPES mode only affects how backslashes are treated in ordinary string literals. It doesn't change how they're processed in LIKE patterns.
However, you can use the ESCAPE option to specify a different character to use as the escape character in LIKE. Just use some other character that doesn't appear in your pattern.
WHERE d_pathname like 'E:\BOOKS\Dictionaries_and_Encyclopedias\%' ESCAPE '|'
I want to remove special characters from a MySQL table but LEAVE UTF8 characters such as arabic.
This is to remove common special characters such as " ' # ! * $ etc.
I have used the following in PHP which works great.
preg_replace('/(?=\P{Nd})\P{L}/u', '', $name);
You can UPDATE your rows using the very same regular expression for comparison.
The string regular expression operators in MySQL are REGEXP or RLIKE.
I hope, this should solve your problem. :)
I'm working in development mode with an H2 in memory database, but I'd like it to behave as much as possible like a mysql database (see http://www.h2database.com/html/features.html#compatibility)
this is my configuration in application.conf file:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play;MODE=MYSQL;DB_CLOSE_DELAY=-1"
to test it I just run "play" and from play's console I issue "h2-browser" and in the url jdbc field I enter "jdbc:h2:mem:play;MODE=MYSQL;DB_CLOSE_DELAY=-1"
the following statements work ok in mysql:
CREATE TABLE `tmp` (
`name` varchar(50) NOT NULL
);
insert into tmp (name) values ('slash: \\, simple quotes \', double quotes \" -');
select * from tmp;
but in the h2 console I get an error, and the only character I can escape is the single quotes, just by preceding it with another single quote. (Also tried entering 'SET MODE MySQL;')
Is there some way to have h2 behave like mysql from play's framework h2-browser? or is it just a limitation of h2?
The link you provided, http://www.h2database.com/html/features.html#compatibility, documents the exact compatibility features H2 supports. Things that are not documented are not supported. In this case it seems the problem is the 'backslash' escaping within a String literal:
'slash: \\, simple quotes \', double quotes \" -'
The backslash is not an escape character for ANSI SQL; to escape a single quote you need to use two single quotes. The problem is this might not work for MySQL as the single backslash is still an escape character:
'slash: \, simple quotes '', double quotes " -'
For this problem, a solution is to use the ANSI mode for MySQL, another solution is to always use bind variables for String literals (PreparedStatement within JDBC).
I'm not exactly sure what happened because I migrated from One server to another of the same spec and SQL...
Still in comments and titles the new database shows the characters ' instead of '
and I was wondering if I could ask for help in either replacing ' with '
or if it was simpler just deleting '
Thanks so much...
Steff
You could use MySQL's REPLACE method (look here):
UPDATE
Changed the statement to reflect the OP's naming:
UPDATE database1.vb_ppgal_albums
SET pp_photos = REPLACE(pp_photos, ''', '\'')
Good luck.
The following is the coding that I use to update double-quote in MySQL. I use the REPLACE function. The first parameter is the field_name that I want to have searched, the second is the escaping of the double quote (\") as the search string, followed by escaping of the escape character (\) followed by the double quote, which will insert into the field name (\"). In the table I will now have a measurement of '1/2\"' instead of '1/2"', which was my goal. I hope this helps. (PS, the Where clause is for show, you may not need it.)
UPDATE `table_name`
SET
`field_name` = REPLACE(`field_name`, '\"', '\\"')
WHERE `Id` > 125