有张表A
id name
1 a
2 b
3 c我想用id查出name
select name from A where id in(1,2,3,4,5)
用id in 去查 例如上面那句 但是结果不是3条 要5条记录 4,5没有 那就空着
id name
1 a
2 b
3 c我想用id查出name
select name from A where id in(1,2,3,4,5)
用id in 去查 例如上面那句 但是结果不是3条 要5条记录 4,5没有 那就空着
解决方案 »
- 请教Oracle中order by默认排序及工作原理
- oracle select 疑惑
- OC4J读取jar档的方式
- 备份过程中遇到如下问题。。。。。。
- oracle 10g有没有9i那样的客户端?该如何配置使能用pl/sql连接??
- 游标问题
- 请教大家如何在linux下使用c/c++语言(用gcc编译)访问Oracle数据库?
- 我今年毕业,现在有间公司请我去当oracle的DBA,不知道这个职位的前途怎么样呢?
- 如何获取oracle服务器的ip地址?
- execute sys.auto_server_pkg.unlock_table('用户名','表名')
- 关于Oracle SQL Developer的菜鸟问题
- 急,问一个 management server 的问题。
(select rownum id from dual connect by rownum<10)b
on b.id=a.id
where b.id in(1,2,3,4,5)
你的要求不太合理,要将原表中没有的数据凭空生出几条来,这些条数还不确定
如果id in(1,2,3,4,5) 括号里的值为5个的话,可以试试
select * from(
select id,name from a union all
select null,null from a union all
select null,null from a union all
select null,null from a union all
select null,null from a union all
select null,null from order by id)
where (id in(1,2,3,4,5) or id is null)
and rownum<=5rownum貌似在mssql里也没有,mssql里用top5吧
或者将1楼里(select rownum id from dual connect by rownum <10)
替换成select 1 from dual union all
select 2 from ...
一条一条写出来
SQL> with temp as
2 (
3 select 1 id from dual
4 union
5 select 2 id from dual
6 union
7 select 3 id from dual
8 )
9 select temp.*, b.t from temp, (select substr(r, decode(rownum, 1, 0, instr(
r,',',1,rownum-1))+1, instr(r,',',1,rownum)-decode(rownum, 1, 0, instr(r,',',1,r
ownum-1))-1) t from (select '1,2,3,4,5'||',' r from dual) connect by instr(r,','
,1,rownum)>0) b where temp.id(+)=b.t; ID T
---------- --------------------
1 1
2 2
3 3
5
4