Click here to Skip to main content
16,018,114 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
SQL
SELECT D1.DISTRICT_NAME, E1.EMP_FNAME, E1.EMP_LNAME, T1.TAX_YEAR, T1.DATE_LAST_CALC
FROM DISTRICT AS D1, EMPLOYEE AS E1, TOTAL_PAB AS T1
WHERE T1.DATE_LAST_CALC BETWEEN '2015-04-01' AND '2015-04-04'
OR '2015-06-01' - T1.DATE_LAST_CALC > 175
ORDER BY DISTRICT_NAME, EMP_LNAME;


I'm trying to create a view in Oracle.

Write a query (and save as a view) to display all employees that need to have their TOTAL_PAB recalculated. They need to be recalculated if their DATE_LAST_CALC is between April 1st, 2015 and April 4th, 2015 (there was a virus report in that time frame so they want to recalculate these) OR the difference between June 1 st, 2015 (beginning of fiscal year) and the DATE_LAST_CALC is greater than 175 days. Sort by the District’s name and then by the employee’s last name

When I try to run this, I get ORA-00933: SQL command not properly ended. I don't know what is wrong with the syntax. Any help please.
Posted
Updated 22-Nov-15 6:56am
v2
Comments
PIEBALDconsult 22-Nov-15 13:43pm    
Not sure about Oracle, but SQL Server doesn't like ORDER BY in views; you should consider removing that, it doesn't belong in the view.

1 solution

The ORDER BY clause is supported in recent versions of Oracle.

In your query I see a couple of problems. The first is if the T1.DATE_LAST_CALC column is of data type DATE, you'll get an error. In Oracle you have to convert to date before comparing. Secondly, you're trying to do 2 things here. Try putting brackets around the two dates your are subtracting.
SQL
OR '2015-06-01' - T1.DATE_LAST_CALC > 175


This should be close; if not, let me know:

SQL
CREATE OR REPLACE VIEW your_view AS
SELECT D1.DISTRICT_NAME, E1.EMP_FNAME, E1.EMP_LNAME, T1.TAX_YEAR, T1.DATE_LAST_CALC
FROM DISTRICT AS D1, EMPLOYEE AS E1, TOTAL_PAB AS T1
WHERE T1.DATE_LAST_CALC BETWEEN TO_DATE('2015-04-01', 'yyyy-mm-dd') AND TO_DATE('2015-04-04', 'yyyy-mm-dd')
OR (TO_DATE('2015-06-01', 'yyyy-mm-dd') - T1.DATE_LAST_CALC) > 175
ORDER BY DISTRICT_NAME, EMP_LNAME;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900