0
votes

I'm currently working on selecting data from 2 oracle tables in the same schema. The problem here has to do with Types. My query is below:

What the issue is is that oracle is telling me "ORA-01790: expression must have same datatype as corresponding expression" And pointing to the field EFF year.

The eff_year field is of type number(4) in the database

The report_date field is of type date in the database

How do I convert the report_date to a number?

I have tried TO_NUMBER(report_date) but this gives me an error ORA-01722: invalid number

SELECT 'Texture' MEASURE,
eff_year
FROM condition 
WHERE linear_id='004'
GROUP BY eff_year
UNION
SELECT 'Cracking' MEASURE,
TO_CHAR(report_date, 'YYYY') eff_year
FROM visual 
WHERE linear_id='004'
GROUP BY report_date
2

2 Answers

2
votes
to_number(TO_CHAR(report_date, 'YYYY')) eff_year
0
votes

I would convert them to dates(to_date(eff_year,'YYYY') and use plain report_date), but using your ideea:

SELECT 'Texture' MEASURE,
eff_year
FROM condition 
WHERE linear_id='004'
GROUP BY eff_year

UNION ALL

SELECT 'Cracking' MEASURE,
to_number(TO_CHAR(report_date, 'YYYY')) eff_year
FROM visual 
WHERE linear_id='004'
GROUP BY TO_CHAR(report_date, 'YYYY')