Oracle:DBMS_OUTPUT 包有替代品吗?

发布于 2024-07-15 01:27:56 字数 49 浏览 8 评论 0原文

尤其是没有 256 个最大字符/行的 和 1000000 个最大字符/缓冲区限制。

especially one that doesn't have the 256 max chars/line
and 1000000 max chars/buffer limitation.

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

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

发布评论

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

评论(6

桃酥萝莉 2024-07-22 01:27:56

也许这些选项之一会满足您的需求(取决于您是在服务器端还是客户端编写内容):

(由 Mark Harrison 更新)我在 AskTom 帖子中使用了 my-dbms-output 包。 一个非常好的功能是您可以通过视图访问结果,这样就可以轻松地在客户端程序中显示输出。 我将其重命名为更短的名称。

Maybe one of these options will suit your needs (depending whether you write something on server side or client side):

(update by Mark Harrison) I went with the my-dbms-output package in the AskTom post. One really nice feature is that you can access the results via a view, so that it's easy to show the output in a client program. I renamed it to a shorter name.

明天过后 2024-07-22 01:27:56

什么版本的Oracle? 这两个限制在最近的版本中都得到了放松。 10.2 支持长度超过 255 个字符的行(新限制为 32k),并消除了最大缓冲区大小限制。 Oracle 9.2 有每行 255 个字符/总大小 1 MB 的限制,但 Oracle 已不再支持该版本。

What version of Oracle? Both of those limitations have been relaxed in recent versions. 10.2 supports lines longer than 255 characters (the new limit is 32k) and eliminates the maximum buffer size limitation. Oracle 9.2 had the 255 characters per line/ 1 MB total limit, but Oracle has desupported that version.

一口甜 2024-07-22 01:27:56

INSERT 是一个绝佳的选择。 您不仅可以从流程中获取信息,还可以保留这些信息以供将来参考或分析。 可以使用称为 SQL 的非常通用的语言来检索、过滤和处理结果。 您可以有一个默认值为 sysdate 的列来检查时间和顺序。 它可以放置在自治事务中,以避免由于回滚而丢失日志记录。

INSERT is a fantastic alternative. Not only do you get the information out of your process, it's persisted for future reference or analysis. And the results can be retrieved and filtered and processed with a very common language called SQL. You could have a column with a default of sysdate to check time and order. It can be placed inside an autonomous transaction to avoid losing the logging due to a rollback.

吾性傲以野 2024-07-22 01:27:56

您可以使用 TCP 包将输出写入终端或远程数据记录器。 非常适合调试在计划任务中运行的包代码。

编辑:这是一个示例过程:

procedure pDebug( str in varchar2 )
-- output debugging message to display or tcp console
   is
x number;
l number;
nPort number;
sAddress varchar2(5000);
  begin
if c_bDebug = 1 then
    if c_tcpbDebug = 1 then
        if cSocket.remote_host is NULL then
            nPort := strMetaDataValue( 'TCP-DEBUG-PORT' );
            sAddress := strMetaDataValue( 'TCP-DEBUG-ADDRESS' );
            dbms_output.put_line( 'tcp:port ' || nPort );
            dbms_output.put_line( 'tcp:address ' || sAddress );
            if length( sAddress ) > 1 and nvl( nPort, 0 ) > 0 then
                begin
                dbms_output.put_line( 'tcp:open start ' ||to_char( SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ) );
                cSocket := utl_tcp.open_connection( sAddress, nPort ); -- open connection
                dbms_output.put_line( 'tcp:open ' || to_char( SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ) );
                c_tcpbDebug := 1;
                exception
                    when others then
                        dbms_output.put_line( SQLERRM );
                        dbms_output.put_line( 'Cant open debug tcp session ' || SYSTIMESTAMp );
                        c_tcpbDebug := 0;
                end;
            else
                c_tcpbDebug := 0;
            end if;
        end if;         

        if cSocket.remote_host is not NULL then
            dbms_output.put_line( 'tcp:write' );
            x := utl_tcp.write_line( cSocket, to_char( SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ) || ' ' || str );
            x := utl_tcp.write_line( cSocket, utl_tcp.crlf );
        end if;
    end if;
-- this bit prints out the debug statement in 254 char bits
    l := length( str );
    x := 1;
    while x <= l loop
        dbms_output.put_line( substr( str,x,254 ) );
        x := x + 254;
    end loop;
end if;
end pDebug;

You can use the TCP package to write output to a terminal or to a remote data logger. Quite handing for debugging package code running in scheduled tasks.

Edit: Here is an example procedure:

procedure pDebug( str in varchar2 )
-- output debugging message to display or tcp console
   is
x number;
l number;
nPort number;
sAddress varchar2(5000);
  begin
if c_bDebug = 1 then
    if c_tcpbDebug = 1 then
        if cSocket.remote_host is NULL then
            nPort := strMetaDataValue( 'TCP-DEBUG-PORT' );
            sAddress := strMetaDataValue( 'TCP-DEBUG-ADDRESS' );
            dbms_output.put_line( 'tcp:port ' || nPort );
            dbms_output.put_line( 'tcp:address ' || sAddress );
            if length( sAddress ) > 1 and nvl( nPort, 0 ) > 0 then
                begin
                dbms_output.put_line( 'tcp:open start ' ||to_char( SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ) );
                cSocket := utl_tcp.open_connection( sAddress, nPort ); -- open connection
                dbms_output.put_line( 'tcp:open ' || to_char( SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ) );
                c_tcpbDebug := 1;
                exception
                    when others then
                        dbms_output.put_line( SQLERRM );
                        dbms_output.put_line( 'Cant open debug tcp session ' || SYSTIMESTAMp );
                        c_tcpbDebug := 0;
                end;
            else
                c_tcpbDebug := 0;
            end if;
        end if;         

        if cSocket.remote_host is not NULL then
            dbms_output.put_line( 'tcp:write' );
            x := utl_tcp.write_line( cSocket, to_char( SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ) || ' ' || str );
            x := utl_tcp.write_line( cSocket, utl_tcp.crlf );
        end if;
    end if;
-- this bit prints out the debug statement in 254 char bits
    l := length( str );
    x := 1;
    while x <= l loop
        dbms_output.put_line( substr( str,x,254 ) );
        x := x + 254;
    end loop;
end if;
end pDebug;
时光沙漏 2024-07-22 01:27:56

另一种选择(尽管可能不是一个很好的选择)是写入警报日志。

sys.dbms_system.ksdwrt(2,to_char(sysdate)|| ' -- The message ');

Another option, although probably not a great one, is to write to the alert log.

sys.dbms_system.ksdwrt(2,to_char(sysdate)|| ' -- The message ');
岛徒 2024-07-22 01:27:56

dbms_output 的一个限制是输出仅在语句完成后才可用。 为了跟踪长时间运行的进程,我使用 dbms_pipe 发送状态消息。 在管道的另一端,您可以看到该过程的进展情况。

One limitiation of dbms_output is that the output becomes available only after the statement has finished. To keep track of long running processes I use dbms_pipe to sent out status messages. On the other end of the pipe you can then see what the process is up to.

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