我需要自动删除的存储过程,每次在表paym
中的列table1
和table2
都不为空。
下表中的示例:
表格:paym
ID username table1 Table2
+-------+-------------+-------------+-----------+
| 1 | John | Value | Value |
+-------+-------------+-------------+-----------+
| 2 | Alex | Null | Null |
+-------+-------------+-------------+-----------+
条件为true:删除后的行:
ID username table1 Table2
+-------+-------------+-------------+-----------+
| 2 | Alex | Null | Null |
+-------+-------------+-------------+-----------+
我的尝试是(不起作用)
CREATE PROCEDURE DeleteRow
BEGIN
DELETE
FROM
paym WHERE table1 and table2 IS NOT NULL ;
END;
答案 0 :(得分:2)
您的逻辑在这里,但是语法错误。
在WHERE子句的每个字段之后,您必须指定一个条件,如下所示:
CREATE PROCEDURE DeleteRow
BEGIN
DELETE
FROM
paym WHERE table1 IS NOT NULL AND table2 IS NOT NULL ;
END;
答案 1 :(得分:2)
如果您希望检查多列CONCAT
NULL
作为黑客
CREATE PROCEDURE DeleteRow
BEGIN
DELETE
FROM
paym WHERE CONCAT(table1,table2) IS NOT NULL;
END;
答案 2 :(得分:1)
CREATE PROCEDURE DeleteRow
BEGIN
DELETE
FROM
paym WHERE table1 IS NOT NULL AND table2 IS NOT NULL ;
END;
答案 3 :(得分:0)
代码应读取table不为null且table 2不为null,因为您需要在and语句后加上一个条件。