简体   繁体   English

如何使用Perl DBI获得“表已创建”的输出

[英]How can I get output “Table created” with perl DBI

There is a code I would like to get output with Perl DBI "Table created": 我想用Perl DBI“创建表”获得代码:

use DBI;
use DBD::Oracle qw(:ora_session_modes);

$dbh=DBI->connect( "dbi:Oracle:", "", "", { ora_session_mode =>
      ORA_SYSDBA , RaiseError => 1, PrintError => 1 } );
$dbh->do(qq{  create table test ( customer_id number(10) NOT NULL )    } );

How can I get this output "Table created" from DBI? 如何从DBI获得此输出“创建表”?

I don't think you can get this answer directly from DBI. 我认为您无法直接从DBI获得此答案。 DBI does not really care about what it is executing, it just passes things to and fom the database. DBI并不真正在乎它在执行什么,它只是将事物传递给数据库并对其进行格式化。 Only you (or the code you wrote) know that the statement you ran was a CREATE TABLE statement. 只有您(或您编写的代码)知道您运行的语句是CREATE TABLE语句。

So if you want to print TABLE CREATED , or even TABLE test CREATED , you must check the return value as suggested by some other answers here and assemble the message yourself. 因此,如果要打印TABLE CREATED或什至TABLE test CREATED ,则必须按照此处其他答案的建议检查返回值,然后自行组装消息。

If the Query is not executed successfully print the error message. 如果未成功执行查询,则打印错误消息。

  $Local_Dbh->do($Query) or print " Unable to execute the query $Local_Dbh->errstr";  

If the table is not created , It will return the undef or -1 otherwise return the value like 如果未创建表,它将返回undef或-1,否则返回值

     Result : 0E0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM