SELECT * FROM ( SELECT TMP_PAGE.*, ROWNUM ROW_ID FROM ( SELECT tt.ID, tt.VIN, tt.AON, tt.MSC, tt.VEH_CLSCRQ, tt.COLOR_CODE, tt.VEH_ZCHGZBH, tt.VEH_WZHGZBH, tt.VEH_FZRQ, tt.FRIST_PRINT_DATE, tt.VEH_CLZZQYMC, tt.VEH_CLPPMC, tt.IFLOCK, tt.UP_SYNCSTATE, tt.VEH_CLXH, tt.IS_SAMPLE, ta.XNYC AS XNYC, SUBSTR( VIN, 8, 1 ) AS DLLX, T_DLLX.NAME AS DLLXNAME FROM T_VEHCERT_PRINT tt LEFT JOIN T_ALL_PARAM ta ON tt.MSC = ta.MSC LEFT JOIN T_DLLX ON SUBSTR( VIN, 8, 1 ) = T_DLLX.CODE WHERE XNYC = '否' AND IFLOCK = '0' AND UP_SYNCSTATE ='1' ORDER BY frist_print_date DESC ) TMP_PAGE WHERE ROWNUM <= '10' ) WHERE ROW_ID > '0'这段sql查询半天都查不出结果
时间: 2024-04-26 21:21:25 浏览: 128
这段 SQL 查询语句的目的是从 T_VEHCERT_PRINT 表中选择一些列,并将它们与其他表连接,然后按照 frist_print_date 字段降序排序。然后,它将结果限制为前 10 行,并为每一行分配一个 ROW_ID。最后,它选择所有 ROW_ID 大于 0 的行。
如果这段 SQL 查询半天都查不出结果,可能是因为没有符合条件的数据存在。您可以检查 WHERE 子句中的条件是否正确,并检查表中是否存在与这些条件匹配的数据。此外,您还可以查看数据库日志,以查找是否存在任何错误或异常。
相关问题
select * from ( select row_.*, rownum rownum_ from ( select * from ( select distinct OB.BUSI_ORDER_ID, 0 as HIS_ID, OB.BUSI_CODE, OB.CUST_ID, OB.CEASE_REASON, OB.ORDER_STATE, OB.CHANNEL_TYPE, ob.user_id, OB.IS_BATCH_ORDER, OB.APPLICATION_ID, OB.CREATE_DATE, OB.DONE_DATE, OB.EFF_DATE, OB.EXP_DATE, OB.OPER_ID, OB.ORG_ID, OB.REGION_ID, OB.NOTE, OB.PROCESS_STATE, nvl(oi.cust_name, ic.cust_name) cust_name, nvl(oc.icc_id, iu.icc_id) icc_id, nvl(oc.svc_num, iu.svc_num) svc_num, icp.cust_name parent_cust_name, icp.cust_id parent_cust_id, ol.order_list_id from ord_busi ob left join ord_offer oo on oo.busi_order_id = ob.busi_order_id and ob.user_id = oo.user_id left join info_user iu on oo.user_id = iu.user_id left join info_cust ic on ob.cust_id = ic.cust_id left join ord_cust oi on ob.cust_id = oi.cust_id and ob.busi_order_id = oi.busi_order_id left join info_cust icp on nvl(ic.parent_cust_id, oi.parent_cust_id) = icp.cust_id left join ( SELECT * FROM ord_user WHERE user_order_id IN ( SELECT MAX(user_order_id) user_order_id FROM ord_user GROUP BY busi_order_id,user_id ) ) oc on ob.user_id = oc.user_id and ob.busi_order_id = oc.busi_order_id left join ord_list ol on ob.busi_order_id = ol.busi_order_id WHERE 1 = 1 and OB.CUST_ID IN( SELECT DISTINCT CUST_ID FROM (SELECT CUST_ID, PARENT_CUST_ID FROM INFO_CUST UNION SELECT CUST_ID, PARENT_CUST_ID FROM ORD_CUST) TMP START WITH TMP.CUST_ID = '10001009208' CONNECT BY TMP.PARENT_CUST_ID = PRIOR TMP.CUST_ID ) union all select distinct OB.BUSI_ORDER_ID,OB.HIS_ID, OB.BUSI_CODE, OB.CUST_ID, OB.CEASE_REASON, OB.ORDER_STATE, OB.CHANNEL_TYPE, OB.USER_ID, OB.IS_BATCH_ORDER, OB.APPLICATION_ID, OB.CREATE_DATE, OB.DONE_DATE, OB.EFF_DATE, OB.EXP_DATE, OB.OPER_ID, OB.ORG_ID, OB.REGION_ID, OB.NOTE, OB.PROCESS_STATE, nvl(oi.cust_name,ic.cust_name) cust_name , nvl(oc.icc_id, iu.icc_id) icc_id, nvl(oc.svc_num,iu.svc_num) svc_num, icp.cust_name parent_cust_name, icp.cust_id parent_cust_id, ol.order_list_id from ord_busi_his ob left join ord_offer_his oo on oo.busi_order_id = ob.busi_order_id 优化一下
可以考虑以下优化方式:
1. 使用INNER JOIN代替LEFT JOIN:如果确保两个表中都含有匹配的行,则使用INNER JOIN可以提高查询效率。
2. 使用EXISTS代替IN:EXISTS执行速度比IN更快,因为它只需要找到匹配的第一个结果,而不是找到所有匹配的结果。
3. 简化子查询:在查询中可以尝试简化子查询,以减少查询的复杂度。
4. 使用索引:使用索引可以提高查询效率,可以根据查询中经常使用的列添加索引。
5. 避免使用SELECT *:只查询需要的列,避免使用SELECT *可以减少查询的复杂度,提高查询效率。
SELECT '155427848241370' || SEQ_KD_INDEX.nextval || 'GJ', a.PROBABLECAUSE, ( SELECT zhFUNc_GETNEWIDFORCIR ( id ) FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), '1028200001', ( SELECT name FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), ( SELECT code FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), a.IP, a.ALARMTIME, a.alarmtext, SYSDATE, NULL, a.alarmid, a.createtime, a.perceivedseverity, a.moname FROM ( SELECT x.*, ( SELECT COUNT( DISTINCT re.coveraddressid ) FROM gistar.jr_customer_record @yjyx_zy re WHERE re.project_type IN ( 'FTTH宽带' ) AND re.oltip = x.IP ) AS oltcount FROM gistar.t_trouble_alarminfo x ) a WHERE a.specialty = 'PON' AND a.motype = 'OLT' AND IP IS NOT NULL AND a.PROBABLECAUSE = 'OLT网管脱网' AND ( SELECT substr( b.tt_number, 0, 2 ) FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'NM' AND ( SELECT title FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'OLT网管脱网' AND ( ( SYSDATE < '2021-05-01' AND a.oltcount >= 600 ) OR a.oltcount >= 400 ) UNION ALL SELECT '155427848241370' || SEQ_KD_INDEX.nextval || 'GJ', a.PROBABLECAUSE, ( SELECT zhFUNc_GETNEWIDFORCIR ( id ) FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), '1028200001', ( SELECT name FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), ( SELECT code FROM gistar.tdn_switch ch WHERE ch.ipaddress = a.IP AND ROWNUM = 1 ), a.IP, a.ALARMTIME, a.alarmtext, SYSDATE, a.cleartime, a.alarmid, a.createtime, a.perceivedseverity, a.moname FROM ( SELECT x.*, ( SELECT COUNT( DISTINCT re.coveraddressid ) FROM gistar.jr_customer_record @yjyx_zy re WHERE re.project_type IN ( 'FTTH宽带' ) AND re.oltip = x.IP ) AS oltcount FROM gistar.t_trouble_alarminfo x ) a WHERE a.specialty = 'PON' AND a.motype = 'OLT' AND IP IS NOT NULL AND a.PROBABLECAUSE = 'OLT网管脱网' AND ( SELECT substr( b.tt_number, 0, 2 ) FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'NM' AND ( SELECT title FROM fwbz.t_trouble_ticket_new @GDOSSDB_SGDD b WHERE a.tt_id = b.tt_id ) = 'OLT网管脱网' AND ( ( SYSDATE < '2021-05-01' AND a.oltcount >= 600 ) OR a.oltcount >= 400 ) AND a.cleartime IS NOT NULL AND a.alarmid IN ( SELECT alarm_id FROM olt_ALARM_BILL GROUP BY alarm_id, device_ip, alarm_time, create_time HAVING count( * ) = 1 );报错ORA-02287: sequence number not allowed here
这个 SQL 语句中使用了 SEQ_KD_INDEX.nextval,而在 SELECT 语句中不能直接使用序列的 nextval() 方法,因为 nextval() 方法不是一个常量或字面值,而是一个函数,因此不能在字符串中直接使用。要解决这个问题,可以将 nextval() 放在一个子查询中,然后在 SELECT 语句中引用该子查询的结果。例如,可以将第一个 SELECT 语句修改如下:
```
SELECT '155427848241370' || (SELECT SEQ_KD_INDEX.nextval FROM dual) || 'GJ', a.PROBABLECAUSE, ...
```
这样就可以在字符串中引用 nextval() 方法的返回值了。注意,这里使用了 Oracle 中的 dual 表来执行子查询,因为在 Oracle 中,必须使用 FROM 子句来指定一个表,即使这个表只包含一行数据也是如此。
阅读全文