ORA-00920 [42000]: invalid relational operator - sql

Here is the SQL Source Code for database selection that generates the following
error: "Query execution failed, Reason: SQL Error [920] [42000]:
ORA-00920: opérateur relationnel non valide.
Please Help!
WITH adr_siege as (
SELECT Nvl(adr.libadr, ' ') AS libadr, Nvl(adr.adress, ' ') AS adress,
Nvl(adr.codpos, ' ') AS codpos, Nvl(adr.locali, ' ') AS locali,
Nvl(adr.codpay, ' ') AS codpay
FROM gnx.tie
JOIN gnx.adr
ON adr.codsoc = tie.codsoc
AND adr.typtie = tie.typtie
AND adr.sigadr = tie.sigtie
AND typadr = 'COM'
WHERE tie.typtie = 'DEP'
AND tie.codsoc=1
AND tie.sigtie = '00000137'
)
SELECT Nvl(a.codpro, ' ') AS codpro, Nvl(a.nompro, ' ') AS nompro,
Nvl(ll.prix_achat, 0) AS prix_achat, Nvl(ll.qte, 0) AS qte,
Nvl(l.nom_fournisseur, ' ') AS nom_fournisseur, Nvl(m.raison, ' ') AS raison,
Nvl(concat(m.adresse1,' ' || m.adresse2), ' ') AS adresse_mag,
Nvl(m.cp, ' ') AS cp, Nvl(m.ville, ' ') AS ville,
Nvl(p.libelle, ' ') AS libelle,
Nvl(To_Char(c.date_validation, 'DD/MM/YYYY'), ' ') AS date_validation,
Nvl((
SELECT sum(fll.prix_achat * fll.qte)
FROM fourniture.frnt_livraison_ligne fll
WHERE fll.noliv
), 0) AS total_prix,
To_Char(SYSDATE, 'DD/MM/YYYY') AS date_edition,
Nvl(f.libadr, ' ') AS fou_lib_adr,
Nvl(f.tel, ' ') AS fou_tel,
Nvl(f.adress, ' ') AS fou_adr, Nvl(f.codpos, ' ') AS fou_cp,
Nvl(f.locali, ' ') AS fou_ville, Nvl(pf.libelle, ' ') AS fou_pays,
Nvl(to_char(p.date_livraison_s1, 'DD/MM/YYYY'), ' ') AS date_livraison_s1,
Nvl(to_char(p.date_livraison_s2, 'DD/MM/YYYY'), ' ') AS date_livraison_s2,
Nvl((
SELECT tbl.lib1
FROM gnx.tie
LEFT JOIN gnx.tbl
ON tbl.codtbl = 'mrg'
AND tbl.lib1 IS NOT NULL
AND tbl.codsoc=1
AND tbl.cletbl = tie.modrgl
WHERE tie.typtie = 'FOU'
AND tie.sigtie = l.code_fournisseur
AND tie.codsoc =1
), ' ') AS mode_paiement,
l.num_sous_periode,
adr_siege.*,
Nvl(m.nummag, ' ') AS nummag,
Nvl(m.tel1, ' ') AS tel1,
l.ref_gnx,
Nvl(tva.taux_tva, 0)/100 AS taux_tva,
Nvl(f.code, ' ') AS code_fournisseur,
(
CASE WHEN (m.lundi_ouverture != '0' OR m.mardi_ouverture != '0' OR m.mercredi_ouverture != '0'
OR m.jeudi_ouverture != '0' OR m.vendredi_ouverture != '0' OR m.samedi_ouverture != '0') THEN 1
ELSE 0
END
) AS AFFICH_HORRAIRE,
a.conditionnement,
a.refpro as REFPRO
FROM adr_siege, fourniture.frnt_livraison l
INNER JOIN fourniture.frnt_livraison_ligne ll ON ll.noliv = l.noliv
INNER JOIN fourniture.frnt_article a ON a.codpro = ll.codpro
INNER JOIN fourniture.frnt_commande c ON c.nocde = l.nocde
INNER JOIN polymag.magasin m ON m.nummag = c.nummag
INNER JOIN polymag.pays p ON p.code = m.codepays
LEFT JOIN fourniture.frnt_fournisseur f ON f.code =l.code_fournisseur
INNER JOIN polymag.pays pf ON pf.code = f.codpay
INNER JOIN fourniture.frnt_periode p ON p.noperiode = c.noperiode
LEFT JOIN fourniture.frnt_tva tva ON tva.code_pays_fou = f.codpay AND tva.code_pays_mag = m.codepays
WHERE l.type_livraison = 'FOU'
(we are selecting in schema named 'fournisseur')
Thank you in advance for your help.

