简体   繁体   中英

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":

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?

I don't think you can get this answer directly from DBI. DBI does not really care about what it is executing, it just passes things to and fom the database. Only you (or the code you wrote) know that the statement you ran was a CREATE TABLE statement.

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.

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

     Result : 0E0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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