在PL / sql(oracle)中,如果行不存在,最简单的方法是INSERT?
我想要的东西:
IF NOT EXISTS (SELECT * FROM table WHERE name = 'jonny') THEN INSERT INTO table VALUES ("jonny",null); END IF;
但它不工作。
注意:此表有2个字段,例如名称和年龄。但只有名字是PK。
INSERT INTO table SELECT 'jonny',NULL FROM dual -- Not Oracle? No need for dual,drop that line WHERE NOT EXISTS (SELECT NULL -- canonical way,but you can select -- anything as EXISTS only checks existence FROM table WHERE name = 'jonny' )