Oracle DB:How 我们可以在 table 中编写插入记录的查询,如果记录已经存在则不插入记录,否则插入记录

Oracle DB:How we can write Query for insert record in the table if records already exist then record is not inserted otherwise record inserted

我们如何在 table 中编写插入记录的查询,如果记录已经存在,则不插入记录,否则插入记录。

如何将其转换成SQL查询。 select 相同的 table 并插入相同的 table 如果记录不存在。

//SQL Sudo Code Like This:
IF ("select count(*) from table_name where name = ? and status = ? and salary = ?"==0):
       // if this is true then we use insert statement.
       INSERT INTO table_name(col1,col2,col3,col4) values(?,?,?,?);

您可以按如下方式使用NOT EXISTS

INSERT INTO TABLE_NAME (COL1,COL2,COL3,COL4)
    SELECT ?,
           ?,
           ?,
           ?
      FROM DUAL
     WHERE NOT EXISTS (
        SELECT 1
          FROM TABLE_NAME
         WHERE NAME = ?
           AND STATUS = ?
           AND SALARY = ?
    )