Oracle 11G重复输出output_put.put_line两次。怎么解决这个?

时间:2015-05-16 17:16:32

标签: string oracle11g output dbms-output

我的循环给了我两倍的结果。因为我只想要一次。我该怎么办?

 for i in 1..length(newStudentNumber) loop
    character := SUBSTR(newStudentNumber, i, 1);
    newStudentNumber := newStudentNumber || case character
     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 character
    end;
  end loop;
  dbms_output.put_line(newStudentNumber);

我希望我对这个问题不要太模糊

提前致谢

1 个答案:

答案 0 :(得分:1)

在循环中,您将可能转换的字符附加到正在循环的相同字符串变量newStudentNumber。如果您不想要旧值和新值,则需要在循环中填充第二个变量。

  -- new variable, which has to be declared
  convertedStudentNumber := null;
  for i in 1..length(newStudentNumber) loop
    character := SUBSTR(newStudentNumber, i, 1);
    convertedStudentNumber := convertedStudentNumber || case character
    ...
    else character
    end;
  end loop;
  dbms_output.put_line(convertedStudentNumber);

现在两个变量有不同的值,一个从TUE...开始,另一个从353620...开始。