2

I have 2 columns in oracle, that I am merging like below

select SURVEY_AREA_7_12 || ' ' || HISSA_NO_7_12 
from XXCUS.XXACL_PN_FARMING_MST

which is working fine. But when I add my own name to the columns like below

select SURVEY_AREA_7_12 || ' ' || HISSA_NO_7_12 as 712_Column 
from XXCUS.XXACL_PN_FARMING_MST

it gives error as

ORA-00923: FROM keyword not found where expected

Nad
  • 4,605
  • 11
  • 71
  • 160

4 Answers4

3

The problem is that your alias has a number in first position; you can quote it or change the alias:

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> select 'a' as 1ABC from dual;
select 'a' as 1ABC from dual
              *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected


SQL> select 'a' as "1ABC" from dual;

1ABC
----
a

A number in a position different from the first gives no problem:

SQL> select 'a' as ABC1 from dual;

ABC1
----
a
Aleksej
  • 22,443
  • 5
  • 33
  • 38
2

Try the identifier with double quotes "

SELECT (SURVEY_AREA_7_12 || ' ' || HISSA_NO_7_12) AS "712_Column"
FROM XXCUS.XXACL_PN_FARMING_MST
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
2

712_Column is an invalid SQL identifier. You can't start an identifier with a number. If you need this, you need to quote the name:

select SURVEY_AREA_7_12 || ' ' || HISSA_NO_7_12 as "712_Column"
from XXCUS.XXACL_PN_FARMING_MST
  • can't I use single `'` quote ? – Nad Sep 26 '16 at 10:38
  • @nad: No. Single quotes are for string constants in SQL. Double quotes are for identifiers. See the chapter "Basic Elements of Oracle SQL" in the manual for details: [here](https://docs.oracle.com/database/121/SQLRF/sql_elements003.htm#SQLRF00217) and [here](https://docs.oracle.com/database/121/SQLRF/sql_elements008.htm#SQLRF00223) –  Sep 26 '16 at 10:38
  • while adding this in my c# code, like below `OracleDataAdapter da712 = new OracleDataAdapter("SELECT (survey_area_7_12 || ' ' || hissa_no_7_12) AS "712_Column" FROM xxcus.xxacl_pn_farming_mst", ObjPriCon);` I am getting error as **) expected** – Nad Sep 26 '16 at 10:43
  • 1
    @nad: that has nothing to do with SQL. You are nesting double quotes inside a string literal with double quotes. Please refer to the C# language specification on how to do that. –  Sep 26 '16 at 10:45
  • @nad - do you really have to call the column `712_Column`? (Do you care about upper case and lower case, in addition to the digits first?) In general it is MUCH MUCH better if you get in the habit of using "standard" identifiers. Why doesn't `column_712` (which will be written in the catalog and in output of your queries in upper case, `COLUMN_712`) work for you? –  Sep 26 '16 at 12:30
2

you are using alias name starts with number. That is the problem. Please use column_712 and execute...

phani
  • 21
  • 1