Не удается найти синтаксическую ошибку при перестройке Access SQL в Oracle SQL - команда SQL неправильно завершена - PullRequest
0 голосов
/ 19 декабря 2018

Попытка воссоздать сценарий из базы данных Access, который извлекает кучу данных о продукте в большой дамп, для более непосредственного запуска в базе данных Oracle, но не может из-за меня найти синтаксическую ошибку вскрипт (давно использующий SQL Server, но новый для Oracle).

Create table temp_test_finfo as SELECT
a.supid_arlnr as knlnr,
a.id_ararts as knarts,
a.supartno_arartl as knartl,
iif(isnull(PRIMPACKEAN_WAPREAN),a.EAN13_AREAN1,v.PRIMPACKEAN_WAPREAN) 
AS knean1, 
a.SUPDESC1_ARLBN1 as knlbn1, 
a.SUPDESC2_ARLBN2 as knlbn2, 
a.DESC1_ARBEN1 as knben1,
a.LONGDESC1_ARBNL1 as knbnl1, 
a.LONGDESC2_ARBNL2 as knbnl2, 
a.ARTGROUP_ARVGR as knvgr, 
a.SEARCHWORD_ARBENS as knbens, 
iif(IsNull(a.LONGDESC1_ARBNL1), iif(InStr(a.DESC1_ARBEN1,' '),0,a.DESC1_ARBEN1, SUBSTR(a.DESC1_ARBEN1,InStr(1,a.DESC1_ARBEN1,' ')-1)), iif(InStr(a.LONGDESC1_ARBNL1,' '),0,a.LONGDESC1_ARBNL1, SUBSTR(a.LONGDESC1_ARBNL1,InStr(1,a.LONGDESC1_ARBNL1,' ')-1))) as ord,
rsk.rsk
FROM (select (case when v.RSKNO_WARSK is null then a.PBID_RSKNO_ARART2 else v.RSKNO_WARSK END) as rsk, a.id_ararts from FINFO.article_dbart00 a LEFT JOIN FINFO.ARTICLE_VILMA_DBWIL002 v ON a.ID_ARARTS = v.ID_WAARTS) as rsk
left join finfo.article_dbart00 a on a.ID_ARARTS = rsk.id_ararts
left join FINFO.ARTICLE_VILMA_DBWIL002 v ON a.ID_ARARTS = v.ID_WAARTS
WHERE a.SUPID_ARLNR != 40 AND a.EXPIRYDATE_ARUTGD Is Null;

Оригинальный скрипт из Access:

