OracleClient special characters in column name

  • Thread starter Thread starter Josep S.
  • Start date Start date
J

Josep S.

Hello
I am working with System.Data.OracleClient

How can I create a table with special characters in
column name ?

I have tried:

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 ('_C1' number)");
oCmd.ExecuteNonQuery();

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 (\"_C1\" number)");
oCmd.ExecuteNonQuery();

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 (\\_C1 number)");
oCmd.ExecuteNonQuery();

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 ({_}C1 number)");
oCmd.ExecuteNonQuery();

... but it does not work.


Thanks for replies.
 
Josep S. said:
Hello
I am working with System.Data.OracleClient

How can I create a table with special characters in
column name ?

I have tried:

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 ('_C1' number)");
oCmd.ExecuteNonQuery();

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 (\"_C1\" number)");
oCmd.ExecuteNonQuery();

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 (\\_C1 number)");
oCmd.ExecuteNonQuery();

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 ({_}C1 number)");
oCmd.ExecuteNonQuery();

... but it does not work.

This one should work.

OracleCommand oCmd = new OracleCommand("CREATE TABLE
T1 (\"_C1\" number)");
oCmd.ExecuteNonQuery();

Oracle schema object names must start with an alpha character. So to get
this to work you must use quoted identifiers.

The SQL is
CREATE TABLE T1 ("_C1")

But since use quoted identifiers to make this work, you will forever have to
use quoted identifiers to reference it.

For instance
SELECT _C1 FROM T1
won't work. You will have to user
SELECT "_C1" from T1.

Why not use
CREATE TABLE T1 (C1_ number)
instead?

David
 
Sometimes you may need to use a special character such as
& or ; in a query that is used by SQL*Plus. You can define
an escape character. You may then use it in queries before
a special character. It is often useful in automated
scripting. To escape the quote character use multiple
quotes

set escape \
select 'It''s mine\; I like it' from dual;
You may also turn escape on and off.

set escape off

Mitesh
 
Back
Top