PLSQL 变量
PLSQL Variables
我是编程新手,我想知道如何声明一个可以在我的代码中使用的变量。
我想要实现的是:
Myvariable = (select Column from table1 where column =1234 group by column);
select column from table2 where column in (myvariable);
select column from table3 where column in (myvariable);
等等
提前致谢:)
这不是一个真正的变量...你可以这样写 sql
select column
from table2
where column in (select Column from table1 where column =1234 group by column);
如果您使用 PL/SQL Developer 访问 Oracle 数据库,您可以使用类似于以下的代码创建测试 window(文件 - 新建 - 测试 Window):
DECLARE
myVariable TABLE1.COLUMN%TYPE := 1234;
BEGIN
FOR aRow2 IN (SELECT COLUMN
FROM TABLE2
WHERE COLUMN = myVariable)
LOOP
DBMS_OUPUT.PUT_LINE('Do something with ''aRow2''');
END LOOP;
COMMIT;
FOR aRow3 IN (SELECT COLUMN
FROM TABLE3
WHERE COLUMN = myVariable)
LOOP
DBMS_OUPUT.PUT_LINE('Do something with ''aRow3''');
END LOOP;
COMMIT;
END;
您需要编辑以上内容以对 TABLE2 和 TABLE3 中的行执行任何操作。
祝你好运。
您可以使用绑定到当前会话的临时 TEMPORARY TABLE:
DECLARE GLOBAL TEMPORARY TABLE temp
{
column INTEGER
}
ON COMMIT DELETE ROWS -- Specify PRESERVE ROWS if you want to keep them through commits
NOT LOGGED
ON ROLLBACK DELETE ROWS -- Remove this line if you want to keep rows when you rollback a transaction
您加载 table:
insert into temp1 (select Column from table1 where column =1234 group by column)
然后您可以使用通用代码使用数据:
select column from table2 where column in (select column from temp1);
select column from table3 where column in (select column from temp1);
我是编程新手,我想知道如何声明一个可以在我的代码中使用的变量。
我想要实现的是:
Myvariable = (select Column from table1 where column =1234 group by column);
select column from table2 where column in (myvariable);
select column from table3 where column in (myvariable);
等等
提前致谢:)
这不是一个真正的变量...你可以这样写 sql
select column
from table2
where column in (select Column from table1 where column =1234 group by column);
如果您使用 PL/SQL Developer 访问 Oracle 数据库,您可以使用类似于以下的代码创建测试 window(文件 - 新建 - 测试 Window):
DECLARE
myVariable TABLE1.COLUMN%TYPE := 1234;
BEGIN
FOR aRow2 IN (SELECT COLUMN
FROM TABLE2
WHERE COLUMN = myVariable)
LOOP
DBMS_OUPUT.PUT_LINE('Do something with ''aRow2''');
END LOOP;
COMMIT;
FOR aRow3 IN (SELECT COLUMN
FROM TABLE3
WHERE COLUMN = myVariable)
LOOP
DBMS_OUPUT.PUT_LINE('Do something with ''aRow3''');
END LOOP;
COMMIT;
END;
您需要编辑以上内容以对 TABLE2 和 TABLE3 中的行执行任何操作。
祝你好运。
您可以使用绑定到当前会话的临时 TEMPORARY TABLE:
DECLARE GLOBAL TEMPORARY TABLE temp
{
column INTEGER
}
ON COMMIT DELETE ROWS -- Specify PRESERVE ROWS if you want to keep them through commits
NOT LOGGED
ON ROLLBACK DELETE ROWS -- Remove this line if you want to keep rows when you rollback a transaction
您加载 table:
insert into temp1 (select Column from table1 where column =1234 group by column)
然后您可以使用通用代码使用数据:
select column from table2 where column in (select column from temp1);
select column from table3 where column in (select column from temp1);