PL / SQL将字符串转换为数字Ascii

时间:2016-06-15 09:07:22

标签: plsql ascii

我有下面的脚本,但我需要将案例更改为ascii 我不知道我需要怎么做。 C 你能帮忙吗?

如果有人可以用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 个答案:

答案 0 :(得分: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;