我们如何从 pl-sql 集合中获取元素的索引号?

How can we get the index number of an element from pl-sql collection?

我从table插入了一些数据记录到集合类型table,然后我想从集合中删除一些不满足条件的记录。

尽管从 pl-sql 集合中删除记录的唯一选项是使用 DELETE 方法,但我该怎么做?

我不确定这个确切的语法是否适合您的数据库,但您可以使用子查询 select 满足您条件的项目的 ID。

DELETE FROM "Table"
  WHERE "Table"."ID" IN (( -- notice double parentheses
      SELECT "ID" -- this subquery returns the IDs for the rows you want to delete
        FROM "Table" -- which are then tested in the IN () statement
        WHERE "Table"."ConditionField" = 'Condition Satisfied'
    ))

假设您有一个名为 myCollection 的关联数组,由 binary_integer 索引,它应该如下所示:

DECLARE
   i BINARY_INTEGER;
BEGIN
   i := myCollection.FIRST;
   WHILE (i IS NOT NULL) LOOP
      IF (myCollection(i) ...) THEN
         myCollection.DELETE(i);
      END IF;
      i := myCollection.NEXT(i);
   END LOOP;
END;
/