이 페이지는 기계 번역되었습니다. 영어 원본을 읽어보세요. English

IBSurgeon 라이브러리

VARCHAR(10)에 29자를 넣는 방법

Firebird 금요일 농담 #6 (https://t.me/firebirdsql에서)

오래됐지만 여전히 좋은 농담: 멀티바이트 문자 집합에서는 선언된 것보다 더 많은 기호를 삽입할 수 있습니다. Unicode를 배우세요! :)

즐거운 시간 되세요!

Code
C:\HQbird\Firebird25.in>isql
Use CONNECT or CREATE DATABASE to specify a database
SQL> create database "c:\databases\test1.fdb" user "SYSDBA" password "masterkey";
SQL> create table t2(v1 varchar(10) character set UNICODE_FSS);
SQL> insert into t2(v1) values('12345678901');
SQL> insert into t2(v1) values('123456789012');
SQL> insert into t2(v1) values('1234567890123');
SQL> insert into t2(v1) values('12345678901234');
SQL> insert into t2(v1) values('123456789012345');
SQL> insert into t2(v1) values('1234567890123456');
SQL> insert into t2(v1) values('12345678901234567');
SQL> insert into t2(v1) values('1234567890123456789101234');
SQL> insert into t2(v1) values('12345678901234567891012345');
SQL> insert into t2(v1) values('123456789012345678910123456');
SQL> insert into t2(v1) values('1234567890123456789101234567');
SQL> insert into t2(v1) values('12345678901234567891012345678');
SQL> insert into t2(v1) values('123456789012345678910123456789');  <--- 29 characters!
SQL> insert into t2(v1) values('1234567890123456789101234567890');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
SQL> create table t3(v1 varchar(10) character set UTF8);
SQL> insert into t2(v1) values('1234567890');
SQL> insert into t2(v1) values('12345678901');
SQL> insert into t2(v1) values('123456789012');
SQL> insert into t2(v1) values('123456789012345678');
SQL> insert into t2(v1) values('1234567890123456789');
SQL> insert into t2(v1) values('12345678901234567890');
SQL> insert into t2(v1) values('123456789012345678901');
SQL> insert into t2(v1) values('12345678901234567890123');
SQL> insert into t2(v1) values('1234567890123456789012345678');
SQL> insert into t2(v1) values('123456789012345678901234567890');
SQL> insert into t2(v1) values('1234567890123456789012345678901');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
SQL>

2.5에서는 작동하지만, 3.0에서는 utf8에서 다르게 동작합니다

Code
SQL> create table t2(v1 varchar(10) character set UNICODE_FSS);
SQL> insert into t2(v1) values('12345678901');
SQL> insert into t2(v1) values('12345678901234567890');
SQL> insert into t2(v1) values('12345678901234567890123456789');
SQL> insert into t2(v1) values('123456789012345678901234567890');
SQL> insert into t2(v1) values('1234567890123456789012345678901');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
-expected length 10, actual 30
SQL> create table t3(v1 varchar(10) character set utf8);
SQL> insert into t3(v1) values('1234567890');
SQL> insert into t3(v1) values('12345678901');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
-expected length 10, actual 11
SQL>