将一行拆分为多行(固定宽度)
一行传入记录有多个子记录串联。每个子记录的长度为 9 个字符。我每行有8个这样的子记录。所以每行是(8x9=72 个字符)。有没有办法可以将 1 条记录分成 8 条记录?
输入
123456789123456789123456789123456789123456789123456789123456789123456789
输出
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
我知道我可以用 8 个子查询来做到这一点并将它们联合起来..有更好的方法吗?
One row of incoming record has multiple sub-records concatenated. Each sub record is 9 characters long. I have 8 such sub-records in each row. So each row is (8x9=72 char). Is there a way i can split 1 record into 8 records here?
Input
123456789123456789123456789123456789123456789123456789123456789123456789
Output
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
I know i can do this with 8 sub queries and union them .. is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
或者这样怎么样:
表 t1 包含您的字符串,表 t2 是通过将其交叉连接到 t1 表生成的从 0 到 7 的顺序数字列表,我们可以使用它来分割字符串列。
or how about this:
table t1 contains your strings, table t2 is a generated list of sequential numbers from 0 to 7 by cross joining it to the t1 table we can use it to cut up the string column.
我见过人们使用仅包含值 1 到 8 的辅助表,然后与该表连接。您可以使用该值来对记录进行子字符串化。
像“注意:查询未经测试”之类的东西
,但我希望这个想法能够得到理解。
I've seen people use a secondary table containing only the values 1 through 8, then joining with that table. You can use the value to substring your record.
Something like
Note: Query untested, but I hope the idea gets across.
如果可以预见的是,每行总是会分成固定数量的行,那么类似以下的事情应该是可能的:
编辑:凯文的迭代器比我的强力版本更简单、更好。 b 子查询应该是 (SELECT ROWNUM as iterator FROM Dual CONNECT BY LEVEL <= 8)
If it is predictable that each line will always split into a fixed number of lines, something like the following should be possible:
EDIT: Kevin's iterator was simpler and better than my brute force version. The b subquery shoud be (SELECT ROWNUM as iterator FROM dual CONNECT BY LEVEL <= 8)