1

I'm still a bit of a stranger when it comes to character set and encoding, so I apologize in advance for any of my misconception.

I'm using Oracle 10g as a DBMS for my web application. My database is configured to UTF-8.

Database information:

SQL> SELECT * FROM NLS_DATABASE_PARAMETERS

PARAMETER                      VALUE
------------------------------ --------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CHARACTERSET               UTF8
NLS_CALENDAR                   GREGORIAN
NLS_DATE_FORMAT                DD-MON-RR
NLS_DATE_LANGUAGE              AMERICAN
NLS_SORT                       BINARY
NLS_TIME_FORMAT                HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT           DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY              $
NLS_COMP                       BINARY
NLS_LENGTH_SEMANTICS           BYTE
NLS_NCHAR_CONV_EXCP            FALSE
NLS_NCHAR_CHARACTERSET         UTF8
NLS_RDBMS_VERSION              10.2.0.3.0

I have a database table that contains a column with a width limit of 1500.

Table details:

COLUMN_NAME                    DATATYPE
------------------------------ --------------------------------
TEST_COLUMN                    VARCHAR2(1500 BYTE)

Initially, being the noobie I am, I thought that the 1500 limit, which was set to the column, was a unit of number of CHARACTER, but found out later that it actually is the unit of number of BYTE.

What I am aiming at is to limit the number of character's to 1500, thus setting VARCHAR2(1500) would only apply to single-byte encoding.

So because I am using UTF-8, which uses multi-byte encoding, I was wondering what would be the correct value to set on my column width which would limit it to 1500 multi-byte character?

4

1 回答 1

3

When you create the column you need to specify character length semantics, like this:

test_column varchar2(1500 char)

You can set a default through NLS_LENGTH_SEMANTICS. It's possible that your scripts may have worked correctly in a different environment because of the server or session parameters. But it is probably better to explicitly set each column.

于 2012-10-31T20:14:53.630 回答