У меня есть две хранимые процедуры, которые фильтруют записи в таблице и дают результат. Ниже приведены хранимые процедуры.
SELECT distinct TO_CHAR(sp.RJ_SPAN_ID) AS SPAN_ID
, TO_CHAR(sp.RJ_MAINTENANCE_ZONE_CODE) AS MAINT_ZONE_CODE
from APP_FTTX.span@SAT sp
INNER JOIN APP_FTTX.transmedia@SAT tm -- transmedia added
on sp.RJ_SPAN_ID = tm.RJ_SPAN_ID
WHERE length(sp.RJ_SPAN_ID) = length(tm.RJ_SPAN_ID)
and sp.RJ_MAINTENANCE_ZONE_CODE = tm.RJ_MAINTENANCE_ZONE_CODE
and sp.INVENTORY_STATUS_CODE = tm.INVENTORY_STATUS_CODE
AND LENGTH(sp.RJ_SPAN_ID) = 21
AND (sp.RJ_SPAN_ID LIKE ('%SPN%')
OR sp.RJ_SPAN_ID LIKE ('%SPQ%')
OR sp.RJ_SPAN_ID LIKE ('%SPR%')
OR sp.RJ_SPAN_ID LIKE ('%SPS%'))
AND (sp.RJ_SPAN_ID LIKE ('%_BU')
OR sp.RJ_SPAN_ID LIKE ('%_MP'))
AND sp.INVENTORY_STATUS_CODE = 'IPL'
AND sp.RJ_MAINTENANCE_ZONE_CODE = 'INMUNVMB01'
AND (sp.RJ_INTRACITY_LINK_ID NOT LIKE ('%\_9%') ESCAPE '\'
OR sp.RJ_INTRACITY_LINK_ID IS NULL);
Вышеуказанный SP возвращает 4 записи, и это действительные записи, которые я хочу вставить в таблицу.
Теперь есть еще один SP, который ниже, который возвращает 7 записей.
SELECT distinct TO_CHAR(sp.RJ_SPAN_ID) AS SPAN_ID
, TO_CHAR(sp.RJ_MAINTENANCE_ZONE_CODE) AS MAINT_ZONE_CODE
from APP_FTTX.span@SAT sp
-- INNER JOIN APP_FTTX.transmedia@SAT tm -- transmedia added
-- on sp.RJ_SPAN_ID = tm.RJ_SPAN_ID
-- WHERE length(sp.RJ_SPAN_ID) = length(tm.RJ_SPAN_ID)
-- and sp.RJ_MAINTENANCE_ZONE_CODE = tm.RJ_MAINTENANCE_ZONE_CODE
-- and sp.INVENTORY_STATUS_CODE = tm.INVENTORY_STATUS_CODE
WHERE LENGTH(sp.RJ_SPAN_ID) = 21
AND (sp.RJ_SPAN_ID LIKE ('%SPN%')
OR sp.RJ_SPAN_ID LIKE ('%SPQ%')
OR sp.RJ_SPAN_ID LIKE ('%SPR%')
OR sp.RJ_SPAN_ID LIKE ('%SPS%'))
AND (sp.RJ_SPAN_ID LIKE ('%_BU')
OR sp.RJ_SPAN_ID LIKE ('%_MP'))
AND sp.INVENTORY_STATUS_CODE = 'IPL'
AND sp.RJ_MAINTENANCE_ZONE_CODE = 'INMUNVMB01'
AND (sp.RJ_INTRACITY_LINK_ID NOT LIKE ('%\_9%') ESCAPE '\'
OR sp.RJ_INTRACITY_LINK_ID IS NULL);
SP похожи. Есть 3 записи, которые являются недействительными во втором SP. Итак, я хочу вот что: я хочу вставить другие 3 записи, которые являются недопустимыми, в другую таблицу.
Пожалуйста, предложите, как этого добиться.
ОБНОВЛЕНИЕ
Согласно комментарию Алекса, я получил минус в моем коде ниже.
SELECT distinct TO_CHAR(sp.RJ_SPAN_ID) AS SPAN_ID, TO_CHAR(sp.RJ_MAINTENANCE_ZONE_CODE) AS MAINT_ZONE_CODE
from APP_FTTX.span@SAT sp
-- INNER JOIN APP_FTTX.transmedia@SAT tm -- transmedia added
-- on sp.RJ_SPAN_ID = tm.RJ_SPAN_ID
-- WHERE length(sp.RJ_SPAN_ID) = length(tm.RJ_SPAN_ID)
-- and sp.RJ_MAINTENANCE_ZONE_CODE = tm.RJ_MAINTENANCE_ZONE_CODE
-- and sp.INVENTORY_STATUS_CODE = tm.INVENTORY_STATUS_CODE
WHERE LENGTH(sp.RJ_SPAN_ID) = 21
AND (sp.RJ_SPAN_ID LIKE ('%SPN%') OR sp.RJ_SPAN_ID LIKE ('%SPQ%') OR sp.RJ_SPAN_ID LIKE ('%SPR%')
OR sp.RJ_SPAN_ID LIKE ('%SPS%'))
AND (sp.RJ_SPAN_ID LIKE ('%_BU') OR sp.RJ_SPAN_ID LIKE ('%_MP'))
AND sp.INVENTORY_STATUS_CODE = 'IPL'
AND sp.RJ_MAINTENANCE_ZONE_CODE = 'INMUNVMB01'
AND (sp.RJ_INTRACITY_LINK_ID NOT LIKE ('%\_9%') ESCAPE '\' OR sp.RJ_INTRACITY_LINK_ID IS NULL)
MINUS
SELECT distinct TO_CHAR(sp.RJ_SPAN_ID) AS SPAN_ID,
TO_CHAR(sp.RJ_MAINTENANCE_ZONE_CODE) AS MAINT_ZONE_CODE
from APP_FTTX.span@SAT sp
INNER JOIN APP_FTTX.transmedia@SAT tm --
transmedia added
on sp.RJ_SPAN_ID = tm.RJ_SPAN_ID
WHERE length(sp.RJ_SPAN_ID) =
length(tm.RJ_SPAN_ID)
and sp.RJ_MAINTENANCE_ZONE_CODE =
tm.RJ_MAINTENANCE_ZONE_CODE
and sp.INVENTORY_STATUS_CODE =
tm.INVENTORY_STATUS_CODE
AND LENGTH(sp.RJ_SPAN_ID) = 21
AND (sp.RJ_SPAN_ID LIKE ('%SPN%') OR
sp.RJ_SPAN_ID LIKE ('%SPQ%') OR sp.RJ_SPAN_ID LIKE ('%SPR%')
OR sp.RJ_SPAN_ID LIKE ('%SPS%'))
AND (sp.RJ_SPAN_ID LIKE ('%_BU') OR
sp.RJ_SPAN_ID LIKE ('%_MP'))
AND sp.INVENTORY_STATUS_CODE = 'IPL'
AND sp.RJ_MAINTENANCE_ZONE_CODE =
'INMUNVMB01'
AND (sp.RJ_INTRACITY_LINK_ID NOT LIKE
('%\_9%') ESCAPE '\' OR sp.RJ_INTRACITY_LINK_ID IS NULL);