2016-06-15 52 views
1

我有下面的腳本,但我需要將案例更改爲ascii 我不明白我需要怎麼做。 C 你能幫忙嗎?PL/SQL將字符串轉換爲數字Ascii

如果有人可以重寫我的ASCII碼這將是偉大的,因爲我沒有看到它:( 感謝您的熱心幫助。

SET SERVEROUTPUT ON; 
CREATE OR REPLACE FUNCTION convert_number(
    p_resultaat IN VARCHAR2) 
    RETURN VARCHAR2 
IS 
    -- variabelen 
    v_newStudentNumber VARCHAR2(255); 
    v_letter VARCHAR2(2); 
BEGIN 
    FOR i IN 1..length(p_resultaat) 
    LOOP 
     v_letter := SUBSTR(p_resultaat, i, 1); 
     v_newStudentNumber := v_newStudentNumber || 
    CASE v_letter 
    WHEN 'A' THEN 
     '16' 
    WHEN 'B' THEN 
     '17' 
    WHEN 'C' THEN 
     '18' 
    WHEN 'D' THEN 
     '19' 
    WHEN 'E' THEN 
     '20' 
    WHEN 'F' THEN 
     '21' 
    WHEN 'G' THEN 
     '22' 
    WHEN 'H' THEN 
     '23' 
    WHEN 'I' THEN 
     '24' 
    WHEN 'J' THEN 
     '25' 
    WHEN 'K' THEN 
     '26' 
    WHEN 'L' THEN 
     '27' 
    WHEN 'M' THEN 
     '28' 
    WHEN 'N' THEN 
     '29' 
    WHEN 'O' THEN 
     '30' 
    WHEN 'P' THEN 
     '31' 
    WHEN 'Q' THEN 
     '32' 
    WHEN 'R' THEN 
     '33' 
    WHEN 'S' THEN 
     '34' 
    WHEN 'T' THEN 
     '35' 
    WHEN 'U' THEN 
     '36' 
    WHEN 'V' THEN 
     '37' 
    WHEN 'W' THEN 
     '38' 
    WHEN 'X' THEN 
     '39' 
    WHEN 'Y' THEN 
     '40' 
    WHEN 'Z' THEN 
     '41' 
     ELSE 
     v_letter 
    END; 
    END LOOP; 
RETURN v_newStudentNumber; 
END convert_number; 

回答

1

您可以通過select ASCII('a') from dual;

實現試試這個代碼: -

create or replace 
FUNCTION convert_number(
    p_resultaat IN VARCHAR2) 
    RETURN VARCHAR2 
IS 
    -- variabelen 
    v_newStudentNumber VARCHAR2(255); 
    v_letter VARCHAR2(2); 
BEGIN 
    FOR i IN 1..length(p_resultaat) 
    LOOP 
     V_Letter := Substr(P_Resultaat, I, 1); 
     V_Newstudentnumber := V_Newstudentnumber || 
     ascii(v_letter); 

    -- END; 
    END LOOP; 
Return V_Newstudentnumber; 
END convert_number; 
+0

這是解決方案,非常感謝您的大力幫助! – voetbalsuuske