在 SQL*Plus 中仅显示实际列数据

发布于 2024-10-08 08:01:29 字数 305 浏览 0 评论 0原文

我正在从 SQL*Plus 中假脱机分隔文本文件,但每一列都按照其定义打印为完整大小,而不是该行中实际的数据。

例如,定义为 10 个字符的列,行值为“test”,则打印为“test”而不是“test”。我可以通过选择列及其 LENGTH 函数的值来确认这一点。它打印“测试|4”。

如果它迫使我使用固定宽度,那么它就违背了分隔符的目的。是否有一个 SET 选项可以解决这个问题,或者其他一些方法让它只打印实际的列数据。

我不想向每一列添加 TRIM,因为如果一个值实际上存储时带有空格,我希望能够保留它们。

谢谢

I'm spooling out delimited text files from SQL*Plus, but every column is printed as the full size per its definition, rather than the data actually in that row.

For instance, a column defined as 10 characters, with a row value of "test", is printing out as "test " instead of "test". I can confirm this by selecting the column along with the value of its LENGTH function. It prints "test |4".

It kind of defeats the purpose of a delimiter if it forces me into fixed-width. Is there a SET option that will fix this, or some other way to make it print only the actual column data.

I don't want to add TRIM to every column, because if a value is actually stored with spaces I want to be able to keep them.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烂柯人 2024-10-15 08:01:29

我见过许多 SQL*plus 脚本,它们创建如下文本文件:

select A || ';' || B || ';' || C || ';' || D
from T
where ...

这对我来说是一个强烈的迹象,表明您不能仅使用 SET 命令切换到可变长度输出。

而不是“;”您当然可以使用任何其他分隔符。由您的查询来正确转义任何可能与分隔符或换行符混淆的字符。

I have seen many SQL*plus script, that create text files like this:

select A || ';' || B || ';' || C || ';' || D
from T
where ...

It's a strong indication to me that you can't just switch to variable length output with a SET command.

Instead of ';' you can of course use any other delimiter. And it's up to your query to properly escape any characters that could be confused with a delimiter or a line feed.

笨笨の傻瓜 2024-10-15 08:01:29

一般来说,我会忘记 SQL Plus 作为从 Oracle 中获取 CSV 的方法。

Tom Kyte 编写了一个不错的 Pro-C unloader

就我个人而言,我编写了一个实用程序,它的功能类似,但是是用 perl 编写的

Generally, I'd forget SQL Plus as a method for getting CSV out of Oracle.

Tom Kyte has written a nice little Pro-C unloader

Personally I've written a utility which does similar but in perl

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文