我在SQL
/ ORACLE
/ INFORMIX
中有此列表,其中包含以下列:
Table: Lot
Columns: Id, Status and ProcessList
所以,我的列ProcessList存储一个这样的varchar:
(1,2,3,7,12)
我需要通过像这样的伪示例这样的独特过程从Lot
表中删除记录:
Delete from Lot where ProcessList contains process 7
我怎么能这样做?
答案 0 :(得分:2)
如果您绝对无法更改架构(这是更可取的),这应该有效:
DELETE FROM Lot
WHERE ProcessList LIKE '%,7,%' -- number is in middle of list
OR ProcessList LIKE '%,7)' -- number is at the end of a list
OR ProcessList LIKE '(7,%' -- number is at the start of the list
OR ProcessList LIKE '(7)' -- number is the only item in the list
答案 1 :(得分:1)
尝试
delete from Lot where
ProcessList like '(7,%' or
ProcessList like '%,7)' or
ProcessList like '%,7,%' or
ProcessList = '(7)';
查询假设process_id
和逗号之间没有空格,process_id
和右括号之间没有空格。而且,ProcessList
是一个文本字段:)
如您所见,在添加所有可能的案例时,查询变得不容易阅读。你想重新考虑存储这样的值(如评论中所建议的那样),因为真的难以使用这样的字符串。