请问如下功能在oracle中怎么实现?

swordmanli 2000-07-20 09:18:00
请问诸位高手:
在MS SQL Server中类似如下的做法,在oracle中如何实现:
例1:存在table1表
...
select *
into #tmp /*请问临时表在oracle中怎么实现?*/
from table1
...
例2:存在A,B表,
A(no integer, num numeric(10,2)) no is primary key
B(no integer, num numeric(10,2)) no is primary key
两表通过no来进行连接,现在A表中的num是错的,要参照B表来修改A表中的num
update a
set a.num = b.num
from a, b
where a.no = b.no
/*请问,这样的功能在oracle中好象无法实现,现在我们在oracle中使用游标来
实现,请问是否有更好的办法?*/
例3:存在A,B表,
A(no1 integer,no2 integer, ....) (no1, no2) is primary key
B(no1 integer, no2 integer ....) (no1, no2) is primary key
两表通过no来连接,现在A中存在一些多余的数据,B表中的数据是正确的,现在想把
A中多余的记录找出来
select a.no, ...
from a left outer join b on (a.no1 = b.no1 and a.no2 = b.no2)
where b.no1 is null
/*这样的写法在oracle中如何实现*/






...全文
309 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fxx 2000-09-10
  • 打赏
  • 举报
回复
1.select * into #tmp from table1
在ORACLE中应该这样:
如果选择出一条数据:SELECT Field1,Field2,... Into v_val1,v_val2,... from table;
如果选出多条数据则要用游标实现。
3.select a.no from table1 a,table2 b
where a.no(+)=b.no

lynx 2000-09-08
  • 打赏
  • 举报
回复
关于例1,解决办法如下:
1.使用FORMS_DDL函数创建临时表,如FORMS_DDL('create table tmp001 as select * from table1');
2.使用临时表的数据;
3.在使用完临时表后,删除该表,如FORMS_DDL('Drop table tmp001');

关于例2,解决办法如下:
1.先根据表a和表b建立视图,如FORMS_DDL('create view tmpview as select a.no,b.num,a.XXX... from a,b where a.no=b.no and b.no is not null');
2.删除表a,再根据视图tmpview创建表a;
3.删除过渡性的视图;

关于例3,解决办法如下:
使用外连接,如select a.no1,a.no2,a.XXX...from a,b where a.no1=b.no1(+) and a.no2=b.no2(+) and b.no1 is not null and b.no2 is not null;

:)给分吧!
swordmanli 2000-08-21
  • 打赏
  • 举报
回复
如果 B 表中不存在 a 的记录呢,那不被更新成空的了吗?
gawj 2000-08-06
  • 打赏
  • 举报
回复
例2:存在A,B表,
update a
set a.num = (select b.num from b where a.no = b.no)
from a
9Thoughts 2000-08-05
  • 打赏
  • 举报
回复
Oracle 8i里支持临时表,Oracle 7不支持。
查阅命令:CREATE TEMPORARY TABLESPACE 及 CREATE TABLE
Tommy Chang 2000-07-20
  • 打赏
  • 举报
回复
1.
select *
into temptable
from sourcetable;

2.
update a
set a.num = (select num from b where a.no = b.no)
// where a.no in (select no from b) 你自己看需要吗?

3.
select *
from a
where not exists(select * from b where a.no1=b.no1 and a.no2=b.no2)

:)
希望没错
swordmanli 2000-07-20
  • 打赏
  • 举报
回复
那用视图怎么来实现我上面的想要得到的功能?
是否能针对我上面的几个例子讲详细一点呢?
barcley 2000-07-20
  • 打赏
  • 举报
回复
可以使用视图吗!视图IN ORACLE IS THE SAME WITH SQL SERVER
Tommy Chang 2000-07-20
  • 打赏
  • 举报
回复
CREATE GLOBAL TEMPORARY TABLE flight_schedule (
startdate DATE,
enddate DATE,
cost NUMBER)
ON COMMIT PRESERVE ROWS;

服务器会需要设置intiX.ora 中compatible=8.1.0
看样子,是8i的特性

swordmanli 是报ora-406 compatible错吗?

再次sorry
swordmanli 2000-07-20
  • 打赏
  • 举报
回复
兄弟,你的这种写法我在 Function 中试过了,好象不成功,你这语法自己试过吗?
Tommy Chang 2000-07-20
  • 打赏
  • 举报
回复
1.create temporary table temptable
as
select *
from sourcetable

sorry
swordmanli 2000-07-20
  • 打赏
  • 举报
回复
我所指的临时表是退出后会自动drop的,而且对它的操作不记录日志的,而且是针对特定连接建立的,多个连接会产生多个临时表的那种!
Tommy Chang 2000-07-20
  • 打赏
  • 举报
回复
swordmanli要的临时表是不是退出后会自动drop的?

2。不用子查询的话实在不知道怎么做。

3。peng_hui回答了。minus是差集,对于可以用outer join的地方应该不需要minus了或union。

另外问句,sql3有谁熟悉?包含sql server那些sql语法吗?
peng_hui 2000-07-20
  • 打赏
  • 举报
回复
我也写错了,b.no(2)没有括号。
cxgtommy,你那个哪是临时表?
Tommy Chang 2000-07-20
  • 打赏
  • 举报
回复
1. 写错了
create table temptable
as
select *
from sourcetable
peng_hui 2000-07-20
  • 打赏
  • 举报
回复
1.cxgtommy提供的语法是什么版本的,我怎么试了不行,我也很想知道ORACLE里是否有临时表可用。
3.用外连接应该可以提高not in的效率:
select * from a where a.no1 = b.no1(+) and a.no2 = b.no(2)(+) and b.no1 is null and b.no2 is null;//假如no1,no2都是主键,那么最后一个条件可不要。
另外,还可以用两个表的差集(我不记得了,好象是MINUS吧,查ORACLE的书看看),我没试过,不知道速度如何。
swordmanli 2000-07-20
  • 打赏
  • 举报
回复
请问
1、temptable是什么性质的表,是临时表吗?对它的操作会记录入日志吗?用完后,它会自动释放吗?
2、in 或 嵌套子查询的效率太低了吧?性能无法跟我在 SQL Server 中提的例子的性能相比。
3、性能也存在问题?
我不知道 oracle中只能这样写吗?有没有更好的办法?

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