且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将减号查询(varchars 列表)的结果存储在 Oracle PL/SQL 中的变量中

更新时间:2022-12-03 18:42:18

不幸的是,将缺失的 ID 放入 table_two 的两种最自然的方法(多行 INSERT>MERGE) 支持 RETURNING.. BULK COLLECT INTO 子句.

Unfortunately, neither of the two most natural ways to get the missing IDs into table_two (a multi-row INSERT or a MERGE) support the RETURNING.. BULK COLLECT INTO clause.

所以,我认为***的办法是首先获取 id 列表,然后使用该列表来维护 table_two.

So, I think your best bet is to get the list of ids first and then use that list to maintain table_two.

像这样:

DECLARE 
  l_missing_id_list SYS.ODCINUMBERLIST;
BEGIN
  SELECT project_id
  BULK COLLECT INTO l_missing_id_list
  FROM 
    (
    SELECT t1.project_id FROM table_one t1
    MINUS
    SELECT t2.project_id FROM table_two t2 );
    
  FORALL i IN l_missing_id_list.FIRST..l_missing_id_list.LAST
    INSERT INTO table_two VALUES ( l_missing_id_list(i) );
    
  COMMIT;
  
  -- Values are now inserted and you have the list of IDs in l_missing_id_list to add to your email.
END;

这是基本概念.据推测,您在 TABLE_TWO 中有更多的列,而不仅仅是 id,因此您必须添加这些列.

That's the basic concept. Presumably you have more columns in TABLE_TWO than just the id, so you'll have to add those.