A
ATS
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g.
Please help,
I'm trying to write an ASP page to use ADO to run a long query against an
Oracle 10g database, to create tables, if they do not already exist. In terms
of ASP/ADO, that would be fine in a SQL Server Sense by a simply
ASP/Server-Side JavaScript as such:
var cnTemp = Server.CreateObject("ADODB.Connection");
cnTemp.Open("~~~~String for DSN~~~~");
rsTemp = cnTemp.Execute("~~~~ LONG Query ~~~~");
while (rsTemp.EOF != true)
{
~~~~~ Get data ~~~~~~
rsTemp.MoveNext();
}
In terms of the query for SQL Server it would look something like this:
if exists(~~~ MY TABLE)
begin
select 'TABLE ALREADY EXISTS' as 'RET'
end
else
begin
create table ~~~~~~
select 'TABLE CREATED' as 'RET'
end
From this, the Connection object in ADO works GREAT. The returned Recordset
object will have a single row from the multiple statements in that query
returned as the single column called 'RET'.
I need to do the same in Oracle 10g. I need to be able to run many
statements inside a single ORacle query, and have it return Recordset
compatible data, with a single column I define, like the 'RET'. But I do not
know how to do this. As best I can determine, in ORacle I would use something
like this:
SET SERVEROUTPUT ON;
declare
if not exists (~~~~ My Table)
then
create table ~~~~~;
DBMS_OUTPUT.PUT_LINE('TABLE CREATED' ;
else
DBMS_OUTPUT.PUT_LINE('TABLE ALREADY EXISTS' ;
end if;
end;
The first problem is that the PUT_LINE command does not let me have an
option to name the column as I desire. The 2nd problem is that to ORacle via
the ADO Connection object, I get an error as such on the "SET SERVEROUTOUT
ON" statement as such:
undefined(i = 0) - [Microsoft][ODBC driver for Oracle][Oracle]ORA-06550:
line 3, column 5: PL/SQL: ORA-00922: missing or invalid option ORA-06550:
line 3, column 1: PL/SQL: SQL Statement ignored
If I run the query in PL/SQL, it works, (albeit, the output returned does
not let me name the column for the PUT_LINE as I desire.
So, with all that said, how can I do this?
The keys are:
#1 A single LARGE query with multiple statements.
#2 Returns rows of data that ADO-Recordset can access.
#3 Lets one set the column names as desired.
#4 Lets me run complicated IF-THEN statements.
#5 Lets me create tables, indexes, execute grants, and create users.
#6 Same coding for SQL Server with ASP/ADO works for Oracle. IE, SOMETHING
has to happen inside the Oracle query to make it work. AND/OR because the
database is Oracle, we execute some simple QUERIES from an ADO-Connection
object ahead of time.
#7 Under no circumstance can the ADO-Command object be used.
Please help,
I'm trying to write an ASP page to use ADO to run a long query against an
Oracle 10g database, to create tables, if they do not already exist. In terms
of ASP/ADO, that would be fine in a SQL Server Sense by a simply
ASP/Server-Side JavaScript as such:
var cnTemp = Server.CreateObject("ADODB.Connection");
cnTemp.Open("~~~~String for DSN~~~~");
rsTemp = cnTemp.Execute("~~~~ LONG Query ~~~~");
while (rsTemp.EOF != true)
{
~~~~~ Get data ~~~~~~
rsTemp.MoveNext();
}
In terms of the query for SQL Server it would look something like this:
if exists(~~~ MY TABLE)
begin
select 'TABLE ALREADY EXISTS' as 'RET'
end
else
begin
create table ~~~~~~
select 'TABLE CREATED' as 'RET'
end
From this, the Connection object in ADO works GREAT. The returned Recordset
object will have a single row from the multiple statements in that query
returned as the single column called 'RET'.
I need to do the same in Oracle 10g. I need to be able to run many
statements inside a single ORacle query, and have it return Recordset
compatible data, with a single column I define, like the 'RET'. But I do not
know how to do this. As best I can determine, in ORacle I would use something
like this:
SET SERVEROUTPUT ON;
declare
if not exists (~~~~ My Table)
then
create table ~~~~~;
DBMS_OUTPUT.PUT_LINE('TABLE CREATED' ;
else
DBMS_OUTPUT.PUT_LINE('TABLE ALREADY EXISTS' ;
end if;
end;
The first problem is that the PUT_LINE command does not let me have an
option to name the column as I desire. The 2nd problem is that to ORacle via
the ADO Connection object, I get an error as such on the "SET SERVEROUTOUT
ON" statement as such:
undefined(i = 0) - [Microsoft][ODBC driver for Oracle][Oracle]ORA-06550:
line 3, column 5: PL/SQL: ORA-00922: missing or invalid option ORA-06550:
line 3, column 1: PL/SQL: SQL Statement ignored
If I run the query in PL/SQL, it works, (albeit, the output returned does
not let me name the column for the PUT_LINE as I desire.
So, with all that said, how can I do this?
The keys are:
#1 A single LARGE query with multiple statements.
#2 Returns rows of data that ADO-Recordset can access.
#3 Lets one set the column names as desired.
#4 Lets me run complicated IF-THEN statements.
#5 Lets me create tables, indexes, execute grants, and create users.
#6 Same coding for SQL Server with ASP/ADO works for Oracle. IE, SOMETHING
has to happen inside the Oracle query to make it work. AND/OR because the
database is Oracle, we execute some simple QUERIES from an ADO-Connection
object ahead of time.
#7 Under no circumstance can the ADO-Command object be used.