在项目中遇到CLOB文本字符集的处理,但在处理CLOB字符的时候,我不用DBMS_CLOB包里的函数,而直接用
SUBSTR(RESULT VARCHAR2
       STR1 IN VARCHAR2
       POS IN BINARY_INTEGER
       LEN IN BINARY_INTEGER) ,
INSTR()
TRIM()
...
...
等字符串处理函数来处理CLOB字符串,为什么能正常返回字符串结果呢? VARCHAR2 不是最大支持32676字节吗?但我的CLOB里的字符远超过这个数字,真的很让我纳闷了。--------------------
举个例来说明
DECALRE V_AAA CLOB;
BEGIN
  SELECT SUBSTR(A,1,500000) INTO V_AAA FROM TABLE_1;   /* TABLE_1表中字段A的字符长度有200多万 */
  DBMS_OUPT.PUT_LINE(LENGTH(V_AAA));  /* 输出结果是正确的,为 500000 */
END;SUBSTR()函数为什么没截断字符呢??  不理解....
如果 DECALRE V_AAA CLOB; 申明为 DECALRE V_AAA VARCHAR2(32767);
那么是不能赋值上去了。....难道SUBSTR()函数也能处理大字符串数据?????那还要DBMS_LOB包做什么呢??

解决方案 »

  1.   

    这就是plsql的神奇之处,很多普通函数在sql中只能处理varchar和varchar2,但是到了plsql中就可以处理clob、blob、long等。
      

  2.   


    不是什么SQL中和PL/SQL中的的神奇之处,在SQL中一样也可以.....
    ORACLE对VARCHA2定义好象没说清楚.....
    谁能解开这个迷团,分就是谁的....
      

  3.   

    官方原文:
    The SUBSTR functions return a portion of char, beginning at character position, substring_length characters long. SUBSTR calculates lengths using characters as defined by the input character set. SUBSTRB uses bytes instead of characters. SUBSTRC uses Unicode complete characters. SUBSTR2 uses UCS2 code points. SUBSTR4 uses UCS4 code points.If position is 0, then it is treated as 1.If position is positive, then Oracle Database counts from the beginning of char to find the first character.If position is negative, then Oracle counts backward from the end of char.If substring_length is omitted, then Oracle returns all characters to the end of char. If substring_length is less than 1, then Oracle returns null.char can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. Both position and substring_length must be of datatype NUMBER, or any datatype that can be implicitly converted to NUMBER, and must resolve to an integer. The return value is the same datatype as char. Floating-point numbers passed as arguments to SUBSTR are automatically converted to integers.
      

  4.   

    厉害!楼主可以把你的测试结果告诉Oracle公司。
      

  5.   

    在PL/SQL中是可以做出一些在SQLPLUS中做不出的操作!常见字段类型的最大容量:
    char(2000B)
    varchar2(4000B)CLOB/BLOB/NCLOB 4GB