语句“select cursor(select ...) c from ...” 从oracle到sql server的转换

zhuyb 2003-08-20 02:54:00
以下面的语句初始化数据:
create table table1(a varchar(2));
create table table2(a varchar(2),b varchar(2));
insert into table1('aa');
insert into table1("aa");
insert into table1 values('aa');
insert into table1 values('bb');
insert into table2 values('aa','a1');
insert into table2 values('aa','a2');
insert into table2 values('aa','a3');
insert into table2 values('bb','b1');
insert into table2 values('bb','b2');
commit;

在oracle中,存在这样的语句:
select a,cursor (select b from table2 where table2.a=table1.a ) c from table1;
该语句是可以成功执行并返回结果的。

在sql server中,该语句不被支持,请问是否有类似方式?

感谢!
...全文
88 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
viptiger 2003-08-20
  • 打赏
  • 举报
回复
select Table1.a,Table2.b from table1
full join
table2 on table2.a=table1.a
zhuyb 2003-08-20
  • 打赏
  • 举报
回复
下面是oracle执行的结果,参考一下,谢谢!
SQL> select a,cursor (select b from table2 where table2.a=table1.a ) test from t
able1;

A TEST
-- --------------------
aa CURSOR STATEMENT : 2

CURSOR STATEMENT : 2

B
--
a1
a2
a3

bb CURSOR STATEMENT : 2

CURSOR STATEMENT : 2

B
--
b1
b2
zhuyb 2003-08-20
  • 打赏
  • 举报
回复
我不能放弃其他数据
zjcxc 元老 2003-08-20
  • 打赏
  • 举报
回复
select a,(select top 1 b from table2 where table2.a=table1.a ) c from table1
chao778899 2003-08-20
  • 打赏
  • 举报
回复
select t1.a,t2.b from table1 t1 inner join table2 on t1.a=t2.a
hjb111 2003-08-20
  • 打赏
  • 举报
回复
select a,(select b from table1,table2 where table2.a=table1.a) c from table
CrazyFor 2003-08-20
  • 打赏
  • 举报
回复
select a,(select top 1 b from table2 where table2.a=table1.a ) c from table1

select a,(select max(b) from table2 where table2.a=table1.a ) c from table1

select a,(select count(b) from table2 where table2.a=table1.a ) c from table1
dafu71 2003-08-20
  • 打赏
  • 举报
回复
select table1.a,table2.b from table1,table2 where table2.a=table1.a
zhuyb 2003-08-20
  • 打赏
  • 举报
回复
感谢各位在短短分钟的回复,但是
我用上面的语句,执行后得到的结果如下:
服务器: 消息 512,级别 16,状态 1,行 1
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。

是什么问题?我用的是sql server 2000 standard edition。
CrazyFor 2003-08-20
  • 打赏
  • 举报
回复
select a,(select b from table2 where table2.a=table1.a ) c from table1
amtyuranus 2003-08-20
  • 打赏
  • 举报
回复
select a,(select b from table2 where table2.a=table1.a ) from table1
zhuyb 2003-08-20
  • 打赏
  • 举报
回复

select a,(select b from table2 where table2.a=table1.a ) c from table1;


---------------------------------------------------------------------------------
服务器: 消息 512,级别 16,状态 1,行 1
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
viptiger 2003-08-20
  • 打赏
  • 举报
回复
select a,(select b from table2 where table2.a=table1.a ) c from table

34,590

社区成员

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

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