DECLARE
l_char VARCHAR2 (3000 )
:= ‘ORACLEEB电子商务套件SSYSTEMghtest‘ ;
l_length NUMBER ;
l_line_char VARCHAR2 (1000 ); --每个字符
l_lengthb NUMBER ; --每个字符的字节长度,汉字变成2个
l_lengthb_total NUMBER := 0 ; --字节长度:汉字算2个
l_char_display VARCHAR2 (1000 ); --换行显示的字符
BEGIN
l_length := length (l_char);
dbms_output.put_line( ‘l_length:‘ ||
l_length);
FOR i IN 1 ..
l_length LOOP
SELECT substr (l_char,
i, 1) INTO l_line_char FROM dual;
--dbms_output.put_line(‘l_line_char:‘||l_line_char);
IF lengthb (l_line_char)
= 3 THEN
--汉字
l_lengthb := 2 ;
ELSE
l_lengthb := 1 ;
END IF ;
l_lengthb_total := l_lengthb_total + l_lengthb;
l_char_display := l_char_display || l_line_char;
IF l_lengthb_total
= 12 THEN
--l_char_display
:= l_char_display || CHR(10);
--12位换行显示
dbms_output.put_line( ‘l_char_display:‘ ||
l_char_display);
l_lengthb_total := 0 ;
l_char_display := NULL ;
END IF ;
END LOOP ;
dbms_output.put_line( ‘l_char_display:‘ ||
l_char_display);
END ;
输出:
l_char_display:ORACLEEB电子
l_char_display:商务套件SSYS
l_char_display:TEMghtest
二、使用回车符
DECLARE
l_char VARCHAR2 (3000 )
:= ‘ORACLEEB电子商务套件SSYSTEMghtest‘ ;
l_length NUMBER ;
l_line_char VARCHAR2 (1000 ); --每个字符
l_lengthb NUMBER ; --每个字符的字节长度,汉字变成2个
l_lengthb_total NUMBER := 0 ; --字节长度:汉字算2个
l_char_display VARCHAR2 (1000 ); --换行显示的字符
BEGIN
l_length := length (l_char);
FOR i IN 1 ..
l_length LOOP
SELECT substr (l_char,
i, 1) INTO l_line_char FROM dual;
--dbms_output.put_line(‘l_line_char:‘||l_line_char);
IF lengthb (l_line_char)
= 3 THEN
--汉字
l_lengthb := 2 ;
ELSE
l_lengthb := 1 ;
END IF ;
l_lengthb_total := l_lengthb_total + l_lengthb;
l_char_display := l_char_display || l_line_char;
IF l_lengthb_total
= 12 THEN
l_char_display := l_char_display || CHR (10 );
--12位换行显示
l_lengthb_total := 0 ;
END IF ;
END LOOP ;
dbms_output.put_line( l_char_display);
END ;
输出:
ORACLEEB电子
商务套件SSYS
TEMghtest