INSERT INTO Finfo ( KNLNR, KNARTS, KNARTL, KNEAN1, KNLBN1, KNLBN2, KNBEN1, KNBNL1, KNBNL2, KNVGR, KNBENS, ORD, RSK )
SELECT FINFO_ARTICLE_DBART00.SUPID_ARLNR, FINFO_ARTICLE_DBART00.ID_ARARTS, FINFO_ARTICLE_DBART00.SUPARTNO_ARARTL, IIf(IsNull('PRIMPACKEAN_WAPREAN'),[FINFO_ARTICLE_DBART00].[EAN13_AREAN1],[FINFO_ARTICLE_VILMA_DBWIL002].[PRIMPACKEAN_WAPREAN]) AS EAN, FINFO_ARTICLE_DBART00.SUPDESC1_ARLBN1, FINFO_ARTICLE_DBART00.SUPDESC2_ARLBN2, FINFO_ARTICLE_DBART00.DESC1_ARBEN1, FINFO_ARTICLE_DBART00.LONGDESC1_ARBNL1, FINFO_ARTICLE_DBART00.LONGDESC2_ARBNL2, FINFO_ARTICLE_DBART00.ARTGROUP_ARVGR, FINFO_ARTICLE_DBART00.SEARCHWORD_ARBENS, IIf(IsNull([FINFO_ARTICLE_DBART00].[LONGDESC1_ARBNL1]),IIf(InStr(1,[FINFO_ARTICLE_DBART00].[DESC1_ARBEN1],' ')=0,[FINFO_ARTICLE_DBART00].[DESC1_ARBEN1],Left([FINFO_ARTICLE_DBART00].[DESC1_ARBEN1],InStr(1,[FINFO_ARTICLE_DBART00].[DESC1_ARBEN1],' ')-1)),IIf(InStr(1,[FINFO_ARTICLE_DBART00].[LONGDESC1_ARBNL1],' ')=0,[FINFO_ARTICLE_DBART00].[LONGDESC1_ARBNL1],Left([FINFO_ARTICLE_DBART00].[LONGDESC1_ARBNL1],InStr(1,[FINFO_ARTICLE_DBART00].[LONGDESC1_ARBNL1],' ')-1))) AS ORD, IIf(IsNull([FINFO_ARTICLE_VILMA_DBWIL002].[RSKNO_WARSK]),[FINFO_ARTICLE_DBART00].[PBID_RSKNO_ARART2],[FINFO_ARTICLE_VILMA_DBWIL002].[RSKNO_WARSK]) AS RSK
FROM FINFO_ARTICLE_DBART00 LEFT JOIN FINFO_ARTICLE_VILMA_DBWIL002 ON FINFO_ARTICLE_DBART00.ID_ARARTS = FINFO_ARTICLE_VILMA_DBWIL002.ID_WAARTS
WHERE (((FINFO_ARTICLE_DBART00.SUPID_ARLNR)<>40) AND ((FINFO_ARTICLE_DBART00.EXPIRYDATE_ARUTGD) Is Null));

Если кто-нибудь может указать мне,Буду очень признателен!

1 Ответ

0 голосов
/ 19 декабря 2018

Попробуйте следующий запрос, замените IIF на decode

SELECT a.supid_arlnr as knlnr,
       a.id_ararts as knarts,
       a.supartno_arartl as knartl,
       DECODE(isnull(PRIMPACKEAN_WAPREAN),a.EAN13_AREAN1, v.PRIMPACKEAN_WAPREAN) AS knean1,
       a.SUPDESC1_ARLBN1 as knlbn1,
       a.SUPDESC2_ARLBN2 as knlbn2,
       a.DESC1_ARBEN1 as knben1,
       a.LONGDESC1_ARBNL1 as knbnl1,
       a.LONGDESC2_ARBNL2 as knbnl2,
       a.ARTGROUP_ARVGR as knvgr,
       a.SEARCHWORD_ARBENS as knbens,
       DECODE(IsNull(a.LONGDESC1_ARBNL1),
           DECODE(InStr(a.DESC1_ARBEN1, ' '),
               0,
               a.DESC1_ARBEN1,
               SUBSTR(a.DESC1_ARBEN1, InStr(1, a.DESC1_ARBEN1, ' ') - 1)),
           DECODE(InStr(a.LONGDESC1_ARBNL1, ' '),
               0,
               a.LONGDESC1_ARBNL1,
               SUBSTR(a.LONGDESC1_ARBNL1,
                      InStr(1, a.LONGDESC1_ARBNL1, ' ') - 1))) as ord,
       rsk
  FROM (select (case
                 when v.RSKNO_WARSK is null then
                  a.PBID_RSKNO_ARART2
                 else
                  v.RSKNO_WARSK
               END) as rsk,
               a.id_ararts
          from FINFO.article_dbart00 a
          LEFT JOIN FINFO.ARTICLE_VILMA_DBWIL002 v ON a.ID_ARARTS =
                                                      v.ID_WAARTS) as rsk
  left join finfo.article_dbart00 a on a.ID_ARARTS = rsk.id_ararts
  left join FINFO.ARTICLE_VILMA_DBWIL002 v ON a.ID_ARARTS = v.ID_WAARTS
 WHERE a.SUPID_ARLNR != 40
   AND a.EXPIRYDATE_ARUTGD Is Null;
...