Oracle SQL Developer Error - ORA-00920: invalid relational operator - oracle

This is my code after check syntax this error appear
Error at line 15, column 6: ORA-00920: invalid relational operator
What problem on this code?
SELECT ahli.mshp_no,
branch.branch_code,
branch.branch_name,
l_mshp_type.mshp_type_desc,
ahli.name,
l_idtype.description,
ahli.ic_no,
ahli.birth_date,
ahli.addr_1,
ahli.addr_2,
ahli.addr_3,
ahli.postcode,
l_state.description,
ahli.notelru,
ahli.h_phone,
ahli.hubaddr_1,
ahli.hubaddr_2,
ahli.hubaddr_3,
ahli.hubpostcode,
ahli.emp_code,
ahli.offaddr_1,
ahli.offaddr_2,
ahli.offaddr_3,
ahli.offpostcode,
ahli.offaddr_4,
waris.nama,
waris.id_type,
waris.id_no,
waris.relation,
waris.addr_1,
waris.addr_2,
waris.addr_3,
waris.postcode,
waris.addr_4,
waris.no_tel1,
waris.no_tel2,
waris.mshp_no,
ahli.mshp_type,
ahli.branch_code,
ahli.id_type,
ahli.addr_4
FROM ahli
inner join waris
ON ahli.mshp_no = waris.mshp_no
AND inner
join branch
ON ahli.branch_code = branch.branch_code
AND inner
join l_mshp_type
ON ahli.mshp_code = l_mshp_type.mshp_type_desc
AND inner
join l_idtype
ON ahli.id_type = l_idtype.description
AND inner
join l_state
ON ahli.offaddr_4 = l_state.description

INNER JOIN WARIS ON AHLI.MSHP_NO = WARIS.MSHP_NO AND
INNER JOIN
You have an extra "AND" at the end.
Remove those, just do
INNER JOIN WARIS ON AHLI.MSHP_NO = WARIS.MSHP_NO
INNER JOIN

Related

Missing Keyword Error in Oracle - Wrong Syntax WHERE Expression