problem is at line 25 because of WHERE fll.noliv that's without any relational operator like <,>,!,= after this statement.

TOTAL_PRIX seems to be invalid; look at its WHERE clause:
(
SELECT SUM(fll.prix_achat * fll.qte)
FROM fourniture.frnt_livraison_ligne fll
WHERE fll.noliv ), 0) AS total_prix,

Related

Could you help me to solve this simple join issue?i am new to sql so no idea what is wrong with this

SELECT LEVEL_A.VALUE,LEVEL_B.VALUE,LEVEL_C.VALUE,LEVEL_C.VALUE
FROM CUSP_VALUE_LIST_HEADER H
JOIN CUSP_VALUE_LIST_ITEM LEVEL_C
ON H.VALUE_LIST_HEADER_NO = LEVEL_C.VALUE_LIST_HEADER_NO
JOIN (SELECT I.VALUE, I.DESCRIPTION
FROM CUSP_VALUE_LIST_HEADER H
JOIN CUSP_VALUE_LIST_ITEM I
ON H.VALUE_LIST_HEADER_NO = I.VALUE_LIST_HEADER_NO
WHERE H.CAPTION = 'SERVER_ENTITY'
AND LOWER(NVL(I.DESCRIPTION, ' ')) NOT LIKE '%disabled%') LEVEL_A
ON LEVEL_A.VALUE = REGEXP_SUBSTR(LEVEL_C.VALUE, '[^#]+', 1, 1)
JOIN (SELECT I.VALUE, I.DESCRIPTION
FROM CUSP_VALUE_LIST_HEADER H
JOIN CUSP_VALUE_LIST_ITEM I
ON H.VALUE_LIST_HEADER_NO = I.VALUE_LIST_HEADER_NO
WHERE H.CAPTION = 'PurchaseType'
AND LOWER(NVL(I.DESCRIPTION, ' ')) NOT LIKE '%disabled%') LEVEL_B
ON LEVEL_B.VALUE = REGEXP_SUBSTR(LEVEL_C.VALUE, '[^#]+', 1, 1) || '#' ||
REGEXP_SUBSTR(LEVEL_C.VALUE, '[^#]+', 1, 2)
WHERE H.CAPTION = 'PurchaseSubCategoryList'
AND LOWER(NVL(LEVEL_C.DESCRIPTION, ' ')) NOT LIKE '%disabled%'
JOIN (SELECT I.VALUE, I.DESCRIPTION
FROM CUSP_VALUE_LIST_HEADER H
JOIN CUSP_VALUE_LIST_ITEM I
ON H.VALUE_LIST_HEADER_NO = I.VALUE_LIST_HEADER_NO
WHERE H.CAPTION = 'PurchaseCategoryList'
AND LOWER(NVL(I.DESCRIPTION, ' ')) NOT LIKE '%disabled%') LEVEL_D
ON LEVEL_D.VALUE = REGEXP_SUBSTR(LEVEL_C.VALUE, '[^#]+', 1, 1) || '#' ||
REGEXP_SUBSTR(LEVEL_C.VALUE, '[^#]+', 1, 2) || '#' || REGEXP_SUBSTR(LEVEL_C.VALUE, '[^#]+', 1, 3)
WHERE H.CAPTION = 'PurchaseSubCategoryList'
AND LOWER(NVL(LEVEL_C.DESCRIPTION, ' ')) NOT LIKE '%disabled%'
ORDER BY LEVEL_C.VALUE ASC;
First, where is the call of table "LEVEL_A" by some FROM command? This can be corrupting all code. When you input a name with dot and another one, it mean as 'tableName.columnName'. I hope help.

select in select inner join

