JKStack
JKStack

Reputation: 210

Ora-00904 - Error with creating a View

I'm stuck with creating a view in Oracle, but before I create the view, I always test it first and I always got this error: Ora-00904.

This is the situation. I have this one Set of Query let say Query A that I need to combined using UNION ALL with the Query A itself with only few modifications applied to create another bigger Set of Query - Query B. The main constraint that keeps me on doing this is the Database Design, and I'm not in the position in the company to change it, so I have to adapt to it. Query A unions Query A for 6 times creating Query B. The additional Major constraint is Query B is from 1 database user only, but there are 54 database users with the same structures that I need to fetch the same query. Query B (db user1) unions Query B (db user2) unions Query B (db user3) and so on until 54 then finally creating Query C --- the final output. My scrip has already reached 6048 lines, then I got this problem that I don't get when I test Query A and Query B. All my table names, owner names, and column names are all correct but I got that error.

This is the code (that needs to be repeated for 54x6 times) - the Query A. Query B applies some similar modification only.:

Select 
  '2013' "YEAR",
  Upper(a.text_month) "MONTH",
  Upper('Budget') "VERSION",
  case
    when length(b.level1_name) > 5 then  'Parent'
    else 'SUBSIDIARIES'
  end "COMPANY_GROUP",
  case
    when length(b.level1_name) < 6 and b.level1_name <> '1000' then  'Subsidiaries'
    else  '1000  Parent' 
  end "COMPANY",
  case
    when length(b.level1_name) < 6 and b.level1_name <> '1000' then  'SUBS'
    else  '1000'
  end "COMPANY_CODE",
  case
     when length(b.level1_name) > 5 then  'Parent'
    else 'SUBSIDIARIES'
  end "COMPANY_NAME",
  b.level1_displayname "DIVISION",
  b.level1_name "DIVISION_CODE",
  case
    when length(b.level1_name) > 5 then  ltrim(upper(substr(b.level1_displayname, 8)))
    else   upper(ltrim(substr(b.level1_displayname, 10)))
  end "DIVISION_NAME",
  upper(a.text_nature_of_trip) "NATURE_OF_TRAVEL",
  upper(a.text_placeeventstraining) "TRAVEL_DETAILS",
  upper(a.text_country) "COUNTRY",
  a.text_name_of_employee "EMPLOYEE_NAME",  a.float_no_of_attendees "NO_OF_ATTENDEES",    
  a.text_sponsored "SPONSORED",
  a.text_remarks "REMARKS",
  'OTHER TRAVEL EXPENSES' "COST_ELEMENT", 
   a.FLOAT_702120005_OTHER_TRAVEL_E "AMOUNT"
From PUBLISH_PNL_AAAA_2013.et_travel_transaction a, 
PUBLISH_PNL_AAAA_2013.cy_2elist b
Where a.elist = b.level3_iid

Upvotes: 3

Views: 1495

Answers (1)

David Aldridge
David Aldridge

Reputation: 52376

ORA-00904 is "invalid column name" -- either you've spelled the column name wrongly, or prefixed it with the wrong table alias, omitted quotes from a string literal, or any number of other issues.

Check the point in the code that the error message mentions for mistakes like that.

Upvotes: 1

Related Questions