Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I see the actual query generated when using OracleParameters with OracleCommand?

Tags:

c#

sql

odp.net

I want to use ODP.NET to run various queries on an oracle database and I'd like to use parameters in the query. Here's a trivial example snippet (omitting all the obvious setup bits of the OracleConnection):

string query = "SELECT FIRSTNAME FROM EMPLOYEES WHERE LASTNAME=:pNAME";
OracleCommand command = new OracleCommand(query);
command.Parameters.Add(":pNAME", OracleDBType.Varchar2).Value = "O'Brien";

My question is, is there anyway to see the query that gets generated from this? I know this is a simple example and the output is probably very obvious, but I'm trying to see how it actually handles things like escaping characters such as the ' in O'Brien. And of course in the future if my queries get more complicated and I'm getting sql errors, I thought I might be able to use the generated query to debug.

Any help or pointers is greatly appreciated!

like image 780
jmccarthy Avatar asked Sep 11 '25 08:09

jmccarthy


1 Answers

SQL parameters are passed as parameters directly to SQL server, so there is no way to see it from your application. You can try checking it from Oracle side.

like image 117
Snowbear Avatar answered Sep 13 '25 23:09

Snowbear