I try to make an inner join on select. My select statement is like below
SELECT con.fpd_no,
con.contract_no,
cm.cust_name,
(select cm.cust_name, TRIM(cm.address) || ', ' || TRIM(cm.zipcode) || ', ' || TRIM(klm.kelurahan_desc) || ', ' || TRIM(kcm.kecamatan_desc) || ', ' || TRIM(kbm.kabupaten_desc) || ', ' || TRIM(prm.propinsi_desc)
from customer_master cm
inner join kelurahan_master klm on klm.kelurahan_id=cm.kelurahan_id
inner join kecamatan_master kcm on kcm.kecamatan_id=klm.kecamatan_id
inner join kabupaten_master kbm on kbm.kabupaten_id=kcm.kabupaten_id
inner join propinsi_master prm on prm.propinsi_id=kbm.propinsi_id;) as address,
con.principal_amount
FROM contract con
JOIN customer_master cm ON cm.cust_no = con.cust_no
WHERE con.deal_code = 'A005'
AND con.fpd_date BETWEEN '01-01-2016' AND '31-01-2016'
AND con.fpd_no = '0103006116'
AND con.objt_group = 'MOTOR';
but I get this error:
ORA-00911: invalid character.
try this:
remove semicolon on subselect and sure about select returns only one row
SELECT con.fpd_no, con.contract_no, cm.cust_name, (select distinct cm.cust_name, TRIM(cm.address) || ', ' || TRIM(cm.zipcode) || ', ' || TRIM(klm.kelurahan_desc) || ', ' || TRIM(kcm.kecamatan_desc) || ', ' || TRIM(kbm.kabupaten_desc) || ', ' || TRIM(prm.propinsi_desc)
from customer_master cm
inner join kelurahan_master klm on klm.kelurahan_id=cm.kelurahan_id
inner join kecamatan_master kcm on kcm.kecamatan_id=klm.kecamatan_id
inner join kabupaten_master kbm on kbm.kabupaten_id=kcm.kabupaten_id
inner join propinsi_master prm on prm.propinsi_id=kbm.propinsi_id) as address, con.principal_amount
FROM contract con
JOIN customer_master cm ON cm.cust_no = con.cust_no
WHERE con.deal_code = 'A005'
AND con.fpd_date BETWEEN '01-01-2016' AND '31-01-2016'
AND con.fpd_no = '0103006116'
AND con.objt_group = 'MOTOR';

Return newest row when several columns are the same

I have a very complex Union query that returns up to two rows. If the second through the 15th columns are identical in both records, I want to return the results of the second record. Otherwise, return the results of the first record which is the newest record. The goal is to return the newest name and address with a pending flag only if the data is not the same.
SELECT TOP 1
1 AS updatePending,
a.entity_number,
a.name_title,
a.name_first,
a.name_middle,
a.name_last,
a.name_suffix,
LTRIM(RTRIM(REPLACE(
LTRIM(RTRIM(ISNULL(a.name_first, ''))) +
CASE WHEN LEN(LTRIM(RTRIM(ISNULL(a.name_first, '')))) = 1 THEN '. ' ELSE ' ' END +
LTRIM(RTRIM(ISNULL(a.name_middle, ''))) +
CASE WHEN LEN(LTRIM(RTRIM(ISNULL(a.name_middle, '')))) = 1 THEN '. ' ELSE ' ' END +
LTRIM(RTRIM(ISNULL(a.name_last, ''))) + ' ' +
LTRIM(RTRIM(ISNULL(a.name_suffix, '')))
,' ',' '))) AS name_full,
NULLIF(LTRIM(RTRIM(
LTRIM(RTRIM(ISNULL(a.company, ''))) +
LTRIM(RTRIM(ISNULL(a.firm_name, ''))))),'') AS company,
a.address1,
a.mailing_address,
a.city,
a.state,
a.zip_code AS zipcode,
a.internet_address AS email_address,
a.time_stamp
FROM statebar.dbo.STAGING_Address_Change_Request a
INNER JOIN Member m ON m.entity_number = a.entity_number
WHERE a.entity_number = (
SELECT m.entity_number
FROM Member m
INNER JOIN Named_Entity ne ON (ne.entity_number = m.entity_number)
WHERE ne.name_last = 'Park'
AND m.birth_year = '1958'
AND m.barno = '12345'
)
AND a.time_stamp > m.time_stamp
UNION ALL
SELECT TOP 1
0 AS updatePending,
ne.entity_number,
ne.name_title,
ne.name_first,
ne.name_middle,
ne.name_last,
ISNULL(ne.name_suffix, ''),
LTRIM(RTRIM(REPLACE(
LTRIM(RTRIM(ISNULL(ne.name_first, ''))) +
CASE WHEN LEN(LTRIM(RTRIM(ISNULL(ne.name_first, '')))) = 1 THEN '. ' ELSE ' ' END +
LTRIM(RTRIM(ISNULL(ne.name_middle, ''))) +
CASE WHEN LEN(LTRIM(RTRIM(ISNULL(ne.name_middle, '')))) = 1 THEN '. ' ELSE ' ' END +
LTRIM(RTRIM(ISNULL(ne.name_last, ''))) + ' ' +
LTRIM(RTRIM(ISNULL(ne.name_suffix, '')))
,' ',' '))) AS name_full,
NULLIF(LTRIM(RTRIM(
LTRIM(RTRIM(ISNULL(ne.company, ''))) +
LTRIM(RTRIM(ISNULL(ne.firm_name, ''))))),'') AS company,
ISNULL(ne.address1, ''),
ne.mailing_address,
ne.city,
ne.state,
ne.zip_code,
ne.internet_address AS email_address,
m.time_stamp
FROM Member m
INNER JOIN Named_Entity ne ON (ne.entity_number = m.entity_number)
LEFT JOIN statebar.dbo.STAGING_Address_Change_Request a ON a.entity_number = m.entity_number
WHERE ne.entity_number = (
SELECT m.entity_number
FROM Member m
INNER JOIN Named_Entity ne ON (ne.entity_number = m.entity_number)
WHERE ne.name_last = 'Park'
AND m.birth_year = '1958'
AND m.barno = '12345'
)
AND m.time_stamp > a.time_stamp
ORDER BY updatePending DESC, a.time_stamp DESC

