2011-10-18 99 views
1

我在oracle中有一個函數,我需要將它轉換爲c#代碼 請幫助或告訴我任何鏈接。需要將oracle函數轉換爲c#代碼

create or replace 
FUNCTION    "GETSEPARATEDSTRING" 
( pString  IN VARCHAR2 
    ,pSeparator  IN VARCHAR2 
    ,pReturnNumber IN PLS_INTEGER 
) 
RETURN VARCHAR2 
IS 
l_SearchString_FinPos   PLS_INTEGER :=0; 
l_SearchString_StartPos   PLS_INTEGER :=0; 
l_SearchString_Length   PLS_INTEGER :=0; 
l_SearchString_CurrentPos  PLS_INTEGER :=0; 
l_Return      VARCHAR2(4000); 

BEGIN 
    -- expecting values as String Seperator String Seperator 
    -- so if pReturnNumber = 2 then where are 
    -- looking for seperators 2 and 1. If there is no seperator 
    -- at the end of the string it is added before comparison, 
    -- Will return a null if: 
    -- The length of pString is > 4000 
    -- The pSeparator has not been specified 
    -- The pReturnNumber IS <= 0 
    -- The pReturnNumber IS greater than the number of pSeparator + 1 and therefore we can't pick up a string 
    -- There was an empty string at the position requested 
    -- Strings are returned without pSeparator 

    IF  LENGTH(pString || pSeparator) <= 4000 
    AND pSeparator      IS NOT NULL 
    AND pReturnNumber     > 0 
    THEN 
    l_SearchString_FinPos  := pReturnNumber; 

    l_SearchString_StartPos  := pReturnNumber - 1; 

    -- Concat a seperator at the end of the string so at least we 

    -- know there is one 

    IF INSTR(pString, pSeparator, -1, 1) != (LENGTH(RTRIM(pString)) - LENGTH(pSeparator) + 1) 

    THEN 

     -- There isn't one at the end so add it 

     l_Return      := pString || pSeparator; 

     --DBMS_OUTPUT.PUT_LINE('Did not find seperator - ADDING'); 

    ELSE 

     l_Return      := pString; 

     --DBMS_OUTPUT.PUT_LINE('FOUND seperator'); 

    END IF; 

    -- Set the start position of where we will check to the 

    -- the last position we found a pSeparator value. 

    l_SearchString_CurrentPos := l_SearchString_FinPos; 

    -- Search for the next pSeparator position 

    l_SearchString_FinPos  := INSTR(l_Return, pSeparator, 1, l_SearchString_CurrentPos); 

    IF l_SearchString_FinPos != 0 

    THEN 

     IF l_SearchString_StartPos != 0 

     THEN 

     l_SearchString_CurrentPos := l_SearchString_StartPos; 

     l_SearchString_StartPos := INSTR(l_Return, pSeparator, 1, l_SearchString_CurrentPos) + 1; 

     ELSE 

     -- If we are looking for the first value then StartPos will = 0 

     -- and cause INSTR to fail 

     l_SearchString_CurrentPos := 1; 

     END IF; 

     l_SearchString_Length  := l_SearchString_FinPos - l_SearchString_StartPos; 

     l_Return     := RTRIM(SUBSTR(l_Return, l_SearchString_StartPos, l_SearchString_Length), pSeparator); 

    ELSE 

     l_Return := NULL; 

    END IF; 

    END IF; 

    RETURN l_Return; 

EXCEPTION 

WHEN OTHERS 

THEN 

    DBMS_OUTPUT.PUT_LINE('FUNCTION GetSeperatedString Captured Error: ' || SQLERRM); 

    RETURN NULL; 
END; 
+0

我不知道PL/SQL的所有,但不是這只是[String.Split](http://msdn.microsoft.com/en-us /library/b873y76a.aspx) – billinkc

+0

只是爲了讓它變得簡單呃給任何人解決這個pl/sql程序的高級目的是什麼? – Kuberchaun

+0

如果你提供這個函數的幾個樣本輸入/輸出並描述應該做什麼而不是隻是拋出代碼並尋求幫助,那對你來說會非常好。並非所有人都知道或掌握了Oracle,但許多人都可以編寫C#。 – Icarus

回答

2

我不明白你爲什麼不能自己轉換它?問題是什麼?你甚至會得到一個評論,描述該功能在做什麼。

做這樣的事情:

  1. 轉換方法簽名和所有本地變量C#的。
  2. 查詢看到INSTR的文件,如果使用基於零的索引爲string.IndexOf
  3. 做直轉換通過一次
  4. 測試功能
  5. 看着一個行以重命名所有的變量有C#的名字
  6. 重構利用C#