select * from (select *
from (select TRANS_ID,
txn_id,
(select name
from t_type a
where a.code = t.txn_id
and category = 'TXN') txn_name,
(case
when (TRAN_STATUS = 1) then
'有效'
when (TRAN_STATUS = 2) then
'撤销'
when (TRAN_STATUS = 3) then
'被冲正'
else
'暂挂'
end) TRAN_STATUS,
'卡' status,
txn_date,
pan,
txn_amt,
shop_id,
(select name from t_shop a where a.code = t.shop_id) shop_name,
cust_no,
(select name
from t_client_info a
where a.code = t.cust_no) cust_name,
g_id,
(select name from t_goods s where s.code = t.g_id) g_name,
g_price,
g_qty,
old_pan
from t_transaction_int t
order by txn_date desc)
where rownum <= 10000
union
select *
from (select TRANS_ID,
txn_id,
(select name
from t_type a
where a.code = t.txn_id
and category = 'TXN') txn_name,
'有效' TRAN_STATUS,
'卡' status,
txn_date,
pan,
txn_amt,
shop_id,
(select name from t_shop a where a.code = t.shop_id) shop_name,
'' cust_no,
(case
when (t.issu_bank is null) then
'卡'
else
(select name from t_bank a where a.code = t.issu_bank)
end) cust_name,
g_id,
(select name from t_goods s where s.code = t.g_id) g_name,
g_price,
g_qty,
'' old_pan
from t_transaction_ext t
order by txn_date desc)
where rownum <= 10000)
order by txn_date desc
from (select TRANS_ID,
txn_id,
(select name
from t_type a
where a.code = t.txn_id
and category = 'TXN') txn_name,
(case
when (TRAN_STATUS = 1) then
'有效'
when (TRAN_STATUS = 2) then
'撤销'
when (TRAN_STATUS = 3) then
'被冲正'
else
'暂挂'
end) TRAN_STATUS,
'卡' status,
txn_date,
pan,
txn_amt,
shop_id,
(select name from t_shop a where a.code = t.shop_id) shop_name,
cust_no,
(select name
from t_client_info a
where a.code = t.cust_no) cust_name,
g_id,
(select name from t_goods s where s.code = t.g_id) g_name,
g_price,
g_qty,
old_pan
from t_transaction_int t
order by txn_date desc)
where rownum <= 10000
union
select *
from (select TRANS_ID,
txn_id,
(select name
from t_type a
where a.code = t.txn_id
and category = 'TXN') txn_name,
'有效' TRAN_STATUS,
'卡' status,
txn_date,
pan,
txn_amt,
shop_id,
(select name from t_shop a where a.code = t.shop_id) shop_name,
'' cust_no,
(case
when (t.issu_bank is null) then
'卡'
else
(select name from t_bank a where a.code = t.issu_bank)
end) cust_name,
g_id,
(select name from t_goods s where s.code = t.g_id) g_name,
g_price,
g_qty,
'' old_pan
from t_transaction_ext t
order by txn_date desc)
where rownum <= 10000)
order by txn_date desc
解决方案 »
- SQL语句
- 用OCI涵数连接ORACL的时候,那个参数决定了可以访问那个SKIM.
- 求某张表中某字段每天的最大值,急,在线等
- pl/sql如何一次删除表中所有的重复条目?
- 如何处理这种情况???请高手朋友解救,,100分赠送!!谢谢
- nvl与no_data_found的使用??
- 急!请问oracle817报这个错误“ORA-01033: Message 1033 not found; No message file for product=RDBMS,facility=ORA”是什么意思,如何
- 如何在oracle数据库中逐行输出表单
- 连接ORACLE816数据库的时候,出现ORA-1254:连接因对象主机或对象不存在而失败
- oracle9i中查系统表数据为空是什么回事!
- oracle text 分词匹配度
- 怎样将 表A 里以及 表C 的数据插入到一张新建的 表B 里面?
from (select TRANS_ID,
txn_id,
(select name
from t_type a
where a.code = t.txn_id
and category = 'TXN') txn_name,
/*(case
when (TRAN_STATUS = 1) then
'有效'
when (TRAN_STATUS = 2) then
'撤销'
when (TRAN_STATUS = 3) then
'被冲正'
else
'暂挂'
end) TRAN_STATUS,*/
decode(TRAN_STATUS, 1, '有效', 2, '撤销', 3, '被冲正', '暂挂') as TRAN_STATUS '卡' status,
txn_date,
pan,
txn_amt,
shop_id,
(select name from t_shop a where a.code = t.shop_id) shop_name,
cust_no,
(select name from t_client_info a where a.code = t.cust_no) cust_name,
g_id,
(select name from t_goods s where s.code = t.g_id) g_name,
g_price,
g_qty,
old_pan
from (select *
from (select * from t_transaction_int order by txn_date desc)
where rownum <= 10000) t
union
select TRANS_ID,
txn_id,
(select name
from t_type a
where a.code = t.txn_id
and category = 'TXN') txn_name,
'有效' TRAN_STATUS,
'卡' status,
txn_date,
pan,
txn_amt,
shop_id,
(select name from t_shop a where a.code = t.shop_id) shop_name,
'' cust_no,
(case
when (t.issu_bank is null) then
'卡'
else
(select name from t_bank a where a.code = t.issu_bank)
end) cust_name,
g_id,
(select name from t_goods s where s.code = t.g_id) g_name,
g_price,
g_qty,
'' old_pan
from (select *
from (select * from t_transaction_ext order by txn_date desc)
where rownum <= 10000) t)
order by txn_date desc
-----------------------------------------------------------------------------------------------------------------Plan hash value: 2819955526---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 20000 | 6582K| | 474K (1)| 01:34:52 |
| 1 | VIEW | | 20000 | 6582K| | 474K (1)| 01:34:52 |
| 2 | SORT UNIQUE | | 20000 | 2871K| 6944K| 474K (54)| 01:34:52 |
| 3 | UNION-ALL | | | | | | |
| 4 | VIEW | | 10000 | 1503K| | 221K (1)| 00:44:19 |
|* 5 | COUNT STOPKEY | | | | | | |PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------| 6 | VIEW | | 3445K| 506M| | 221K (1)| 00:44:19 |
|* 7 | SORT ORDER BY STOPKEY| | 3445K| 828M| 2243M| 221K (1)| 00:44:19 |
| 8 | TABLE ACCESS FULL | T_TRANSACTION_INT | 3445K| 828M| | 33812 (1)| 00:06:46 |
| 9 | VIEW | | 10000 | 1367K| | 252K (1)| 00:50:25 |
|* 10 | COUNT STOPKEY | | | | | | |
| 11 | VIEW | | 4493K| 599M| | 252K (1)| 00:50:25 |
|* 12 | SORT ORDER BY STOPKEY| | 4493K| 938M| 2340M| 252K (1)| 00:50:25 |
| 13 | TABLE ACCESS FULL | T_TRANSACTION_EXT | 4493K| 938M| | 38670 (1)| 00:07:45 |
---------------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5 - filter(ROWNUM<=10000)
7 - filter(ROWNUM<=10000)
10 - filter(ROWNUM<=10000)
12 - filter(ROWNUM<=10000)
用explain分析得出一下结果,但解决方案不知道怎么弄。
其余的没办法。
where条件我是有的,在程序上我会加上,但就算sql加上时间条件,在explain分析是还是提示全表扫描的。
虽然有主键索引,但当时写sql的时候用union all的就少了2条,而用union就没少,我也没深究原因,就直接用union了。
7 - filter(ROWNUM<=10000)
10 - filter(ROWNUM<=10000)
12 - filter(ROWNUM<=10000)
union all 不需要排序剃重。
因此 union all的速度要比union 快,并且重复数据会被显示,不会出现你说的【当时写sql的时候用union all的就少了2条,而用union就没少,我也没深究原因,就直接用union了。】
2.可能的话,尽量减少T_TRANSACTION_INT、T_TRANSACTION_EXT查询出来的数据量,如增加TXN_DATE条件等;
3.如果资源允许,增加sql并发数/*+parallel(t,8)*/
第三个/*+parallel(t,8)*/ 应该增加在哪个地方?
3.select * from (select *
from (select/*+parallel(t,8)*/ TRANS_ID,
txn_id,