Get specific columns from xml path

I have this query here:
SELECT
T.AKSIONERET,
sd.Identification_No, sd.Date_Of_Incorp,
sd.Ownership_Desc, sd.Ownership_Code,
sd.Subject_Name_Code, sd.Subject_Name,
sd.Subject_Type_Code,
LEFT(sd.Object_Desc, 3999) AS Object_Desc,
sd.Subject_Status_Name, sd.Subject_Name,
nr2.NACE_Code, nr2.NACE_PARENT, nr2.Description,
sd.Subject_Type_Name, sd.Subject_Status_Name,
sd.Subject_Type_Name, f.Place_Of_Registration, sd.Object_Desc
FROM
NRC_Subject_DEF AS sd
LEFT JOIN
NRC_Nace_REV2 AS nr2 ON nr2.Subject_DEF_Code = sd.Subject_DEF_Code
LEFT JOIN
NRC_ForeignCompany AS f ON sd.ForeignCompany_Code = f.ForeignCompany_Code
LEFT JOIN
(SELECT
SDP.Subject_DEF_Code,
(SELECT
SDP1.Subject_DEF_Code, P.First_Name + ' ' + P.Last_Name + '-' + P.Citizenship_Desc AS FullAksionerCitizenship
FROM
NRC_PeopleAddress P
INNER JOIN
NRC_SubjectDefPeople SDP1 ON SDP1.People_Code = P.People_Code
WHERE
SDP1.Subject_DEF_Code = SDP.Subject_DEF_Code
GROUP BY
SDP1.Subject_DEF_Code, P.First_Name + ' ' + P.Last_Name + '-' + P.Citizenship_Desc
FOR XML PATH('')) AS AKSIONERET
FROM
NRC_SubjectDefPeople SDP
WHERE
SDP.Groyp_Type IN (1,2)
GROUP BY
SDP.Subject_DEF_Code) AS T ON T.Subject_DEF_Code = SD.SUBJECT_DEF_CODE
I need to retrieve, instead of T.AKSIONERET the FullAksionerCitizenship which I get from the for xml path.
I know I have to do some other SELECT but I kept getting errors, syntax errors.
Could someone help?
Thanks in advance
I'm quite sure, that there could be a better design and I'm not able to run this against test data off course, but this could work:
SELECT
T.AKSIONERET,
T2.FullAksionerCitizenship,
sd.Identification_No, sd.Date_Of_Incorp,
sd.Ownership_Desc, sd.Ownership_Code,
sd.Subject_Name_Code, sd.Subject_Name,
sd.Subject_Type_Code,
LEFT(sd.Object_Desc, 3999) AS Object_Desc,
sd.Subject_Status_Name, sd.Subject_Name,
nr2.NACE_Code, nr2.NACE_PARENT, nr2.Description,
sd.Subject_Type_Name, sd.Subject_Status_Name,
sd.Subject_Type_Name, f.Place_Of_Registration, sd.Object_Desc
FROM
NRC_Subject_DEF AS sd
LEFT JOIN
NRC_Nace_REV2 AS nr2 ON nr2.Subject_DEF_Code = sd.Subject_DEF_Code
LEFT JOIN
NRC_ForeignCompany AS f ON sd.ForeignCompany_Code = f.ForeignCompany_Code
LEFT JOIN
(SELECT
SDP.Subject_DEF_Code,
(SELECT
SDP1.Subject_DEF_Code, P.First_Name + ' ' + P.Last_Name + '-' + P.Citizenship_Desc AS FullAksionerCitizenship
FROM
NRC_PeopleAddress P
INNER JOIN
NRC_SubjectDefPeople SDP1 ON SDP1.People_Code = P.People_Code
WHERE
SDP1.Subject_DEF_Code = SDP.Subject_DEF_Code
GROUP BY
SDP1.Subject_DEF_Code, P.First_Name + ' ' + P.Last_Name + '-' + P.Citizenship_Desc
FOR XML PATH('')) AS AKSIONERET
FROM
NRC_SubjectDefPeople SDP
WHERE
SDP.Groyp_Type IN (1,2)
GROUP BY
SDP.Subject_DEF_Code) AS T ON T.Subject_DEF_Code = SD.SUBJECT_DEF_CODE
--here starts the new block (difficult for me without knowing your db...)
LEFT JOIN
(SELECT
(SELECT
SDP1.Subject_DEF_Code, P.First_Name + ' ' + P.Last_Name + '-' + P.Citizenship_Desc AS FullAksionerCitizenship
FROM
NRC_PeopleAddress P
INNER JOIN
NRC_SubjectDefPeople SDP1 ON SDP1.People_Code = P.People_Code
WHERE
SDP1.Subject_DEF_Code = SDP.Subject_DEF_Code
GROUP BY
SDP1.Subject_DEF_Code, P.First_Name + ' ' + P.Last_Name + '-' + P.Citizenship_Desc
) AS FullAksionerCitizenship
FROM
NRC_SubjectDefPeople SDP
WHERE
SDP.Groyp_Type IN (1,2)
GROUP BY
SDP.Subject_DEF_Code) AS T2 ON T2.Subject_DEF_Code = SD.SUBJECT_DEF_CODE

