2017-05-05 106 views
-3

琴絃,我有如下組合作爲輸入,請幫我一個函數返回的輸出變量下面剝離在Oracle

COMPANY-ID_ABC_123   ==> This should give three outputs (COMPANY-ID,ABC,123) 
COMPANY-ID     ==> this should give give three outputs such as (COMPANY-ID,null,null) 
COMPANY-ID-FLAG    ==> this should give give three outputs such as (COMPANY-ID,FLAG,null) 
COMPANY-ID-FLAG-ES  ==> this should give give three outputs such as (COMPANY-ID,FLAG,ES) 
COMPANY-ID-ES    ==> this should give give three outputs such as (COMPANY-ID,ES,null) 
IOB-2003    ==> if i give any other string other than the above , it has to just display (IOB-2003,null,null) 
+0

你可以檢查一下你是否寫完了所有的東西嗎? (我發現兩三個奇怪的東西......例如COMPANY-ID-FLAG或COMPANY-ID_FLAG?但也有其他說明) – etsa

+0

是的COMPANY-ID是默認的,第一個例子包含兩個附加的字符串下劃線_。休息它的所有連字符。 –

+0

如果是這樣,請修改並編輯您的問題。澄清你的實際值是否也是如此(例如,當你編寫COMPANY-ID時,你的意思是任何值或只是「COMPANY_ID」?) – etsa

回答

0

假設只有這些價值觀被認爲是討論的那樣,你可以只用多個if-elsif-end語句對其進行硬編碼。否則,你必須解析輸入字符串。如果我必須解析它,我會首先從COMPANY-ID中刪除連字符,然後解析「 - 」和/或「_」上的字符串。

CREATE OR REPLACE PROCEDURE getVal 
    (string_in IN varchar2, 
     string_out1 OUT varchar2, 
     string_out2 OUT varchar2, 
     string_out3 OUT varchar2) 
AS 
    string_out1 := 'IOB-2003'; 
    string_out2 := 'null'; 
    string_out3 := 'null'; 

BEGIN 

    IF string_in = 'COMPANY-ID_ABC_123' THEN 
     string_out1 := 'COMPANY-ID'; 
     string_out2 := 'ABC'; 
     string_out3 := '123'; 

    ELSIF string_in = 'COMPANY-ID' THEN 
     string_out1 := 'COMPANY-ID'; 

    ELSIF string_in = 'COMPANY-ID-FLAG' THEN 
     string_out1 := 'COMPANY-ID'; 
     string_out2 := 'FLAG'; 

    ELSIF string_in = 'COMPANY-ID-FLAG-ES' THEN 
     string_out1 := 'COMPANY-ID'; 
     string_out2 := 'FLAG'; 
     string_out3 := 'ES'; 

    ELSIF string_in = 'COMPANY-ID-ES' THEN 
     string_out1 := 'COMPANY-ID'; 
     string_out2 := 'ES'; 

    END IF; 

END;