PrimaveraTard
MIS
I am attempting to run a query in perl that will drop, create, and alter the tables of an Oracle DB. Below is a snippet of how I am doing one table. (Keep in mind, I'm actaully doing this to 21 tables) I used this Perl syntax to retrieve data from this database and write it to a file before and being the Perltard that I am, figured it would work to do some admin. things as well. The complete error I receive is:
"DBD::Oracle::st execute failed: ORA-00933: SQL command not properly ended (DBD ERROR: OCIStmtExecute) at This is where the directory goes\file_name.pl line 514."
Line 514 looks like this:
my $sth = $dbh->prepare( $sql );
This is an example of how I do one table:
#!perl -w
use strict;
use DBI;
use CGI qw/:standard/;
#Connect to Oracle database, making sure AutoCommit is
#turned off and potential errors are raised.
my $dbh = DBI->connect('dbi:Oracle:System', 'username', 'password', {RaiseError => 1,
AutoCommit => 0});
#Create the SQL.
my $sql = qq{DROP TABLE This_Table CASCADE CONSTRAINTS
CREATE TABLE FAQ_Table (
FT_This_NR NUMBER(5) NOT NULL,
This_QSTN VARCHAR2(250) NULL,
This_LINK VARCHAR2(50) NOT NULL,
This_DT_TM_UPDT VARCHAR2(19) NULL,
This_DT_TM_VRFD VARCHAR2(19) NOT NULL,
This_ATHR CHAR(18) NULL,
This_ANSWR CHAR(1000) NULL
)
TABLESPACE IS_STATIC
ALTER TABLE This_Table
ADD ( PRIMARY KEY (FT_This_NR) )
};
#Prepare the SQL and execute.
my $sth = $dbh->prepare( $sql );
$sth->execute();
$dbh->disconnect(); #Disconnect
"DBD::Oracle::st execute failed: ORA-00933: SQL command not properly ended (DBD ERROR: OCIStmtExecute) at This is where the directory goes\file_name.pl line 514."
Line 514 looks like this:
my $sth = $dbh->prepare( $sql );
This is an example of how I do one table:
#!perl -w
use strict;
use DBI;
use CGI qw/:standard/;
#Connect to Oracle database, making sure AutoCommit is
#turned off and potential errors are raised.
my $dbh = DBI->connect('dbi:Oracle:System', 'username', 'password', {RaiseError => 1,
AutoCommit => 0});
#Create the SQL.
my $sql = qq{DROP TABLE This_Table CASCADE CONSTRAINTS
CREATE TABLE FAQ_Table (
FT_This_NR NUMBER(5) NOT NULL,
This_QSTN VARCHAR2(250) NULL,
This_LINK VARCHAR2(50) NOT NULL,
This_DT_TM_UPDT VARCHAR2(19) NULL,
This_DT_TM_VRFD VARCHAR2(19) NOT NULL,
This_ATHR CHAR(18) NULL,
This_ANSWR CHAR(1000) NULL
)
TABLESPACE IS_STATIC
ALTER TABLE This_Table
ADD ( PRIMARY KEY (FT_This_NR) )
};
#Prepare the SQL and execute.
my $sth = $dbh->prepare( $sql );
$sth->execute();
$dbh->disconnect(); #Disconnect