已知表中存在以下数据
Order_Auto fact
SL2009110001 SL
SL2009110002 SL
SL2009100001 SL
SL2009100003 SL
Order_Auto的组成是由 fact的值加上年月以及四位流水号,
如果当前是09年9月时, 要求得到 SL2009100001
如果当前是09年10月时,要求得到 SL2009100004
如果当前是09年11月时,要求得到 SL2009110003
请问用一条sql该如何实现!
Order_Auto fact
SL2009110001 SL
SL2009110002 SL
SL2009100001 SL
SL2009100003 SL
Order_Auto的组成是由 fact的值加上年月以及四位流水号,
如果当前是09年9月时, 要求得到 SL2009100001
如果当前是09年10月时,要求得到 SL2009100004
如果当前是09年11月时,要求得到 SL2009110003
请问用一条sql该如何实现!
')
fact的值会不会变化?
from table1
where Order_Auto like :fact||to_char(sysdate,'yyyymm')||'%'
select nvl(max(substr(order_auto,1,8))||trim(to_char(max(substr(order_auto,9,4)+1),'0000')),'SL'||to_char(sysdate,'yyyymm')||'0001') result
from tb where substr(order_auto,3,6) = to_char(sysdate,'yyyymm');
------------ ----
SL2009110001 SL
SL2009110002 SL
SL2009100001 SL
SL2009100003 SL已用时间: 00: 00: 00.00
14:41:24 scott@TUNGKONG> select nvl(max(substr(order_auto,1,8))||trim(to_char(max(substr(order_auto,9,4)+1),'0000')),'SL'||to_char(sysdate,'yyyymm')||'0001') result
14:41:28 2 from tb where substr(order_auto,3,6) = to_char(sysdate,'yyyymm');RESULT
---------------------
SL2009110003已用时间: 00: 00: 00.00
14:41:29 scott@TUNGKONG> select nvl(max(substr(order_auto,1,8))||trim(to_char(max(substr(order_auto,9,4)+1),'0000')),'SL'||'&testdate'||'0001') result
14:41:44 2 from tb where substr(order_auto,3,6) = '&testdate';
输入 testdate 的值: 200909
原值 1: select nvl(max(substr(order_auto,1,8))||trim(to_char(max(substr(order_auto,9,4)+1),'0000')),'SL'||'&testdate'||'0001') result
新值 1: select nvl(max(substr(order_auto,1,8))||trim(to_char(max(substr(order_auto,9,4)+1),'0000')),'SL'||'200909'||'0001') result
输入 testdate 的值: 200909
原值 2: from tb where substr(order_auto,3,6) = '&testdate'
新值 2: from tb where substr(order_auto,3,6) = '200909'RESULT
---------------------
SL2009090001已用时间: 00: 00: 00.00
14:41:52 scott@TUNGKONG> /
输入 testdate 的值: 200910
原值 1: select nvl(max(substr(order_auto,1,8))||trim(to_char(max(substr(order_auto,9,4)+1),'0000')),'SL'||'&testdate'||'0001') result
新值 1: select nvl(max(substr(order_auto,1,8))||trim(to_char(max(substr(order_auto,9,4)+1),'0000')),'SL'||'200910'||'0001') result
输入 testdate 的值: 200910
原值 2: from tb where substr(order_auto,3,6) = '&testdate'
新值 2: from tb where substr(order_auto,3,6) = '200910'RESULT
---------------------
SL2009100004已用时间: 00: 00: 00.01