February 12, 2016 at 12:28 pm
Hello - I'm trying to write this formula in an Oracle database but...
I'm receiving this error
-- Failed: General SQL error. ORA-00933: SQL command not properly ended
Sorry if my coding structure isn't proper etiquette - still learning Current Code Picture
When the inventory is received that's what's called the "IN_DATE" So I recieved 20,000 plastic bottles today IN_DATE = GETNOW() or "2/12/2016" So this SQL will run EVERY DAY at 5pm or so so Everything that is RECEIVED that DAY that follows the Class listed at the bottom there is a field for each of these received items that is called "Non_Conformed_Allocatable" And this will be switched to "Y"
UPDATE FGMULTI
SET NON_CONFORM_ALLOCATABLE = 'Y'
FROM
fgmulti as fg
LEFT OUTER JOIN
arinvt as ar ON fg.arinvt_id = ar.id
WHERE
IN_Date = CurrentDate
AND
ar.Class LIKE 'CP%'
OR
ar.Class LIKE 'FG%'
OR
ar.Class LIKE 'IN%'
OR
ar.Class LIKE 'LA%'
OR
ar.Class LIKE 'PK%'
February 12, 2016 at 12:44 pm
For starters remove the "as", you don't need it when aliasing tables in Oracle. Give me a little time to mess with this, I'll be back.
UPDATE FGMULTI
SET NON_CONFORM_ALLOCATABLE = 'Y'
FROM
fgmulti fg
LEFT OUTER JOIN
arinvt ar ON fg.arinvt_id = ar.id
WHERE
IN_Date = CurrentDate
AND
ar.Class LIKE 'CP%'
OR
ar.Class LIKE 'FG%'
OR
ar.Class LIKE 'IN%'
OR
ar.Class LIKE 'LA%'
OR
ar.Class LIKE 'PK%'
February 12, 2016 at 12:49 pm
To the best of my knowledge Oracle doesn't support Joins in an Update statement.
February 12, 2016 at 12:56 pm
Yes - just found this out as well
So now I'm trying to work with this:
UPDATE FGMULTI
JOIN
arinvt ar ON
LEFT OUTER JOIN
fgmulti.arinvt_id = ar.id
SET NON_CONFORM_ALLOCATABLE = 'Y'
WHERE
IN_Date = CurrentDate
AND
ar.Class LIKE 'CP%'
OR
ar.Class LIKE 'FG%'
OR
ar.Class LIKE 'IN%'
OR
ar.Class LIKE 'LA%'
OR
ar.Class LIKE 'PK%'
February 12, 2016 at 1:33 pm
I disagree with Grumpy's first suggestion. Oracle may not "need" the AS for a table alias (and neither does SQL Server), but including it in my opinion greatly increases readability and maintainability of the code.
UPDATE ... FROM is a SQL Server only construction, not supported by the ANSI standard, or by most other DBMSes. (And for good reasons, it has some very dangerous and often overlooked effects).
The ANSI compliant way to write this kind of update would be:
UPDATE FGMULTI
SET NON_CONFORM_ALLOCATABLE = 'Y'
WHERE EXISTS
(SELECT *
FROM fgmulti as fg
LEFT OUTER JOIN
arinvt as ar ON fg.arinvt_id = ar.id
WHERE (something) = FGMULTI.(SomeColumn)
AND (other conditions));
I cannot provide more specific help then this. Your code lacks aliases for the columns (which in my opinion is a bad practice - the DBMS may know which column it is, but you have to spend time on it every time you look at the query). So I do not know which condition references which tables in your original code.
February 12, 2016 at 8:08 pm
rshukis10 (2/12/2016)
Yes - just found this out as wellSo now I'm trying to work with this:
UPDATE FGMULTI
JOIN
arinvt ar ON
LEFT OUTER JOIN
fgmulti.arinvt_id = ar.id
SET NON_CONFORM_ALLOCATABLE = 'Y'
WHERE
IN_Date = CurrentDate
AND
ar.Class LIKE 'CP%'
OR
ar.Class LIKE 'FG%'
OR
ar.Class LIKE 'IN%'
OR
ar.Class LIKE 'LA%'
OR
ar.Class LIKE 'PK%'
Don't use UPDATE for joined updates in Oracle. Use MERGE instead. It's easier to use for updates.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 12, 2016 at 8:12 pm
Hugo Kornelis (2/12/2016)
I disagree with Grumpy's first suggestion. Oracle may not "need" the AS for a table alias (and neither does SQL Server), but including it in my opinion greatly increases readability and maintainability of the code.
To each their own. I don't use "AS" for table aliases either. Come to think of it, I generally don't use "AS" for column aliases because I usually use the ColumnAlias = Expression form in my select lists. Like I said, to each their own. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
February 13, 2016 at 5:15 am
That may be an unrestricted update. The left-joined table contributes nothing, and the WHERE clause is an unpredictable mess of AND and OR. What exactly are you trying to do?
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply