Using count within another select - hql

I get this exception:
<AST>:0:0: unexpected AST node: query
right-hand operand of a binary operator was null
<AST>:0:0: unexpected end of subtree
right-hand operand of a binary operator was null
While running this HQL query
select p.nicenumber from thosenumbers p, thesenumbers w where p.datnumber - (select count(*) from thatnumbers b where b.thisnumber = '123' and b.coolnumber = w.coolnumber) > 0
Its a syntax issue since it runs perfectly in my database visualizer

i was overthinking it and the answer was simply where p.datnumber > (select count(*) from thatnumbers b where b.thisnumber = '123' and b.coolnumber = w.coolnumber)

Related

using alias with type in oracle sql rising ORA-00907: missing right parenthesis error

I have following code:
select a.DATA_ID,
b.FILE_NAME, b.CREATION_DATE,
CASE WHEN a.cdvs_data is null THEN 'N' ELSE 'Y' END AS IS_DELETABLE from cl_dat_dst_his c inner join CL_DAT_VERSION a on c.CL_DAT_VERSION_ID=a.CL_DAT_VERSION_ID
inner join cl_history b on c.CDVS_HIST_ID = b.CL_HIS_ID where b.CL_HIS_TABLE_ID=14424 ORDER BY b.CREATION_DATE DESC
However, when i wrap the result inside the TYPE as following:
select uploaded_data(a.DATA_ID,
b.FILE_NAME, b.CREATION_DATE,
CASE WHEN a.cdvs_data is null THEN 'N' ELSE 'Y' END AS IS_DELETABLE) from cl_dat_dst_his c inner join CL_DAT_VERSION a on c.CL_DAT_VERSION_ID=a.CL_DAT_VERSION_ID
inner join cl_history b on c.CDVS_HIST_ID = b.CL_HIS_ID where b.CL_HIS_TABLE_ID=14424 ORDER BY b.CREATION_DATE DESC
It is showing following error:
ORA-00907: missing right parenthesis
could you give me hint what is the problem?
Remove the AS IS_DELETABLE column alias, it is invalid syntax inside the type constructor.
select uploaded_data(
a.DATA_ID,
b.FILE_NAME,
b.CREATION_DATE,
CASE WHEN a.cdvs_data is null THEN 'N' ELSE 'Y' END -- AS IS_DELETABLE
)
from cl_dat_dst_his c
inner join CL_DAT_VERSION a
on c.CL_DAT_VERSION_ID=a.CL_DAT_VERSION_ID
inner join cl_history b
on c.CDVS_HIST_ID = b.CL_HIS_ID
where b.CL_HIS_TABLE_ID=14424
ORDER BY b.CREATION_DATE DESC

Syntax issues with pervasive SQL if statement used to determine left join on clause