How to Convert the SQL Server Query to Equivelent SQLite Query?

I have this query which works in SQL server:
SELECT
T_Cbt.cbtName,
T_HDD.hddName,
T_HDD.ip,
T_HDD.compName,
T_Cbt.mobRack,
T_HDD.size,
T_OS.osName + ' ' + T_OS.osVersion + ' - ' + T_OS.osLanguage AS Expr1,
T_OS.osBit,
T_SWList.swName + ' ' + T_SWDetails.swVersion + ' - ' + T_SWDetails.swLang + ' ' + T_SWDetails.swArch AS Expr2
FROM T_OS INNER JOIN
T_Cbt INNER JOIN
T_HDD ON T_Cbt.cbtId = T_HDD.cbtId ON T_OS.id = T_HDD.osId INNER JOIN
T_Division ON T_HDD.division = T_Division.divId LEFT OUTER JOIN
T_SWDetails INNER JOIN
T_SW ON T_SWDetails.sdPk = T_SW.swdid INNER JOIN
T_SWList ON T_SWDetails.swdId = T_SWList.swId ON T_HDD.hddid = T_SW.hddid
WHERE T_Cbt.cbtName <> 'FREE'
ORDER BY T_Cbt.purpose
While i am executing this query in Sqlite i get error like Error while executing query: near "ON": syntax error How to fix it?
SQLite does not allow nesting JOIN and ON arbitrarily. Reordering your JOINs to not use nesting should allow the query to execute without a problem;
SELECT
T_Cbt.cbtName, T_HDD.hddName, T_HDD.ip, T_HDD.compName,
T_Cbt.mobRack, T_HDD.size,
T_OS.osName || ' ' || T_OS.osVersion || ' - ' || T_OS.osLanguage AS Expr1,
T_OS.osBit, T_SWList.swName || ' ' || T_SWDetails.swVersion || ' - ' ||
T_SWDetails.swLang || ' ' || T_SWDetails.swArch AS Expr2
FROM T_OS
INNER JOIN T_HDD ON T_OS.id = T_HDD.osId
INNER JOIN T_Cbt ON T_Cbt.cbtId = T_HDD.cbtId
INNER JOIN T_Division ON T_HDD.division = T_Division.divId
INNER JOIN T_SW ON T_HDD.hddid = T_SW.hddid
LEFT OUTER JOIN T_SWDetails ON T_SWDetails.sdPk = T_SW.swdid
INNER JOIN T_SWList ON T_SWDetails.swdId = T_SWList.swId
WHERE (T_Cbt.cbtName <> 'FREE')
ORDER BY T_Cbt.purpose