Himanshu Himanshu - 9 days ago 8
SQL Question

Why this returns SQL command not properly ended?

Why below query returns SQL Error: ORA-00933: SQL command not properly ended.

INSERT INTO SYNC_MASTERS_TO_PS(
MASTER_CD,
LANG_CD,
TABLE_NAME,
PS_CD
)
SELECT 27542003,
99,
m_office_types,
a.ps_cd
FROM (SELECT DISTINCT PS_CD
FROM M_POLICE_STATION
WHERE STATE_CD = 27)
AS a

Answer

Assuming that m_office_types is a variable you defined somewhere, you have to remove the AS from table alias:

INSERT INTO SYNC_MASTERS_TO_PS(
                           MASTER_CD,
                           LANG_CD,
                           TABLE_NAME,
                           PS_CD
                          )
SELECT 27542003,
       99,
       m_office_types,
       a.ps_cd
  FROM (SELECT DISTINCT PS_CD
          FROM M_POLICE_STATION
         WHERE STATE_CD = 27)
       a
Comments