Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Executing statement and commiting statement via qtp
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
Hello All,

I am connecting to DB and trying to execute statement:

Code:
strQuery = "exec STATEMENT"

Please note that this is not a SELECT statement.

I am getting error message that SQL statement is invalid, though I can successfully execute same statement in SQL Plus. Can you please advise me proper syntax how to execute this statement and after that commit changes to DB with code sample?
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
try this, may be it can help you
Code:
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Connection String"

Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection

oCommand.CommandText = "exec Statement"
oCommand.Execute

Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Thanks, I've tried but outcome is the same:

Code:
ORA-00900: Invalid SQL Statement
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
I doubt there is something wrong in your exec staement.
Can you paste exeactly what you are trying here?

Reply
#5
Solved: 11 Years, 3 Months, 4 Weeks ago
Actually there can be a problem, sql statements which are executable in SQL Plus require different syntax in SQL Developer, otherwise - cannot be executed and result in exactly the same manner: Invalid SQL statement.

For example:
- in SQL Plus I execute statement like this: exec statement
- in SQL Developer I wrap statement:
Code:
begin;
exec statement
end;

As for my current code it's below:

Code:
Dim oConn
Dim strConn
Dim strQuery

Set oConn = CreateObject("ADODB.Connection")
Set oRecSet = CreateObject("ADODB.Recordset")
Set oCommand = CreateObject("ADODB.Command")
oConn.Open "Driver={Microsoft ODBC for Oracle};Server=myserver.com;Uid=user;Pwd=pwd;"
oCommand.ActiveConnection = oConn
oCommand.CommandText = "exec STATEMENT"
oCommand.Execute
oConn.Close
Reply
#6
Solved: 11 Years, 3 Months, 4 Weeks ago
Yes, I agree that syntax could be different for some or the other application but this should not be the case when you are doing it through the script. like as in the example you said in SQL Developer you need to wrap, this is the way sql developer tells server to execute the statement.
anyways are you able to execute the same statement on either of the the application ie SQL plus or sql dev
bcoz what i found about ORA-00900: invalid SQL statement is
"The statement is not recognized as a valid SQL statement. This error can occur if the Procedural Option is not installed and a SQL statement is issued that requires this option (for example, a CREATE PROCEDURE statement). You can determine if the Procedural Option is installed by starting SQL*Plus. If the PL/SQL banner is not displayed, then the option is not installed. "

which i beleive is a syntax error and correcting that should solve the issue.

let me know your comments on this.

Reply
#7
Solved: 11 Years, 3 Months, 4 Weeks ago
Working solution is:

Code:
Dim oConn
Dim oCommand
Set oConn = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConn.Open "Driver={Microsoft ODBC for Oracle};Server=myserver.com;Uid=user;Pwd=pwd;"
oCommand.ActiveConnection = oConn
oCommand.CommandText = "STATEMENT"
oCommand.Execute
oConn.Close

See oCommand.CommandText line for modifications: exec word was removed.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question adding two conditions into a while statement lotos 4 5,092 11-10-2017, 04:49 AM
Last Post: lotos
  Reading an amount from statement shipu 0 1,909 12-24-2013, 01:42 AM
Last Post: shipu
  executing qtp on a remote machine sujaravi123 4 4,936 08-02-2013, 01:22 PM
Last Post: sujaravi123
Exclamation Conditional Statement (If.......else) Unleash Rajesh 4 5,677 09-07-2011, 04:55 PM
Last Post: tarun
  correct use of OR statement lotos 2 2,840 06-02-2011, 02:52 PM
Last Post: lotos

Forum Jump:


Users browsing this thread: 1 Guest(s)