Friday, January 9, 2015

SQLException: ORA-00904 TableName.ColumnName: invalid

The exception occurs when the column name in a sql statement does not match any column names of the database table. This can happen in several situations.

1. Mis-spell the column name.

2. The column name is missing in the table.

3. Use an invalid column name that does not follow the valid column name criteria.
       
       The valid column name criteria:

  •         The column name must begin with a letter.
  •         The column name must be less than or equal to thirty characters
  •         The column name must only consists of alphanumeric characters and special characters ($, _, #). It must be enclosed in double quotation marks if it contains any other characters.
  •         The column name cannot be a reserved word.

      For example, the following aql will throw such an exception.

       CREATE TABLE FRUIT (
               01NAME                    VARCHAR2(30),
               PRICE                        NUMBER,
               Description                VARCHAR2(50)
        );


4. If you created the table with double quotation marks around the column names, the column names are case sensitive, referring the column names without double quotation marks will cause the exception. For example, if you created the FRUIT table using the following sql,

        CREATE TABLE FRUIT (
               "Name"                    VARCHAR2(30),
               "Price"                     NUMBER,
               "Description"           VARCHAR2(50)
         );

when you query the table with the following sql, the exception occurs.

        SELECT Name, Price FROM FRUIT;

To avoid the exception, you need to put double quotation marks around the column names.

        SELECT "Name", "Price" FROM FRUIT.

5. Extra comma at the end of the last column. For example the following will give such an exception.

      CREATE TABLE FRUIT (
               NAME                       VARCHAR2(30),
               PRICE                        NUMBER,
               Description                VARCHAR2(50),
       );

                                    > Next


-------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment