I have the following Oracle SQL query I want to execute as a NativeQuery in JPA with the Play Framework, but for some reason, I always get an ORA-00907: missing right parenthesis error.
SELECT
a.EMPLOYEE_ID,
a.FIRST_NAME,
a.LAST_NAME,
a.EMAIL,
a.PHONE_NUMBER,
TO_CHAR(a.HIRE_DATE, 'YYYY/MM/DD') HIRE_DATE,
a.JOB_ID,
a.SALARY,
a.COMMISSION_PCT,
a.MANAGER_ID,
a.DEPARTMENT_ID,
CONCAT(b.FIRST_NAME, CONCAT(' ', b.LAST_NAME)) MANAGER_NAME,
JOBS.JOB_TITLE,
DEPARTMENTS.DEPARTMENT_NAME
FROM
EMPLOYEES a
LEFT JOIN
JOBS
ON
a.JOB_ID = JOBS.JOB_ID
LEFT JOIN
EMPLOYEES b
ON
a.MANAGER_ID = b.EMPLOYEE_ID
LEFT JOIN
DEPARTMENTS
ON
a.DEPARTMENT_ID = DEPARTMENTS.DEPARTMENT_ID
ORDER BY
a.EMPLOYEE_ID
ASC
I tried testing this query in the Oracle SQL Developer and it works, so I don't know if JPA automatically inserts an open left parenthesis in the query. The Play console doesn't really help much since it doesn't point out exactly where the ORA-00907 error is trapped in.
Related
I have the following Hibernate HQL query:
select t from Term t join ApprovedCourse ap on t.id = ap.term.id group by t order by t desc
It's failing with the
ORA-00979: not a GROUP BY expression
error because Oracle insists that all select values be in the group by. Hibernate, of course, is hiding the various fields of the Term object from us, letting us deal with it as a Term and not Term.id. (This query works on Postgres, by the way. Postgres is more liberal about its group by requirements.)
Hibernate is producing the following SQL:
select term0_.id as id1_12_, term0_.semester_id as semester_id2_12_, term0_.year_id as year_id3_12_
from term term0_
inner join approved_course approvedco1_
on (term0_.id=approvedco1_.term_id)
group by term0_.id
order by term0_.id desc
I've tried just removing the select t from the start of the query, but then Hibernate assumes that I'm selecting both the Term and ApprovedCourse objects, and that makes things worse.
So how do I make this work in a Hibernate way?
I found that I could get what I want by replacing the group by clause with a distinct in the select clause. Here's the resulting query:
select distinct(t) from Term t join ApprovedCourse ap on t.id = ap.term.id order by t desc
I have the following query , I want to load only the data where last_update_date is greater than one of the value, I delure the value in correct way and its working in SQL Server data source but when I use Oracle date source its not working. Also I try to change the quotation mark with :VARIABLENAME it gives me this error:
not all variables bound
SELECT
PAPF.NATIONAL_IDENTIFIER NatnlIdNum,
PAY.PAYROLL_NAME PayrollName,
DEP.NAME DepartmentName,
PER_ASSIGNMENT_STATUS_TYPES_TL.USER_STATUS EmploymentStatDesc,
EMPLOYMENT_CATEGORY.MEANING EmploymentCatDesc,
PER_POSITION_DEFINITIONS.SEGMENT4 PositionName,
PAAF.EFFECTIVE_START_DATE EffectiveStartDate,
PAAF.EFFECTIVE_END_DATE EffectiveEndDate,
PG.NAME GradeName,
FROM PER_ALL_PEOPLE_F PAPF
INNER JOIN PER_ALL_ASSIGNMENTS_F PAAF
ON PAPF.PERSON_ID=PAAF.PERSON_ID
LEFT JOIN PAY_ALL_PAYROLLS_F PAY
ON PAAF.PAYROLL_ID=PAY.PAYROLL_ID
AND TRUNC(SYSDATE) BETWEEN PAY.EFFECTIVE_START_DATE
AND PAY.EFFECTIVE_START_DATE
LEFT JOIN PAY_PEOPLE_GROUPS PPG
ON PAAF.PEOPLE_GROUP_ID=PPG.PEOPLE_GROUP_ID
LEFT JOIN HR_ALL_ORGANIZATION_UNITS DEP
ON PPG.SEGMENT2=DEP.ORGANIZATION_ID
LEFT JOIN fnd_lookup_values EMPLOYMENT_CATEGORY
ON PAAF.EMPLOYMENT_CATEGORY=EMPLOYMENT_CATEGORY.lookup_code
AND EMPLOYMENT_CATEGORY.language='AR'
AND EMPLOYMENT_CATEGORY.lookup_type='EMP_CAT'
LEFT JOIN PER_ASSIGNMENT_STATUS_TYPES_TL
ON PAAF.ASSIGNMENT_STATUS_TYPE_ID=PER_ASSIGNMENT_STATUS_TYPES_TL.ASSIGNMENT_STATUS_TYPE_ID
AND PER_ASSIGNMENT_STATUS_TYPES_TL.language='AR'
LEFT JOIN HR_ALL_POSITIONS_F
ON PAAF.POSITION_ID=HR_ALL_POSITIONS_F.POSITION_ID
AND TRUNC(SYSDATE) BETWEEN HR_ALL_POSITIONS_F.EFFECTIVE_START_DATE
AND HR_ALL_POSITIONS_F.EFFECTIVE_START_DATE
LEFT JOIN PER_POSITION_DEFINITIONS
ON HR_ALL_POSITIONS_F.POSITION_DEFINITION_ID=PER_POSITION_DEFINITIONS.POSITION_DEFINITION_ID
LEFT JOIN PER_GRADES PG
ON PAAF.GRADE_ID=PG.GRADE_ID
LEFT JOIN HR_ALL_ORGANIZATION_UNITS SCHOOL
ON PPG.SEGMENT5=SCHOOL.ORGANIZATION_ID
LEFT JOIN HR_ALL_ORGANIZATION_UNITS ED
ON PPG.SEGMENT6=ED.ORGANIZATION_ID
WHERE TRUNC(SYSDATE) BETWEEN PAPF.EFFECTIVE_START_DATE
AND PAPF.EFFECTIVE_END_DATE
AND PAAF.LAST_UPDATE_DATE >?
Parameters cannot be extracted from the SQL command. The provider might not help to parse parameter information from the command. In that case, use the "SQL command from variable" access mode, in which the entire SQL command is stored in a variable. ORA-00920: invalid relational operator (OraOLEDB)
You can build the query in a string variable, then use the "SQL command from variable" option in the OLE DB Source and add the parameter in the query. However when doing this, make sure that the date format passed into the Oracle data source is the date format that is expected. To concatenate the date parameter within the string variable holding the SQL, it will need to be cast to a string, the format will still be preserved, however this doesn't guarantee that it will be passed as a date data type and casting may be necessary. Also, note that the string casting function (DT_STR, number of characters, code page) will return an error if the length of the string that's converted is longer than the specified length and it's subsequently truncated. An example expression for the SQL in a string variable follows.
"SELECT
PAPF.NATIONAL_IDENTIFIER NatnlIdNum,
PAY.PAYROLL_NAME PayrollName,
DEP.NAME DepartmentName,
PER_ASSIGNMENT_STATUS_TYPES_TL.USER_STATUS EmploymentStatDesc,
EMPLOYMENT_CATEGORY.MEANING EmploymentCatDesc,
PER_POSITION_DEFINITIONS.SEGMENT4 PositionName,
PAAF.EFFECTIVE_START_DATE EffectiveStartDate,
PAAF.EFFECTIVE_END_DATE EffectiveEndDate,
PG.NAME GradeName,
FROM PER_ALL_PEOPLE_F PAPF
INNER JOIN PER_ALL_ASSIGNMENTS_F PAAF
ON PAPF.PERSON_ID=PAAF.PERSON_ID
LEFT JOIN PAY_ALL_PAYROLLS_F PAY
ON PAAF.PAYROLL_ID=PAY.PAYROLL_ID
AND TRUNC(SYSDATE) BETWEEN PAY.EFFECTIVE_START_DATE
AND PAY.EFFECTIVE_START_DATE
LEFT JOIN PAY_PEOPLE_GROUPS PPG
ON PAAF.PEOPLE_GROUP_ID=PPG.PEOPLE_GROUP_ID
LEFT JOIN HR_ALL_ORGANIZATION_UNITS DEP
ON PPG.SEGMENT2=DEP.ORGANIZATION_ID
LEFT JOIN fnd_lookup_values EMPLOYMENT_CATEGORY
ON PAAF.EMPLOYMENT_CATEGORY=EMPLOYMENT_CATEGORY.lookup_code
AND EMPLOYMENT_CATEGORY.language='AR'
AND EMPLOYMENT_CATEGORY.lookup_type='EMP_CAT'
LEFT JOIN PER_ASSIGNMENT_STATUS_TYPES_TL
ON PAAF.ASSIGNMENT_STATUS_TYPE_ID=PER_ASSIGNMENT_STATUS_TYPES_TL.ASSIGNMENT_STATUS_TYPE_ID
AND PER_ASSIGNMENT_STATUS_TYPES_TL.language='AR'
LEFT JOIN HR_ALL_POSITIONS_F
ON PAAF.POSITION_ID=HR_ALL_POSITIONS_F.POSITION_ID
AND TRUNC(SYSDATE) BETWEEN HR_ALL_POSITIONS_F.EFFECTIVE_START_DATE
AND HR_ALL_POSITIONS_F.EFFECTIVE_START_DATE
LEFT JOIN PER_POSITION_DEFINITIONS
ON HR_ALL_POSITIONS_F.POSITION_DEFINITION_ID=PER_POSITION_DEFINITIONS.POSITION_DEFINITION_ID
LEFT JOIN PER_GRADES PG
ON PAAF.GRADE_ID=PG.GRADE_ID
LEFT JOIN HR_ALL_ORGANIZATION_UNITS SCHOOL
ON PPG.SEGMENT5=SCHOOL.ORGANIZATION_ID
LEFT JOIN HR_ALL_ORGANIZATION_UNITS ED
ON PPG.SEGMENT6=ED.ORGANIZATION_ID
WHERE TRUNC(SYSDATE) BETWEEN PAPF.EFFECTIVE_START_DATE
AND PAPF.EFFECTIVE_END_DATE
AND PAAF.LAST_UPDATE_DATE > " + (DT_STR, 25, 1252)#[$Package:YourDateParameter]
I have a query that consists of a join between two tables. When it is an inner join, the query works fine. However, when I change it to an outer join, it throws an error as if the secondary table was not defined in the query.
Here is what I mean:
select a.unit
, a.data_date
from (
select unit
, person
, data_date
from the_data
) a
join personnel b
on (
b.person = a.person
and b.first_date <= a.data_date
and b.last_date >= a.data_date
)
the_data and personnel are tables
This works as written, but if you change the join to a left join, it reports that a.data_date is an invalid identifier (and if you rewrite the ON clause so the top line is at the bottom, it will say that a.person is invalid).
I vaguely remember coming across this once before, and it turned out to be an internal Oracle bug.
The database is 64-bit version 11.2.0.4.0.
looking for solution on my sql query error.I'm trying to create second cascading Input Control in JaspersoftServer. The first Input Control works fine, however when I try to create a second cascade IC it returns with the error. I have 3 tables (user, client, user_client), many to many, so 1 linked table (user_client) between them.The 1st Input Control (client) - works well, end user will select the client, the client can have many users, so cascade is the key. Also, as the output, I would like to get not the user_id, but user's firstname and the lastname as one column field. And here is where i'm stuck. I'm pretty sure it is simple syntaxis error, but spent a good couple of hours to figure out what is wrong with it. Is anyone can have a look at it please and indicate where is the problem in my query ?! So far I've done:
select distinct
u.user_id,(
SELECT CONCAT(first_name, surname) AS user_name from tbl_user ),
c.client_id
FROM tbl_user u
left join tbl_user_client uc
on uc.user_id = u.user_id
left join tbl_client c
on c.client_id = uc.client_id
where c.client_id = uc.client_id
order by c.client_id
Thank you in advance.
P.S. JasperServer + Oracle 11g
You're doing an uncorrelated subquery to get the first/last name from the user table. There is no relationship between that subquery:
SELECT CONCAT(first_name, surname) AS user_name from tbl_user
... and the user ID in the main query, so the subquery will attempt to return every first/last name for all users, for every row your joins find.
You don't need to do a subquery at all as you already have the tbl_user information available:
select u.user_id,
CONCAT(u.first_name, u.surname) AS user_name
c.client_id
FROM tbl_user u
left join tbl_user_client uc
on uc.user_id = u.user_id
left join tbl_client c
on c.client_id = uc.client_id
where c.client_id = uc.client_id
order by c.client_id
If you want to put a space between the first and last name you'll either need nested concat() calls, since that function only takes two arguments:
select u.user_id,
CONCAT(u.first_name, CONCAT(' ', u.surname)) AS user_name
...
... or perhaps more readably use the concatenation operator instead:
select u.user_id,
u.first_name ||' '|| u.surname AS user_name
...
If the first control has selected a client and this query is supposed to find the users related to that client, you're joining the tables the wrong way round, aren't you? And you aren't filtering on the selected client - but no idea how that's actually implemented in Jasper. Maybe you do want the entire list and will filter it on the Jasper side.
I have a Oracle command as
Select offers.OFR_STAT,OFFER_DETAILS.*,PrevData.*
From offers
INNER JOIN OFFER_DETAILS
ON OFFER_DETAILS.OFFER_ID=offers.OFFER_ID
INNER JOIN (
SELECT InnerOfrDtl.*
FROM OFFER_DETAILS as InnerOfrDtl
WHERE InnerOfrDtl.offer_id=offers.offer_id
) AS PrevData
ON PrevData.SCHEDULE_TYPE=OFFER_DETAILS.SCHEDULE_TYPE
While running I got an error message as "missing right parenthesis".
Here I wanted to use a sub-query for Inner join.
Try removing the AS after the close parenthesis and before PrevData. As I understand it, Oracle does not allow the keyword AS for table aliases.
The query does not require a sub-query. You could write:
SELECT o.OFR_STAT, d.*, p.*
FROM offers o
JOIN Offer_Details d ON d.Offer_ID = o.Offer_ID
JOIN Offer_Details p
ON p.Offer_ID = o.Offer_ID
AND p.Schedule_Type = d.Schedule_Type
I'm not wholly convinced that the query makes sense, but that's a different matter altogether.
Remove the AS keyword for the sub-query, this is not supported by Oracle:
Select offers.OFR_STAT,OFFER_DETAILS.*,PrevData.*
From offers
INNER JOIN OFFER_DETAILS
ON OFFER_DETAILS.OFFER_ID=offers.OFFER_ID
INNER JOIN (
SELECT InnerOfrDtl.*
FROM OFFER_DETAILS as InnerOfrDtl
WHERE InnerOfrDtl.offer_id=offers.offer_id
) PrevData -- <<<< here is the change
ON PrevData.SCHEDULE_TYPE=OFFER_DETAILS.SCHEDULE_TYPE
Older versions of Oracle (8i for sure, probably 9i too) have trouble with explicit INNER JOINs. Replacing them with implicit (non-ANSI?) inner joins can fix the problem.
https://forums.oracle.com/forums/thread.jspa?threadID=328028