0

我的要求有点不同。我有两个嵌套的 FOR 循环来获取数据并根据特定条件将排序的数据插入表中。

原代码如下:

FOR Name_1 IN First_Cursor
LOOP
  FOR Name_2 IN Second_Cursor (Name_1.Table_Field_Name)
  LOOP
    IF (Condition)
      THEN
        Prevalidation of data

        INSERT INTO <Table_Name>
          VALUES (..............................);
      ELSE
        IF (Condition)
        THEN
          Prevalidation of data

          UPDATE <Table_Name>
            WHERE .....................;

      END IF;
    END IF;
  END LOOP;
END LOOP;

我必须将整个代码转换为 FORALL

我尝试了很多代码,但都成功了,我认为语法本身是错误的

IF (Condition)
THEN
  Prevalidation of data

  FORALL Name_2 IN Second_Cursor (Name_1.Table_Field_Name) of Name_1
    INSERT INTO <Table_Name>
      VALUES (..............................);
ELSE
  IF (Condition)
  THEN
    Prevalidation of data
    FORALL Name_2 IN Second_Cursor (Name_1.Table_Field_Name) of Name_1
      UPDATE <Table_Name>
        WHERE .....................;    
  END IF;
END IF;
4

1 回答 1

0

请在 sql 中使用“case”语句,如下所示:

句法:

CASE [ expression ]

   WHEN condition_1 THEN result_1
   WHEN condition_2 THEN result_2
   ...
   WHEN condition_n THEN result_n

   ELSE result

END

SQL:

 select column1,column2,
    ( case when col3>0 then col4 else col5 end) as 'col_name' ,
    ( case when col6='value' then col7 else col8 end) as 'col_name1' 
    from 
    table_name
    where col_name13>45
于 2014-02-27T11:30:56.603 回答