Howdy,

I want to make a sql that goes to oracle. the sql should be
"Select "cusip", "price structure" from tableA" (basically the columns are wrapped in double quotes.

I used this synatax in C#:

string mysql = "select "+'"'+"cusip,"+'"' + '"'+ "Price structure\"" from tableA"

and I am getting the following output:

select \"cusip,\"\"Price from tableA

This output can't be processed by Oracle.

How can I fix the syntax in C#, so that the output would be "Select "cusip", "price structure" from tableA"

thanks
nath

Dani AI

Generated

Short answer: the SQL needs real double-quote characters around the identifiers (Oracle uses double quotes for quoted identifiers). ’s idea to escape the quotes in a C# literal is correct; ’s suggestion to use single quotes would produce SQL string literals (not column names) and is not appropriate for quoting identifiers.

A cleaner C# option is to use a verbatim string and double the quotes inside it, for example:

string sql = @"select ""cusip"", ""price structure"" from tableA";

Notes and troubleshooting tips:

  • Oracle treats quoted identifiers as case-sensitive and exact. If a column truly was created as "price structure" you must match that spelling and case. Unquoted identifiers are normalized to uppercase by Oracle, so avoid creating quoted identifiers with spaces unless you really need them.
  • The debugger or inspector may show escape sequences (backslashes) in its representation of a string; print the SQL with Console.WriteLine or log the text you send to Oracle to verify the exact characters being transmitted.
  • Identifiers cannot be parameterized. If possible, rename/remove spaces in column names (or add a view/alias without spaces) to simplify SQL and eliminate the need for quotes.
  • If you see malformed output like the one posted by it usually means the source literal was mis-assembled (mismatched concatenation/quotes). Use either a single quoted source literal with escapes or a verbatim string for readability to avoid that class of bug.

Recommended Answers

All 2 Replies

Did you try escaping the " marks

string mysql = "select \"cusip\", \"price structure\" from tableA";

Oracle should accept you using:

string mysql = "select 'cusip', 'price structure' from tableA";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.