oracle 带引用值的SQL查询/触发器

qmb5sa22  于 2023-11-17  发布在  Oracle
关注(0)|答案(1)|浏览(123)

这里是第一个计时器。我正在处理一个SQL触发器,需要找到一种方法来引用一个基于工作订单号的值。下面是数据的样子:
1
这是我目前所知道的

CURSOR C1 (insSpoolID IN CHAR) IS
select substr(data_valuestring,8) from E2S_SPOOLERDATA
where SPOOL_ID = insSpoolID AND DATA_VALUESTRING LIKE '!WO_NB!%%' ESCAPE '!';

CURSOR C2 (insSpoolID IN CHAR) IS
select substr(data_valuestring,14) from E2S_SPOOLERDATA
where SPOOL_ID = insSpoolID AND DATA_VALUESTRING LIKE '!PRODUCTCODE!%%' ESCAPE '!';

CURSOR C3 (insSpoolID IN CHAR) IS
select substr(data_valuestring,9) from E2S_SPOOLERDATA
where SPOOL_ID = insSpoolID AND DATA_VALUESTRING LIKE '!CONTNO!%%' ESCAPE '!';

CURSOR C4 (insSpoolID IN CHAR) IS
select substr(data_valuestring,8) from E2S_SPOOLERDATA
where SPOOL_ID = insSpoolID AND DATA_VALUESTRING LIKE '!BAGNO!%%' ESCAPE '!';

CURSOR C5 (insSpoolID IN CHAR) IS
select substr(data_valuestring,12) from E2S_SPOOLERDATA
where SPOOL_ID = insSpoolID AND DATA_VALUESTRING LIKE '!CONTAINER!%%' ESCAPE '!';

CURSOR C6 (insSpoolID IN CHAR) IS
select substr(data_valuestring,8) from E2S_SPOOLERDATA
where SPOOL_ID = insSpoolID AND DATA_VALUESTRING LIKE '!BATCH!%%' ESCAPE '!';

CURSOR C7 (insSpoolID IN CHAR) IS
select substr(data_valuestring,7) from E2S_SPOOLERDATA
where SPOOL_ID = insSpoolID AND DATA_VALUESTRING LIKE '!ITEM!%%' ESCAPE '!';

BEGIN
If :new.SPOOL_STATUS = 'S' then

   sSpoolID:= :new.spool_id;
   sDCMTCode:= :new.DCMT_CODE;

If sDCMTCode like '%VARPESEE%' then
     OPEN C1(sSpoolID);
     OPEN C2(sSpoolID);
     OPEN C3(sSpoolID);
     OPEN C4(sSpoolID);
     FETCH C1 INTO sWONb;
     FETCH C2 INTO sProductCode;
     FETCH C3 INTO sContNo;
     Fetch C7 INTO sItem;

**Get CONTAINERS_NB value, output to sCont_Total_Number:=TotalCont**

Insert into SPOOLERDATA (SPOOL_ID,SPOOL_INDEX,SPOOL_STATUS,DATA_TABLE,DATA_ROW,DATA_COLUMN,DATA_TYPE,DATA_LENGTH,DATA_VALUENUMBER,DATA_VALUEDATE,DATA_VALUESTRING) values (sSpoolID,'999','S','ROW','999','VALUE','VARCHAR2','250','0',null,'%CONT_PRINT_NUMBER_TOTAL%' || sCont_Total_Number);
     end if;

END IF;

# Need way to get the data CONTAINERS_NB(see table above, value is 2 in the example) where the work order numbers are matching for the two input variables, WO_NB and ITEM_NB.

字符串
因此,我需要一个查询来查找集装箱号,方法是从WO_NB和<$em_NB条目输入的相应METADATASET值中选择集装箱号。
希望你能理解。
提前感谢任何提供帮助的人。
我已经开始计划使用这样的东西,但认为我可能是远离什么是需要的。

SELECT TO_CHAR(VALUE) FROM E2S_METADATAVALUE_MAN WHERE NAME='WO_NB' 
      AND FK_METADATASET=
             (SELECT FK_METADATASET from E2S_METADATAVALUE_MAN 
                    where NAME='FORMULA_CATEGORY' 
                               AND FK_METADATASET IN 
             (SELECT FK_METADATASET FROM E2S_METADATAVALUE_MAN 
                    where dbms_lob.instr (Value,insC1WO) >0));

wixjitnu

wixjitnu1#

因此,我需要一个查询来查找容器号,方法是从WO_NBITEM_NB条目输入的相应METADATASET值中选择容器号。
你试图用光标做的事情很难理解。
你似乎只需要一个PIVOT,然后过滤输出:

SELECT *
FROM   table_name
PIVOT (
  MAX(value)
  FOR (name) IN (
    'WO_NB' AS wo_nb,
    'ITEM_NB' AS item_nb,
    'CONTAINERS_NB' AS containers_nb
  )
)
WHERE  wo_nb   = v_the_wo_nb_you_are_trying_to_match
AND    item_nb = v_the_item_nb_you_are_trying_to_match

字符串
fiddle

相关问题