I'm new to Oracle SQL, I'm being asked to do some scenarios to learn the different expressions and so on.
I'm currently working on this statement but I keep having trouble with syntax and trying to get my expressions in the correct place.
If you don't mind taking a look at what I'm doing wrong and helping me learn the correct syntax I'd appreciate it a lot.
I have to find everything in the Sale, SaleDetail, OrderStatus, Warehouse, User and StockDetail tables.
The fields I need to find are saleno, serialstart, serialend, the product description (label field), sale status (saleid (I think)), WarehouseName (WH.NAME)
Here below is the code I've written so far.
SELECT
S.SALENO,
SD.SERIALSTART,
SD.SERIALEND,
SDT.LABEL,
USR.USERNAME,
WH.NAME
FROM
ITR_SALE,
ITR_SALEDETAIL,
ITR_ORDER,
ITR_WAREHOUSE,
ITR_USER,
ITR_STOCKDETAIL
JOIN ITR_SALE S
JOIN ITR_SALEDETAIL SD ON S.ID = SD.SALENO
JOIN ITR_WAREHOUSE WH ON SD.ID = WH.NAME
JOIN ITR_ORDER ODR ON WH.ID = ODR.STATUSID
JOIN ITR_USER USR ON ODR.ID = USR.USERNAME
JOIN ITR_STOCKDETAIL ON USR.ID = SDT.LABEL
WHERE S.LASTSTATUSCHANGETIME
BETWEEN ('2016-01-01 00:00:00' AND '2016-12-31 23:59:59')
AND STATUSID = ('COMPLETED');
Below follows the error message
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 21 Column: 1
EDIT:
Finished code below, changed a few expressions and conditions.
SELECT
S.SALENO,
SD.SERIALSTART,
SD.SERIALEND,
SDA.LABEL,
USR.USERNAME,
WH.NAME
FROM
ITR_SALE S
INNER JOIN
ITR_SALEDETAIL SD ON S.ID = SD.SALEID
INNER JOIN
ITR_ORDERSTATUS ODS ON SD.ID = ODS.ID
INNER JOIN
ITR_WAREHOUSE WH ON ODS.ID = WH.NAME
INNER JOIN
ITR_USER USR ON WH.ID = USR.USERNAME
INNER JOIN
ITR_STOCKDETAIL SDA ON USR.ID = SDA.LABEL
WHERE 'DATE' BETWEEN '2016-01-01' AND '2016-12-31'
AND S.STATUSID = '4';`
Use proper join syntax. Edit. Need to remove parenthesis from last line or user IN clause.
SELECT
S.SALENO,
SD.SERIALSTART,
SD.SERIALEND,
SDT.LABEL,
USR.USERNAME,
WH.NAME
FROM
ITR_SALE S INNER JOIN ITR_SALEDETAIL SD ON S.ID = SD.SALENO
INNER JOIN ITR_SALEDETAIL SD ON S.ID = SD.SALENO
INNER JOIN ITR_WAREHOUSE WH ON SD.ID = WH.NAME
INNER JOIN ITR_ORDER ODR ON WH.ID = ODR.STATUSID
INNER JOIN ITR_USER USR ON ODR.ID = USR.USERNAME
INNER JOIN ITR_STOCKDETAIL STD ON USR.ID = SDT.LABEL
WHERE S.LASTSTATUSCHANGETIME
BETWEEN '2016-01-01 00:00:00' AND '2016-12-31 23:59:59'
AND STATUSID = 'COMPLETED';

Missing Operator in Query Expression

I have this code
SELECT Sales.InvoiceNo, Sales.SaleDate, Clients.Name, Clients.Address AS
ClientAdrs, Stock.Itemname, Stock.Tax, Stock.Price, Transactions.Qty,
Transactions.NetValue,Transactions.TaxAmount, Transactions.TotalAmount,
Sales.GrossNet, Sales.GrossTax, Sales.GrossTotal, Sales.PrintingCharge,
Sales.LabourCharge, Sales.AdjustableAmount,Sales.GrandTotal, Sales.InWords,
ShopeDetails.Address, ShopeDetails.Email, ShopeDetails.Mobile1,
ShopeDetails.Mobile2, ShopeDetails.TIN, ShopeDetails.AcN,ShopeDetails.IFC
FROM Sales
INNER JOIN Clients
ON Sales.Cid = Clients.Cid
INNER JOIN Transactions
ON Sales.InvoiceNo = Transactions.InvoiceNo
INNER JOIN Stock
ON Transactions.Sid = Stock.Sid
INNER JOIN ShopeDetails
ON Sales.Id = ShopeDetails.Id
and i get this error
Syntax error (missing operator) in query expression
Sales.Cid = Clients.Cid INNER JOIN Transactions ON Sales.InvoiceNo = Transactions.InvoiceNo INNER JOIN Stock ON Transactions.Sid = Stock.Sid INNER JOIN ShopeDetails ON Sales.Id = ShopeDetails.I
Please Help anyone !!
SELECT Sales.InvoiceNo, Sales.SaleDate, Clients.Name, Clients.Address AS
ClientAdrs,Stock.Itemname, Stock.Tax, Stock.Price, Transactions.Qty,
Transactions.NetValue,Transactions.TaxAmount, Transactions.TotalAmount,
Sales.GrossNet, Sales.GrossTax, Sales.GrossTotal, Sales.PrintingCharge,
Sales.LabourCharge, Sales.AdjustableAmount,Sales.GrandTotal, Sales.InWords,
ShopeDetails.Address, ShopeDetails.Email, ShopeDetails.Mobile1,
ShopeDetails.Mobile2, ShopeDetails.TIN, ShopeDetails.AcN,ShopeDetails.IFC
FROM (((Sales INNER JOIN Clients ON Sales.Cid = Clients.Cid)
INNER JOIN Transactions ON Sales.InvoiceNo = Transactions.InvoiceNo)
INNER JOIN Stock ON Transactions.Sid = Stock.Sid )
INNER JOIN ShopeDetails ON Sales.Id = ShopeDetails.Id
this solved the problem

Left Outer Join Error

I get this error for the below query when I am trying to make a left outer join
ERROR at line 7:
ORA-00936: missing expression
select s.FINAL_BSAL,s.EMP_No,p.ERN_DDCT_CATNO,p.AMOUNT,n.NO_PAY_AMOUNT,
p.Pay_month,a.ARREARS_AMOUNT from salary_details s,pay_details p,Arrears a,No_Pay n
where s.emp_no=p.emp_no
and
s.SAL_NO IN (SELECT MAX(SAL_NO) FROM SALARY_DETAILS group by EMP_NO)
AND
to_char(P.PAY_MONTH,'MM-YYYY') =to_char(n.NO_PAY_MONTH,'MM-YYYY') (+)
AND
to_char(P.PAY_MONTH,'MM-YYYY')=to_char(a.ARREARS_MONTH,'MM-YYYY') ;
Please help.
The issue lies with the placement of (+):
Instead of:
to_char(P.PAY_MONTH,'MM-YYYY') =to_char(n.NO_PAY_MONTH,'MM-YYYY') (+)
you should do:
to_char(P.PAY_MONTH,'MM-YYYY') =to_char(n.NO_PAY_MONTH (+),'MM-YYYY')
However, if I were you, I'd go with #Walter_Ritzel's approach and use ANSI JOIN syntax instead. That and properly format the SQL so that it's readable...
Try this:
select s.FINAL_BSAL
,s.EMP_No
,p.ERN_DDCT_CATNO
,p.AMOUNT
,n.NO_PAY_AMOUNT
,p.Pay_month
,a.ARREARS_AMOUNT
from salary_details s inner join pay_details p on s.emp_no = p.emp_no
inner join Arrears a on to_char(P.PAY_MONTH,'MM-YYYY')= to_char(a.ARREARS_MONTH,'MM-YYYY')
left outer join No_Pay n on to_char(P.PAY_MONTH,'MM-YYYY') = to_char(n.NO_PAY_MONTH,'MM-YYYY')
where s.SAL_NO IN (SELECT MAX(SAL_NO) FROM SALARY_DETAILS group by EMP_NO);

Oracle's OUTER JOIN (+) on string - Migration PostgreSQL

I'm migrating a client's software database from Oracle to PostgreSQL, and I have some trouble understanding a query, what it does, and consequently how to migrate it.
The query is:
SELECT *
FROM TBL1, TBL2, TBL3, TBL4
WHERE TBL3.Project_ID = TBL1.Project_ID
AND TBL2.Type_ID = TBL1.Type_ID
AND TBL4.PROPERTY_NAME(+)='Id'
AND TBL4.Entity_ID(+)=TBL1.Entity_ID
And the part I don't get, is the outer join (+) on 'Id'.
A join on a table, OK, but on a string? I've no idea of what it does.
Do someone has an idea?
Thanks.
TBL4.PROPERTY_NAME(+)='Id' means when the line was inner joined, then the value has to be 'Id', but when the line was outer joined, the condition is evaluated as true
however you should rewrite the statement to the standard as:
SELECT *
FROM TBL1
JOIN TBL2 ON TBL2.Type_ID = TBL1.Type_ID
JOIN TBL3 ON TBL3.Project_ID = TBL1.Project_ID
LEFT JOIN TBL4 ON TBL4.Entity_ID=TBL1.Entity_ID AND TBL4.PROPERTY_NAME='Id'
This is the equivalent of the following query using ANSI join syntax:
SELECT *
FROM TBL1 t1
INNER JOIN TBL2 t2 ON (t1.Type_ID = t2.Type_ID)
INNER JOIN TBL3 t3 ON (t3.Project_ID = t1.Project_ID)
LEFT JOIN TBL4 t4 ON (t4.Entity_ID = t1.Entity_ID AND t4.PROPERTY_NAME = 'Id')
You're not joining to a string, merely specifying a join condition that's based on one.

What would be the correct syntax for a full outer join in linq

I'm new to linq and I'm having trouble getting the correct syntax for this sql statement.
SELECT
A.AssetName,
B.MPercentage,
B.OPercentage,
B.IsStateDefault,
D.ShortName
FROM [Core].[dbo].[Asset] A
FULL OUTER JOIN [Core].[dbo].[PayrollMarkup] B
ON A.PayrollMarkupID = B.PayrollMarkupID
FULL OUTER JOIN [Core].[dbo].[StatePayrollMarkup] C
ON B.PayrollMarkupID = C.PayrollMarkupID
FULL OUTER JOIN [Core].[dbo].[StateLookup] D
ON C.StateID = D.StateID
WHERE A.AssetName IS NOT null

Resources