【问题标题】:Multiple cursors in the same for loop同一个for循环中的多个游标
【发布时间】:2012-08-28 17:13:26
【问题描述】:

我有一个关于使用光标的问题。

Table t1 having "t1c1" and "t1c2" columns.

Table t2 having "t2c2" and "t2c2" columns.

Table t3 having "t3c2","t3c2","t3c3","t3c4" columns.

Two cursors "cur1" and "cur2".

我编写了需要使用光标“cur1”的for循环将值插入t3的代码

例子:

DECLARE

CURSOR cur1 IS
SELECT t1c1 FROM t1;

CURSOR cur2 IS
SELECT t2c1 FROM t2;

BEGIN

FOR f1 IN cur1 LOOP

EXIT WHEN cur1%NOTFOUND;

INSERT INTO TABLE t3
(
  SELECT f1.t1c1,t2.t2c2,'hello' FROM t2;
);

END LOOP;

从上面的代码中,我插入了表 t3 的第一三列。

我想知道如何将 cur2(光标值)插入表 t3 的第 4 列。

【问题讨论】:

  • 问题标记为oraclemysql:您使用的是哪个?为什么不使用INSERT ... SELECTMySQL 的文档)在表之间进行适当的连接?

标签: mysql oracle oracle10g oracle11g


【解决方案1】:
insert into t3
select t1.t1c1, t2.t2c2, 'Hello'
from t1,
     t2

对我来说真正奇怪的是,你没有提到 t1 和 t3 之间的任何链接,所以你得到了cartezian。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 2023-03-04
    • 2012-04-14
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    相关资源
    最近更新 更多