在我的查询中,我使用REPLACE( b.DESCRIPTION,'SP. Z O.O.','') AS DESCRIPTION
从列中删除SP. Z O.O.
这些字符。希望它对我有用。但是在我的数据库SP. Z O.O.
中,这些字符以不同的方式存储。与sp. Z.o.o
,SP. z.o.o
等相同。
在某处,它以大写字母存储,在某处以小写字母存储。
REPLACE( b.DESCRIPTION,'SP. Z O.O.','') AS DESCRIPTION
通过这种方法,我只能删除大写字母。我希望所有条件都删除这样的类似单词。
如何在这种情况下应用正则表达式或案例?
这是我的疑问:
SELECT b.TRANS_DETAILS_ID,b.CREDIT_AMOUNT,b.ENTITY_NAME,REPLACE(b.DESCRIPTION,'SP.Z OO','')作为说明,DATE_FORMAT(a.TRANSACTION_DATE_TIME,'%d-%m-%Y ')TRANS_DATE FROM bank_book_transaction_master a,bank_book_transaction_details b WHERE.TRANSACTION_DATE_TIME BETWEEN'2017-12-01'''2017-12-26'DEBIT_CREDIT_FLAG = 1 AND a.ORG_ID ='53'AND a.BANK_ID ='14' AND a.TRANSACTION_ID = b.TRANS_MASTER_ID
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以使用以下查询执行此操作:
UPDATE strtest
SET mystring = CONCAT(
LEFT (mystring, POSITION('SP. Z O.O.' IN mystring)-1),
RIGHT(mystring, LENGTH(mystring)-POSITION('SP. Z O.O.' IN mystring)-9)
)
WHERE mystring LIKE '%SP. Z O.O.%';
<强>示例:强>
测试表
MariaDB [bernd]> SELECT * from strtest;
+----+------------------+
| id | mystring |
+----+------------------+
| 1 | SP. Z O.O. |
| 2 | ABCSP. Z O.O. |
| 3 | SP. Z O.O.XYZ |
| 4 | QWESP. Z O.O.IOP |
| 5 | AAASp. Z o.O.LLL |
+----+------------------+
5 rows in set (0.00 sec)
删除SELECT中的字符串(&gt;&gt;&gt;&lt;&lt;&lt;&lt;仅用于测试)
MariaDB [bernd]> SELECT CONCAT( '>>>',
-> LEFT (mystring, POSITION('SP. Z O.O.' IN mystring)-1),
-> RIGHT(mystring, LENGTH(mystring)-POSITION('SP. Z O.O.' IN mystring)-9),
-> '<<<') AS resultstring
-> FROM strtest;
+--------------+
| resultstring |
+--------------+
| >>><<< |
| >>>ABC<<< |
| >>>XYZ<<< |
| >>>QWEIOP<<< |
| >>>AAALLL<<< |
+--------------+
5 rows in set (0.00 sec)
更新表
MariaDB [bernd]> UPDATE strtest
-> SET mystring = CONCAT(
-> LEFT (mystring, POSITION('SP. Z O.O.' IN mystring)-1),
-> RIGHT(mystring, LENGTH(mystring)-POSITION('SP. Z O.O.' IN mystring)-9)
-> )
-> WHERE mystring LIKE '%SP. Z O.O.%';
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0
MariaDB [bernd]> SELECT * from strtest;
+----+----------+
| id | mystring |
+----+----------+
| 1 | |
| 2 | ABC |
| 3 | XYZ |
| 4 | QWEIOP |
| 5 | AAALLL |
+----+----------+
5 rows in set (0.00 sec)
MariaDB [bernd]>