Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 用作执行其他查询的数组的Oracle数据库表_Sql_Loops_Oracle10g - Fatal编程技术网

Sql 用作执行其他查询的数组的Oracle数据库表

Sql 用作执行其他查询的数组的Oracle数据库表,sql,loops,oracle10g,Sql,Loops,Oracle10g,我在书籍和网络上搜索了几个小时,却找不到任何真正的运气。因为Oracle或PL/SQL并不是我一生中最伟大的礼物,我想我应该这样做 我想要实现的是选择表A中的所有记录,并在循环中使用“每个”记录 在伪代码中,应该是这样的 x=从表A中选择*; 每x 更新表_B,其中kitten=x; 循环结束 帮助?使用光标: DECLARE cursor c1 is select monthly_income from employees where name = v_name_in; BE

我在书籍和网络上搜索了几个小时,却找不到任何真正的运气。因为Oracle或PL/SQL并不是我一生中最伟大的礼物,我想我应该这样做

我想要实现的是选择表A中的所有记录,并在循环中使用“每个”记录

在伪代码中,应该是这样的

x=从表A中选择*; 每x 更新表_B,其中kitten=x; 循环结束

帮助?

使用光标:

DECLARE
cursor c1 is
   select monthly_income
   from employees
   where name = v_name_in;
BEGIN
    FOR employee_rec in c1
    LOOP
         update tableB set incom_val = employee_rec.monthly_income where ...;
    END LOOP;
END;
或:

 DECLARE
    BEGIN
        FOR employee_rec in (select monthly_income
                                from employees
                                where name = v_name_in)
        LOOP
             update tableB set incom_val = employee_rec.monthly_income where ...;
        END LOOP;
    END;
使用光标:

DECLARE
cursor c1 is
   select monthly_income
   from employees
   where name = v_name_in;
BEGIN
    FOR employee_rec in c1
    LOOP
         update tableB set incom_val = employee_rec.monthly_income where ...;
    END LOOP;
END;
或:

 DECLARE
    BEGIN
        FOR employee_rec in (select monthly_income
                                from employees
                                where name = v_name_in)
        LOOP
             update tableB set incom_val = employee_rec.monthly_income where ...;
        END LOOP;
    END;

如果可能,尝试将其作为单个UPDATE语句编写

update table_b b
   set (b.col1, b.col2) = (
          select a.colx + 10, a.coly / 18
            from table_a a
           where b.id = a.id);

它比过程中的对应项更快,代码行也更少,因此更易于理解和迁移到其他数据库。

如果可能,尝试将其作为单个UPDATE语句编写

update table_b b
   set (b.col1, b.col2) = (
          select a.colx + 10, a.coly / 18
            from table_a a
           where b.id = a.id);
它比过程中的对应程序更快,而且代码行也更少,因此更易于理解和迁移到其他数据库