Query with foward-slash (/) in a string

245
February 15, 2017, at 11:16 PM

in MySql database I'm trying to run a query to replace a string (text type) containing a slash (/). eg: abc/xyz

first I tried to select:

select id,params FROM  mytable WHERE params LIKE '%abc/xyz%' AND alias ='myalias';

then I tried to replace directly

UPDATE mytable SET params = REPLACE(params,'abc/xyz','abc & xyz') WHERE alias ='myalias';

but both querys returns 0 results.

Any suggestions?

Thank's

Answer 1
select REPLACE('string abc/xyz', 'abc/xyz','abc & xyz');
+--------------------------------------------------+
| REPLACE('string abc/xyz', 'abc/xyz','abc & xyz') |
+--------------------------------------------------+
| string abc & xyz                                 |
+--------------------------------------------------+

It mean that replace clause works perfectly, but if you receive 0 it mean that you don't have row wit params LIKE '%abc/xyz%' AND alias ='myalias', first query says exactly this.

Here my simple example:

cli [db]> create table simpleTest (id int key, params varchar(50) );
Query OK, 0 rows affected (0.00 sec)
cli [db]> insert into simpleTest values
    -> (1, 'params test abc/xyz 1'),
    -> (2, 'params test abc/xyz 2'),
    -> (3, 'params test abc/xyz 3');
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0
cli [db]> select * from simpleTest;
+----+-----------------------+
| id | params                |
+----+-----------------------+
|  1 | params test abc/xyz 1 |
|  2 | params test abc/xyz 2 |
|  3 | params test abc/xyz 3 |
+----+-----------------------+
3 rows in set (0.00 sec)
cli [db]> update simpleTest set params = replace(params, 'abc/xyz', 'abc & xyz');
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
cli [db]> select * from simpleTest;
+----+-------------------------+
| id | params                  |
+----+-------------------------+
|  1 | params test abc & xyz 1 |
|  2 | params test abc & xyz 2 |
|  3 | params test abc & xyz 3 |
+----+-------------------------+
3 rows in set (0.00 sec)

and it works for me...

READ ALSO
Full join two querys

Full join two querys

This query returned 385 strings

254
Nested queries and Join

Nested queries and Join

As a beginner with SQL, I’m ok to do simple tasks but I’m struggling right now with multiple nested queriesMy problem is that I have 3 tables like this:

282
How to build a stable system for processing 90 millions of rows & transffering into live server every day?

How to build a stable system for processing 90 millions of rows & transffering into live server every day?

I have an employee rewarding & tracking system for a companyThe company I am developing a system for, providing me sales data with FTP every day

202
Php login password_verify

Php login password_verify

I am learning how to use prepared statements and I thought I would try out a login system (simple) using the password_hash() and password_verify() functionsI have succesffuly inserted data in using prepared statemernts, now I wish to verify the password...

335