我对此查询有疑问
DECLARE @INPUT INT
SET @INPUT = 12345
;
WITH ABCD(SEQ, X, Y)
AS
(
SELECT 1,
@INPUT % 10,
@INPUT / 10
UNION ALL
SELECT SEQ + 1,
Y % 10,
Y / 10
FROM ABCD
WHERE X > 0 OR Y > 0
)
SELECT *
FROM ABCD
ORDER BY SEQ
此查询将生成类似这样的内容
我想将其转换为Oracle 10g(必须有效10g)
谢谢
答案 0 :(得分:2)
我通过依赖字符串解析而不是数学运算来欺骗一点来计算X. 但这样的东西似乎有效
with t as (
select 12345 col1 from dual
)
select level seq,
trunc((col1 -
power(10,level) * trunc(col1/(power(10,level)))) /
power(10,level-1)) x,
trunc(col1/(power(10,level))) y
from t
connect by level <= length(col1)+1
/
SQL> ed
Wrote file afiedt.buf
1 with t as (
2 select 12345 col1 from dual
3 )
4 select level seq,
5 trunc((col1 -
6 power(10,level) * trunc(col1/(power(10,level)))) /
7 power(10,level-1)) x,
8 trunc(col1/(power(10,level))) y
9 from t
10* connect by level <= length(col1)+1
SQL> /
SEQ X Y
---------- ---------- ----------
1 5 1234
2 4 123
3 3 12
4 2 1
5 1 0
6 0 0
6 rows selected.