SELECT查询结果集中,如何能够动态添加一个标识列?

56 篇文章 0 订阅
11 篇文章 0 订阅

SELECT查询结果集中,如何能够动态添加一个标识列
比如通过
select * from t_category c1 start with c1.id=79350 connect by prior c1.id=c1.parent_id order by resource_order
此查询语句可以获取如下数据
ID RESOURCE_TYPE RESOURCE_ID RESOURCE_NAME PARENT_ID ...
79351 1 _A1000127724 浮沉1 79350 ...
79352 1 _A1000127732 浮沉2 79350 ...

能否在查询结果集后面动态添加一列
如RESOURCE_ID这列,内容是79350,要达到的效果是

ID RESOURCE_TYPE RESOURCE_ID RESOURCE_NAME PARENT_ID RESOURCE_ID...
79351 1 _A1000127724 浮沉1 79350 79350...
79352 1 _A1000127732 浮沉2 79350 79350...

只是想通过union把需要的数据一次加载上来,并能加以区分,如:
select * from t_category c1 start with c1.id=79350 connect by prior c1.id=c1.parent_id order by resource_order
union
select * from t_category c1 start with c1.id=79351 connect by prior c1.id=c1.parent_id order by resource_order
union
select * from t_category c1 start with c1.id=79352 connect by prior c1.id=c1.parent_id order by resource_order
union
select * from t_category c1 start with c1.id=79353 connect by prior c1.id=c1.parent_id order by resource_order
不知这样是否可行

select id,resource_type,resource_id,resource_name,parent_id,resource_order,resource_path,resource_show_path,resource_stencil,state,template_id,product_id,is_adv,business_type,is_focus,is_commend,create_time,79350 as source_id from (select * from t_category c1 start with c1.id=79350 connect by prior c1.id=c1.parent_id order by resource_order)
union
select id,resource_type,resource_id,resource_name,parent_id,resource_order,resource_path,resource_show_path,resource_stencil,state,template_id,product_id,is_adv,business_type,is_focus,is_commend,create_time,105620 as source_id from (select * from t_category c1 start with c1.id=105620 connect by prior c1.id=c1.parent_id order by resource_order)
union
select id,resource_type,resource_id,resource_name,parent_id,resource_order,resource_path,resource_show_path,resource_stencil,state,template_id,product_id,is_adv,business_type,is_focus,is_commend,create_time,105621 as source_id from (select * from t_category c1 start with c1.id=105621 connect by prior c1.id=c1.parent_id order by resource_order)

据说也可采用存储过程或者临时表解决此问题,后续会对以上问题进行改造。

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值