【发布时间】:2019-05-27 06:33:52
【问题描述】:
基本上我来自 MS SQL 背景,但情况是我需要在 Oracle 中创建一个查询,该查询有一个临时表并在开始 - 结束时我更新该表的行,最后我想要一个 select 语句来输出表。
CREATE GLOBAL TEMPORARY TABLE temp_users (
id number(5) NOT NULL,
name varchar2(50) NOT NULL,
surname varchar2(50) NOT NULL ) ON COMMIT DELETE ROWS;
Declare
dd varchar(400);
Begin
INSERT INTO temp_users VALUES (1, 'John', 'Smith');
INSERT INTO temp_users VALUES (2, 'Anne', 'Parker');
INSERT INTO temp_users VALUES (3, 'Kate', 'Doe');
INSERT INTO temp_users VALUES (1, 'John', 'Smith');
INSERT INTO temp_users VALUES (2, 'Anne', 'Parker');
INSERT INTO temp_users VALUES (3, 'Kate', 'Doe');
// this code i have used to return the table
execute immediate'SELECT * FROM temp_users';
execute immediate 'drop table temp_users';
End;
【问题讨论】:
-
为什么要在 begin end 内运行 select? Oracle 的过程不一定遵循与 MSSQL 相同的做法。告诉我们您为什么希望它在 begin..end 内运行,我们将为您提供更好的解决方案。另外,请告诉我们您运行的是哪个版本的 Oracle。
-
获取/返回数据,以便我可以在其他地方使用它。
标签: oracle