Back Story: I am looking to do a left join based on if a condition is true with an if statement. However if it is false, I want to still join the said table in, but with the same columns or with a new set of columns. This query is being wrote for a Pervasive SQL DB.
This query is fairly large, without this particular issue it executes and returns the data sets as expected. Below is a snapshot of the issue I am currently running into..
SELECT A.ONUM, B.JN, C.SEQ, C.PN
From Z.OH
LEFT JOIN OL A ON Z.ONUM = A.ONUM
LEFT JOIN JH B ON A.ONUM = B.SNUM AND A.OLNUM = B.SLNUM AND B.CLSD <> 'Y'
LEFT JOIN JO C ON IF(A.LC <> 'ZY', B.JN = C.JN, LEFT(B.C_PO, 6) = C.JN OR B.JN = C.JN) AND C.OP_T NOT IN ('Z','C')
WHERE Z.OT <> 'T' AND C.PN NOT IN (SELECT X.PN FROM JH X WHERE B.JN = X.JN)
Again, very summarized version with lots of joins/filters/select statement removed.
I am running into issues on the join with the IF statement. Without the if statement, the query executes as expected.
The original join being: B.JN = C.JN AND C.OP_T NOT IN ('Z', 'C')
When executing the query in PCC it would give the following syntax error at the following point: "B.JN << ??? >> = C.JN"
I tried switching over to an OR statement as shown below, but the run time of the query made it an impossible choice.
LEFT JOIN JO C ON
(B.JN = C.JN) OR (A.LC = 'ZY' AND LEFT(B.C_PO, 6) = C.JN)
AND C.OP_T NOT IN ('Z','C')
Checking the documentation, it looks like the query on the if statement is following the correct syntax...
Most simple solution would be to avoid the IF in the WHERE-clause, and do:
SELECT A.ONUM, B.JN, C.SEQ, C.PN
From Z.OH
LEFT JOIN OL A ON Z.ONUM = A.ONUM
LEFT JOIN JH B ON A.ONUM = B.SNUM AND A.OLNUM = B.SLNUM AND B.CLSD <> 'Y'
LEFT JOIN JO C ON (A.LC <> 'ZY' AND B.JN = C.JN) OR (A.LC = 'ZY' AND (LEFT(B.C_PO, 6) = C.JN OR B.JN = C.JN))
AND C.OP_T NOT IN ('Z','C')
WHERE Z.OT <> 'T' AND C.PN NOT IN (SELECT X.PN FROM JH X WHERE B.JN = X.JN)

Oracle error 923 when selecting hardcoded values for some columns in UNION ALL

I am facing oracle error 00923 while trying to retrieve hard coded values ('') in one of the sub-query that is a part of UNION ALL query.
select p.owner,
p.exception_id,
p.status,
p.product_id,
p.event_id
from exception p, exception c
where c.Parent_Id = p.Exception_Id
AND c.Owner_COID = p.Owner_COID
UNION ALL
select p.owner,
p.exception_id,
p.status,
'',
''
from exception p
and not exists (select * from bb_Exception c
WHERE c.Parent_Id = p.Exception_Id);
Could some one please help me resolve the issue?.
Thanks
No WHERE clause in the second half of the UNION ALL !
from exception p
and not exists (select * from b
should be
from exception p
where not exists (select * from b
Once you fix that, if p.product_id or p.event_id are numeric (as might be expected with IDs) then you should get this exception:
ORA-01790: expression must have same datatype as corresponding expression
The solution in to use null rather than empty string. Oracle treats them as equivalent but '' is a varchar2 datatype and null is not.

Hive String index out of range error

I am trying to execute this below query in Hive(cloudera),
select a.col1,a.col2
FROM t1 a LEFT SEMI JOIN (select * from t2 where y = 0) b on (a.col1 =b.x);
Below is the error I am getting,
Your query has the following error(s):
Error while compiling statement: FAILED: StringIndexOutOfBoundsException String index out of range: 0
I am getting this even if i run just select * from t2 where y = 0. But the same query is working fine in Impala. Any suggestion?
Thanks in advance.
The might have failed because there is an empty as in select

ORA-00905: missing keyword error oracle

Hi when i am trying to execute following oracle query I am getting
[Err] ORA-00905: missing keyword
CREATE VIEW MJNSXJJRW_view AS
SELECT B.oID AS "_oid", B.oTm AS "_otm"
FROM
(SELECT DISTINCT oID, oTm FROM MJNSXJJRW) B
LEFT JOIN MJNSXJJRW AS S0 ON
B.oID = S0.oID AND
S0.idx = 0 AND
S0.kID = "str_val" ;
The most likely issue is MJNSXJJRW AS S0. You use the AS keyword when defining column aliases, not when defining table aliases.
CREATE VIEW MJNSXJJRW_view AS
SELECT B.oID AS "_oid", B.oTm AS "_otm"
FROM
(SELECT DISTINCT oID, oTm FROM MJNSXJJRW) B
LEFT JOIN MJNSXJJRW S0 ON
B.oID = S0.oID AND
S0.idx = 0 AND
S0.kID = "str_val" ;
I'm assuming that "str_val" is a column, not a string literal. If it's the latter you should use single quotes.

Resources