CURSOR CUR_OP_BAL IS
SELECT GLD.GOLDSMITH_ID, RTRIM(LTRIM(PTY.LC_PARTY_FIRST_NAME)) || ' ' ||
RTRIM(LTRIM(NVL(PTY.LC_PARTY_LAST_NAME,''))) AS GOLDSMITH_NAME,
PTY.LC_PARTY_SHORT_NAME
FROM PUR_GOLDSMITH_ML_T GLD
INNER JOIN COM_LOCAL_PARTY_MST_T PTY ON GLD.GOLDSMITH_ID = PTY.LC_PARTY_ID
ORDER BY GOLDSMITH_NAME;
in above code i am getting compile error :
Error(16,33): PLS-00103: Encountered the symbol "INNER" when expecting one of the following:
, ; for group having intersect minus order start union where connect
Please give me a proper solution
Not Sure about the issue but what i could see in the code is using of alias name "GOLDSMITH_NAME" in order by statement which is not possible, it can be possible only if you write one more select statement on top of it, some thing like :
select * from
(SELECT GLD.GOLDSMITH_ID, RTRIM(LTRIM(PTY.LC_PARTY_FIRST_NAME)) || ' ' ||
RTRIM(LTRIM(NVL(PTY.LC_PARTY_LAST_NAME,''))) AS GOLDSMITH_NAME,
PTY.LC_PARTY_SHORT_NAME
FROM PUR_GOLDSMITH_ML_T GLD
INNER JOIN COM_LOCAL_PARTY_MST_T PTY ON GLD.GOLDSMITH_ID = PTY.LC_PARTY_ID
)
ORDER BY GOLDSMITH_NAME;
Related
I'm getting the error:
TableName is neither present in the group by, nor is it an aggregate
function. Add to group by or wrap in first() (or first_value) if you
don't care which value you get.;
When I execute the following code in Databricks SQL
SELECT
ts_originationopportunity,
concat_ws(distinctreferrals.referralcompanycontact,'; ') AS referralcompanycontacts
FROM
(SELECT DISTINCT
ts_originationopportunity,
IFNULL(ts_referralcontactname + ' at ','') + ts_referralcompanyname AS referralcompanycontact
FROM baseorigination.ts_referralsource) distinctreferrals
GROUP BY ts_originationopportunity
I had already received assistance with a similar question by #Tim Biegeleisen, however when applied the suggested code from the previous question I get no results from 'referralcompanycontact'
SELECT
ts_originationopportunity,
array_join(collect_set(distinctreferrals.referralcompanycontact),'; ') AS referralcompanycontacts
FROM
(SELECT DISTINCT
ts_originationopportunity,
IFNULL(ts_referralcontactname + ' at ','') + ts_referralcompanyname AS referralcompanycontact
FROM baseorigination.ts_referralsource) distinctreferrals
GROUP BY ts_originationopportunity
Any thoughts?
I have now tried the following:
SELECT
ts_referralsource.ts_originationopportunity
,CONCAT_WS(ts_referralsource.ts_referralcontactname, ' at ', ts_referralsource.ts_referralcompanyname), ';') AS referralcompanycontact
FROM baseorigination.ts_referralsource
GROUP BY ts_referralsource.ts_originationopportunity
But getting the error:
== SQL ==
SELECT
ts_referralsource.ts_originationopportunity
,CONCAT_WS(ts_referralsource.ts_referralcontactname, ' at ', ts_referralsource.ts_referralcompanyname), ';') AS referralcompanycontact
------------------------------------------------------------------------------------------------------------^^^
ok, I almost figured it out.
The following will get me my results without the groupby
SELECT
ts_originationopportunity
,CONCAT(ts_referralcontactname, ' at ', ts_referralcompanyname) AS referralcompanycontact
FROM baseorigination.ts_referralsource
-- GROUP BY ts_referralsource.ts_originationopportunity
However, with the groupby I the following error:
'spark_catalog.baseorigination.ts_referralsource.ts_referralcontactname' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
I got a similar error when I tried to use group by in a similar manner. The following is a sample table on which I have tried to use similar query:
When I tried the following query (similar to yours), I got the same error:
SELECT a,CONCAT(b, ' at ', c) AS new FROM demo GROUP BY a
This is because you are not aggregating the columns that you are selecting i.e., b and c in the above query (ts_referralcontactname and ts_referralcompanyname in your case).
So as suggested in the error message, you have to apply an appropriate aggregate function. I have used first in my case and got the desired result.
SELECT a,CONCAT(first(b), ' at ', first(c)) AS new FROM demo GROUP BY a
Now, since you are getting desired result even without group by, change your query as shown below:
SELECT
ts_originationopportunity
,CONCAT(first(ts_referralcontactname), ' at ', first(ts_referralcompanyname)) AS referralcompanycontact
FROM baseorigination.ts_referralsource GROUP BY ts_referralsource.ts_originationopportunity
I am compiling this Function but getting ERROR : missing ORDER BY expression in the window specification
CREATE OR REPLACE FUNCTION WFir_get_act_section_cd(firnum IN NUMBER,langcd IN NUMBER) RETURN VARCHAR2
as
ACTSEC VARCHAR2(1500);
BEGIN
begin
--- ERROR START
select ltrim(max(sys_connect_by_path(NVL(act_long,' ') || '/' || NVL(section,' '),',')),',') as FIR_ACT_SEC into ACTSEC from(select NVL(act_long,' ') || '/' || NVL(section,' '), row_number() over() rn from rep_fir_sections sec
INNER JOIN m_act a on sec.act_cd = a.act_cd
INNER JOIN m_section c on sec.section_cd = c.section_code
and FIR_REG_NUM = FIRNum
and a.lang_cd = langcd) WHERE ROWNUM <=1 start with rn = 1
connect by prior rn = rn -1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
end;
return ACTSEC;
END;
When we are compiling above function after migrate this function form MYSQL to Oracle i am getting error "missing ORDER BY expression in the window specification"
I don't know why i am getting this ERROR, Please help me to resolve this ERROR
Row_number() over () is incorrect.
order by is REQUIRED for row_number to work.
Row_number() over (order by Null /*or you decide what field list*/) .
To assign a row_number you have to specify order by some column. The system doesn't know what row to assign to #1 if you don't specify an order for the system to put them into. Even order by null or order by 1 should work; but you'll probably want a specific field or fields to order by.
Put another way, order by isn't optional on a Row_number window function.
Doc Link
"...
ROW_NUMBER is an analytic function. It assigns a unique number to each row to which it is applied (either each row in the partition or each row returned by the query), in the ordered sequence of rows specified in the order_by_clause, beginning with 1. ..."
This implies without an order by, no row number can be assigned.
I have a problem, I don't understand why do I have this error..
The problem is in the creation of the cursor, but i don't understand why he says that missing a right parentesis...
This is my code :
CREATE OR REPLACE FUNCTION classementEtudiantSemestre( p_idEtudiant IN Etudiants.idEtudiant%TYPE, p_idSemestre IN Semestres.idSemestre%TYPE) RETURN NUMBER IS
CURSOR cur_lesmoys IS (
SELECT DISTINCT moyenneEtudiantSemestreAvecAbs(idEtudiant, idSemestre)
FROM ETUDIANTS E
JOIN GROUPES G ON G.idGroupe=E.idGroupe
JOIN SEMESTRES S ON G.idPromotion = S.idPromotion
WHERE idSemestre=p_idSemestre
ORDER BY moyenneEtudiantSemestreAvecAbs(idEtudiant, idSemestre) DESC
);
u_classement NUMBER:=1;
BEGIN
FOR rty_lesmoys IN cur_lesmoys LOOP
IF rty_lesmoyes.moyenneEtudiantSemestreAvecAbs(idEtudiant, idSemestre)=moyenneEtudiantSemestreAvecAbs(p_idEtudiant, p_idSemestre) THEN
RETURN u_classement;
ELSE
u_classement := u_classement +1;
END IF;
END LOOP;
END;
ORACLE ERRORS :
3/23 PL/SQL: SQL Statement ignored
9/31 PL/SQL: ORA-00907: missing right parenthesis
Help me please..
Does this work (i.e. with no brackets and naming the calculated column)?
CURSOR cur_lesmoys IS
SELECT DISTINCT moyenneEtudiantSemestreAvecAbs(idEtudiant, idSemestre) AS resultCol
FROM ETUDIANTS E
JOIN GROUPES G ON G.idGroupe=E.idGroupe
JOIN SEMESTRES S ON G.idPromotion = S.idPromotion
WHERE idSemestre=p_idSemestre
ORDER BY moyenneEtudiantSemestreAvecAbs(idEtudiant, idSemestre) DESC
;
If it's still not working, make sure this query works, you might have mistyped the name of a table/column
SELECT DISTINCT moyenneEtudiantSemestreAvecAbs(idEtudiant, idSemestre)
FROM ETUDIANTS E
JOIN GROUPES G ON G.idGroupe=E.idGroupe
JOIN SEMESTRES S ON G.idPromotion = S.idPromotion
WHERE idSemestre=p_idSemestre
ORDER BY moyenneEtudiantSemestreAvecAbs(idEtudiant, idSemestre) DESC
It's better to focus on the first error, the second one can often be caused by the first and be confusing.
I have tried the following query within HUE's Beeswax Query Editor:
SET MAXDATE=(SELECT MAX(DATA_DAY) FROM DB1.DESTINATION_TABLE);
SELECT COUNT(*) FROM DB2.SOURCE_TABLE
WHERE YEAR(DATA_DAY) >= '2015'
AND DATA_DAY > ${HIVECONF:MAXDATE};
This query will not run and produces the following error message:
FAILED: ParseException line 1:4 missing KW_ROLE at 'MAXDATE' near 'MAXDATE' line 1:11 missing EOF at '=' near 'MAXDATE'
Any advice on what the problem is? I don't understand what the KW_ROLE message means.
I come from a SQL Server background and would just run the following within SQL Server, but am trying to find a functional Hadoop/Hive equivalent.
SELECT COUNT(*) FROM DB2.SOURCE_TABLE
WHERE YEAR(DATA_DAY) >= '2015'
AND DATA_DAY > (SELECT MAX(DATA_DAY) FROM DB1.DESTINATION_TABLE)
Query which you have tried contains syntax issue. HiveConf should surrounded by single quotes.
SET MAXDATE=(SELECT MAX(DATA_DAY) FROM DB1.DESTINATION_TABLE);
SELECT COUNT(*) FROM DB2.SOURCE_TABLE
WHERE YEAR(DATA_DAY) >= '2015'
AND DATA_DAY > '${HIVECONF:MAXDATE}';
As far as I know, hive support the following syntax too.
SELECT COUNT(*) FROM DB2.SOURCE_TABLE a
JOIN
(SELECT MAX(DATA_DAY) AS max_date FROM DB1.DESTINATION_TABLE) b
WHERE YEAR(a.DATA_DAY) >= '2015'
AND a.DATA_DAY > b.max_date;
But it's not a good implementation if there are bunches of data on DB1.DESTINATION_TABLE.
In such case each query would task lots of sub-querys in SELECT MAX(DATA_DAY) FROM DB1.DESTINATION_TABLE.
If possible, you could store your SELECT MAX(DATA_DAY) FROM DB1.DESTINATION_TABLE result in another table, maybe Max_table.
Then the sql would be like this:
SELECT COUNT(*) FROM DB2.SOURCE_TABLE
JOIN Max_table
WHERE YEAR(DB2.SOURCE_TABLE.DATA_DAY) >= '2015' and
DB2.SOURCE_TABLE.DATA_DAY > (Max_table.DATA_DAY)
Please find the below query. When I run this query I am getting an ORA-00907: missing right parenthesis error. I am unable to understand the problem on this query. Please give me the solution for this error. I have read some related topics on this topic. but, I didn't get the right solution. I am using Oracle 10g version.
The query:
SELECT A.City||'.' AS AAddress,
M_InOut_Header_v.Org_Location_ID AS Org_Location_ID,
M_InOut_Header_v.ContactName,
M_InOut_Header_v.Title,
M_InOut_Header_v.EMail,
M_InOut_Header_v.Phone,
M_InOut_Header_v.BPGreeting,
M_InOut_Header_v.Name2,
M_InOut_Header_v.Name,
B.City||'.' AS BAddress,
M_InOut_Header_v.C_Location_ID AS C_Location_ID,
M_InOut_Header_v.BPContactGreeting,
--M_InOut_Header_v.BPGreeting,
--M_InOut_Header_v.Name,
--M_InOut_Header_v.Name2,
M_InOut_Header_v.Address1,
M_InOut_Header_v.Address2,
M_InOut_Header_v.Address3,
M_InOut_Header_v.Address4,
M_InOut_Header_v.City,
M_InOut_Header_v.POSTAL1,
M_InOut_Header_v.CountryName,
--M_InOut_Header_v.BPContactGreeting,
--M_InOut_Header_v.Name,
M_InOut_Header_v.OrderRemarks,
(SELECT NVL(C_Order.DocumentNo,'')||'
- '||NVL(TRIM(TO_CHAR(C_Order.DateOrdered,'DD/MM/YYYY')),'')
FROM C_Order
WHERE M_InOut_Header_v.C_Order_ID=C_Order.C_Order_ID
) AS CC_Order_ID,
M_InOut_Header_v.C_Order_ID AS C_Order_ID,
M_InOut_Header_v.OrderType,
M_InOut_Header_v.ReferenceNo,
M_InOut_Header_v.POReference,
(SELECT NVL(M_Warehouse.Name,'')
FROM M_Warehouse
WHERE M_InOut_Header_v.M_Warehouse_ID=M_Warehouse.M_Warehouse_ID
) AS DM_Warehouse_ID,
M_InOut_Header_v.M_Warehouse_ID AS M_Warehouse_ID,
(SELECT NVL(M_Shipper.Name,'')
FROM M_Shipper
WHERE M_InOut_Header_v.M_Shipper_ID=M_Shipper.M_Shipper_ID
) AS EM_Shipper_ID,
M_InOut_Header_v.M_Shipper_ID AS M_Shipper_ID,
M_InOut_Header_v.Vehicle_No_BizInt,
M_InOut_Header_v.TrackingNo,
M_InOut_Header_v.Permit_No_BizInt,
M_InOut_Header_v.LR_Number_BizInt,
M_InOut_Header_v.FREIGHTCOSTRULE2,
M_InOut_Header_v.FreightAmt,
M_InOut_Header_v.POREMARKS,
M_InOut_Header_v.NoPackages,
M_InOut_Header_v.Gross_Weight_BizInt,
M_InOut_Header_v.UOMSymbol,
M_InOut_Header_v.SalesRepPhone,
M_InOut_Header_v.SalesRepEmail,
M_InOut_Header_v.DocumentType,
InOut_Header_v.DocumentNo,
M_InOut_Header_v.MovementDate,
M_InOut_Header_v.Description,
(SELECT NVL(M_InOut.DocumentNo,'')||'
- '||NVL(TRIM(TO_CHAR(M_InOut.MovementDate,'DD/MM/YYYY')),'')
FROM M_InOut
WHERE M_InOut_Header_v.M_InOut_ID=M_InOut.M_InOut_ID
) AS FM_InOut_ID,
M_InOut_Header_v.M_InOut_ID AS M_InOut_ID,
M_InOut_Header_v.DocumentTypeNote,
M_InOut_Header_v.REMARKS1,
M_InOut_Header_v.REMARKS2,
M_InOut_Header_v.REMARKS3,
M_InOut_Header_v.REMARKS4
FROM M_InOut_Header_v
LEFT OUTER JOIN C_Location A
ON (M_InOut_Header_v.Org_Location_ID=A.C_Location_ID)
LEFT OUTER JOIN C_Location B
ON (M_InOut_Header_v.C_Location_ID=B.C_Location_ID)
WHERE (M_InOut_Header_v.M_InOut_ID=1002241)
AND M_InOut_Header_v.AD_Client_ID IN (1000008,0)
AND M_InOut_Header_v.AD_Org_ID IN (1000099,1000098,0,1000100,1000096,1000097)
AND (A.C_Location_ID IS NULL
OR A.C_Location_ID NOT IN (
SELECT PA.Record_ID FROM AD_Private_Access AS PA
WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144
AND PA.IsActive = 'Y'
))
AND ( B.C_Location_ID IS NULL
OR B.C_Location_ID NOT IN (
SELECT ADP.Record_ID FROM AD_Private_Access AS ADP
WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144
AND ADP.IsActive = 'Y'
))
ORDER BY M_InOut_Header_v.DocumentNo;
This gives me:
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 80 Column: 26
But I didn't find any mistake in that line. I think it is syntactically correct.
The line number is slightly misleading, but it's pointing to the start of the problem. The issue is with these two subqueries:
SELECT PA.Record_ID FROM AD_Private_Access AS PA
WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144
AND PA.IsActive = 'Y'
and:
SELECT ADP.Record_ID FROM AD_Private_Access AS ADP
WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144
AND ADP.IsActive = 'Y'
You cannot use AS to mark an alias for a table name, only (optionally) for a column name or expression. There isn't actually a missing parenthesis. It's hard to know exactly what the parser is thinking, but in this case it looks like it's trying to interpret the AS PA as a column alias for that subquery, and that implies that the subquery should have ended by now, and so there should have been a close parenthesis already. (Another option might have been to try to treat AS as the table alias, but then it would have had to try to decide what PA meant; plus AS is a keyword so it wouldn't be valid as an alias name anyway).
Just remove the AS keyword from both of those and it'll work (or move on to another error).
SELECT PA.Record_ID FROM AD_Private_Access PA
...
and:
SELECT ADP.Record_ID FROM AD_Private_Access ADP
...