Table aliasing not working in raw Oracle SQL queri

2019-07-28 06:50发布

问题:

Considering the following Raw SQL query made in Django 1.5 to an Oracle backend that is actually working

cursor.execute("SELECT EGW.TF_BSC_CELTCHH.BSC FROM EGW.TF_BSC_CELTCHH WHERE ROWNUM <= 5")

But if I try to use an alias for the table name like this:

cursor.execute("SELECT TCHH.BSC FROM EGW.TF_BSC_CELTCHH AS TCHH WHERE ROWNUM <= 5")

I get the following error:

ORA-00933: SQL command not properly ended

Why table aliasing is causing such trouble in Oracle?

回答1:

Don't use AS, just type ...

cursor.execute("SELECT TCHH.BSC FROM EGW.TF_BSC_CELTCHH TCHH WHERE ROWNUM <= 5")

That way it should work.

Cheers!