java.sql.SQLException: ORA-01427: single-row subquery returns more than one row

ORA-01427: 单行子查询返回多个行

sql语句如下:

select h.operator,
       to_char(h.operate_tm, 'yyyy-mm-dd hh24:mi:ss') operate_tm,
       (select t.res_label name
          from sysmngdba.res@msp t
         where t.id = h.system_id) system_id,
       (select t.res_label name
          from sysmngdba.res@msp t
         where t.id = h.module_id) module_id,
       (select index_value
          from int_sys_param
         where index_type = 'operateType'
           and index_code = h.operate_type) operate_type,
       h.operate_page,
       h.tab_nm,
       DECODE(h.status, '0', '??', '1', '??', '2', '???????????') status,
       DECODE(h.sensitive_Id, '1', '????', '2', '??', '3', '??') sensitive_Id,
       h.ip_address,
       h.note,
       h.session_id,
       h.transaction_id,
       h.operator || ',' || nvl(h.operate_page, ' ') || ',' ||
       nvl(h.session_id, 0) || ',' || nvl(h.transaction_id, 0)
  from (select a.operator,
               a.operate_tm,
               a.system_id,
               a.module_id,
               a.operate_type,
               a.operate_page,
               a.tab_nm,
               a.status,
               a.sensitive_Id,
               a.ip_address,
               a.note,
               a.session_id,
               a.transaction_id
          from process_log a
        union all
        select b.operator,
               b.operate_tm,
               b.system_id,
               b.module_id,
               b.operate_type,
               b.operate_page,
               b.tab_nm,
               b.status,
               b.sensitive_Id,
               b.ip_address,
               b.note,
               b.session_id,
               b.transaction_id
          from iigsmdba.parameter_log b) h
 where 1 = 1
   and operate_tm >=
       to_date('2015-03-06 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
   and operate_tm <=
       to_date('2015-03-09 23:59:59', 'yyyy-mm-dd hh24:mi:ss')

 

解决办法:

首先要确认是哪个子查询引起的,以上面的sql为例

在这三条在子查询中加入rownum<2, 限制返回一行数据。可以成功查询。

        select t.res_label name
          from sysmngdba.res@msp t
         where t.id = h.system_id and rownum<2) system_id,
       (select t.res_label name
          from sysmngdba.res@msp t
         where t.id = h.module_id and rownum<2) module_id,
       (select index_value
          from int_sys_param
         where index_type = 'operateType'
           and index_code = h.operate_type and rownum<2) operate_type,

然后依次去掉 rownum < 2,看看具体是哪一条引起的。

最后排查是下面这条语句存在多条数据:

select index_value
          from int_sys_param
         where index_type = 'operateType'
and index_code = h.operate_type

转载于:https://www.cnblogs.com/teamsun/p/4330316.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值