[英]Custom File format using Spool SQLPLUS
I am trying to export data from multiple tables to a custom pipe delimited file format.我正在尝试将数据从多个表导出到自定义 pipe 分隔文件格式。 I am able to generate pipe delimited file from single table, but not able to achieve the required custom format.
我能够从单个表中生成 pipe 分隔文件,但无法实现所需的自定义格式。
Here is the format:这是格式:
HD|034567|24052021092630|1.0
3|||||0|0|12345678909|2|SDATA|DNAME||||TBD|||M|||||||||||||||||
3|||||0|0|12345678910|1|SDATA|DNAME||||TBD|||F|||||||||||||||||
3|||||0|0|12345678911|5|SDATA|DNAME||||TBD|||M|||||||||||||||||
FT|000000003
Where first row
that starts with HD
is from separate table, last one is hardcoded and data in rows in the middle is from the main table.以
HD
开头的first row
来自单独的表,最后一行是硬编码的,中间行中的数据来自主表。 How I can generate this format.dat file using SPOOL SQL*PLUS or with any other utility that is more suitable to scenario.如何使用 SPOOL SQL*PLUS 或任何其他更适合场景的实用程序生成此 format.dat 文件。
Thank you谢谢
It's been 5 hours since you posted the question and no replies yet.自您发布问题以来已经 5 小时了,还没有回复。 Maybe it means that you can't do it the way you planned to.
也许这意味着你不能按照你计划的方式去做。
"Trivial" solution would be to use 3 SELECT
statements with a UNION ALL
, eg “微不足道”的解决方案是使用带有
UNION ALL
的 3 SELECT
语句,例如
select 'HD', col1, col2, col3 from table_1
UNION ALL
select number of columns from table_2
UNION ALL
select 'FT', 000000003 from dual
but it won't work because但它不会工作,因为
You could run 3 separate select
statements, but there'll be empty lines in between.您可以运行 3 个单独
select
语句,但中间会有空行。
Therefore, consider switching to PL/SQL and UTL_FILE package to create such a file.因此,考虑切换到 PL/SQL 和 UTL_FILE package 来创建这样的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.