Oracle 学习之:ASCII,CHR函数的作用和用法

2014-11-24 18:00:37 · 作者: · 浏览: 0

上面我们的例子中都是单个字符,那么如果是多个字符会有什么结果呢?SELECT ASCII('xy') from dual;结果为120;SELECT ASCII('x') from dual;结果为120。从这两个例子中可能我们已经看出了什么。

"ASCII gives the ascii value of the first character of a string"即:ASCII函数只对你给出的字符串中的第一个字符起作用;

最后我们再介绍几个常用的chr()函数,chr(9);chr(10);chr(13);chr(32);chr(34),其中chr(9)是tab,chr(10)是换行符,chr(13)是回车符,chr(32)是空格符,chr(34)是双引号“"”。

可能有人会对回车和换行有些分不清,因为平常这两个符号是合在一起使用的。回车即回到行首,换行即换到下一行。那我们在oracle中用chr(13)和chr(10)会有区别吗?(结果没有区别,因为现在的语言会自动把它们转成“回车换行”)。即

declare

begin

dbms_output.put_line('huiche');

dbms_output.put_line(chr(10));

dbms_output.put_line('hhh');

end;



declare

begin

dbms_output.put_line('huiche');

dbms_output.put_line(chr(13));

dbms_output.put_line('hhh');

end;

两个块输出的结果是完全一样的。