
oracle数据库SQL语句select * from sys_entity_group where id in(4270,4270)查询只显示一条记录!
select*fromsys_entity_groupwhereidin(4270,4270)查询只显示一条记录,有没有办法让两条记录都显示出来?求大神帮忙、在线等...
select * from sys_entity_group where id in(4270,4270)查询只显示一条记录,有没有办法让两条记录都显示出来?求大神帮忙、在线等
展开
展开全部
说实话,不知道你想干什么,,,
select * from sys_entity_group where id =4270
union all
select * from sys_entity_group where id =4270
要这样显示成2条?
select * from sys_entity_group where id =4270
union all
select * from sys_entity_group where id =4270
要这样显示成2条?
追问
本来好好的简简单单的一个select * from sys_entity_group where id in (……),可是脑残客户他就要弄几个id一样的进去还得给他显示、这不固定没规律的,IN( )里面想是几就是几
追答
大概知道你什么意思了,,,给你个大概的思路
首先你的数据相当于是传入一个4270,4270,380 这样的数据,然后利用大概split()函数将你这个传入的数据拆分,给你提供一下我原来回答别人的sql split()的实现
http://zhidao.baidu.com/question/580672716.html?oldq=1#answer-1458344505
然后将得到的数据插入一个临时表,利用过程实现,,,
以下为实现的过程,我这边sqlserver测试是可以的,细节的问题,你自己再改下吧
create PROC test001_sp @id varchar(100)
AS
BEGIN
SET NOCOUNT ON
CREATE TABLE #table(short_str VARCHAR(10))
INSERT INTO #table
( short_str )
SELECT short_str FROM dbo.split(@id,',')
DECLARE @short_str VARCHAR(10)
declare mycursor cursor FOR
SELECT short_str FROM #table
open mycursor
fetch next from mycursor INTO @short_str
while(@@fetch_status=0)
begin
select * from sys_entity_group where id=@short_str
fetch next from mycursor into @short_str
end
close mycursor
deallocate mycursor
DROP TABLE #table
SET NOCOUNT OFF
END
----
--EXEC test001_sp '04,02,04'
就是传入你的数据,然后利用我前面说的split()函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
原来数据库里只有1条记录,要显示2条出来?
更多追问追答
追问
可以这么说,因为查询的时候这个ID是通过参数传进去的,显示的时候就是要不管传几个、相同不相同都要显示出来 ... 有没有别的方法可以做到?
追答
额,就是一次传一堆ID过来,里面可能有重复的,但是都要显示。你可以写个存储过程,弄个循环,把ID全部查一遍,把插到的记录插到一个临时表,然后输出的时候查询临时表就行。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单,三种方法可以实现
1,用union all 缺点是不灵活
select * from sys_entity_group where id =4270 union all select * from sys_entity_group where id =4270
2,全连接 ,缺点是行数只能是表的连接后的数量
select a.* from sys_entity_group a,sys_entity_group b where a.id=4270
3,利用connect by 比较灵活,一个语句想显示多少条都行,你想显示多少条就把 rownum<6这个改成几
select * from (
select * from sys_entity_group connect by id=id start with id=4270 ) where rownum<6
1,用union all 缺点是不灵活
select * from sys_entity_group where id =4270 union all select * from sys_entity_group where id =4270
2,全连接 ,缺点是行数只能是表的连接后的数量
select a.* from sys_entity_group a,sys_entity_group b where a.id=4270
3,利用connect by 比较灵活,一个语句想显示多少条都行,你想显示多少条就把 rownum<6这个改成几
select * from (
select * from sys_entity_group connect by id=id start with id=4270 ) where rownum<6
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询