ORA-00910: specified length too long for its datatype - oracle

I have a column in Oracle to store comments of Nvarchar2(2000). When a user tries to enter beyond 2000 characters, I get the following error:
ORA-00910: specified length too long for its datatype.
The NLS_NCHAR_CHARACTERSET parameter is having AL16UTF16 value.
Is there any way to increase the size to accept up to 6000 characters? My column already has lots of contents, so not sure if I will be able to change the datatype from NVarchar(2000) to any other.

Unless you use Oracle 12c, it's not possible to store more than 2000 characters, see the datatypes description here:
http://docs.oracle.com/cd/B28359_01/server.111/b28320/limits001.htm
Instead, you should use the NCLOB datatype.
If you use 12c, check: http://dbasolved.com/2013/06/26/change-varchar2-to-32k-12c-edition/

Related

convert DB2 column with varbinary datatype to equivalent in oracle

I have column datatype on db2 as
"column name" VARBINARY(2000) defalut Binary(X'20')
I need its equivalent column datatype and default value for oracle
Use RAW or LONG RAW Datatype, However Oracle recommends BLOB and BFILE datatypes for large amounts of binary data.
Check this link for further information
Use Oracle type RAW or LONG RAW , and use the same default value.
Example:
,mycol raw(2000) default to_number(' ')
datatype replacement for VARBINARY is raw in oracle( as per remaining answers).
But the default value for Binary(X'20') is representing a space.
As the hexadecimal value for a space is 20,and for that reason its mentioned as X'20'.
select rawtohex(' ') from dual; which will give you 20.

How did the unicode characters endup in the database table column?

Recently I came across a unicode character (\u2019) in a database table column while parsing using Python.
Question: What are the reasons that can result in unicode characters showing up in the database table? Is it data entry issue?
Appreciate any input.
When you set up your Oracle Database you choose a character set which will be used in the SQL char datatypes (char, varchar2 etc).
Suppose you chose your character set and you have a table with a column of VARCHAR2 type. Suddenly you need to store some string with non-ASCII symbols not supported by your database (chosen character set). You may convert this string into ASCII string by calling ASCIISTR function for example and store it in your VARCHAR2 column (but it's not a good idea because many SQL built-in functions don't understand '\u2019' (they think it's just 6 symbols)). That's how Unicode may appear in your table column (ASCIISTR converts non-ascii symbols into unicode representation such as '\u2019').
Another option is special Oracle nchar datatypes which were designed to store UNICODE without altering global database settings.
Here is the link with Oracle documentation: https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch6unicode.htm

Char Vs Byte in Oracle

I am comparing two databases which have similar schema. Both should support unicode characters.
When i describe the same table in both database, db 1 shows all the varchar fields with char, (eg varchar(20 char)) but the db2 shows without char, (varchar(20)
the second schema supports only one byte/char.
When i compare nls_database_parameters and v$nls_parameters in both database its all same.
could some one let me know what may be the change here?
Have you checked NLS_LENGTH_SEMANTICS? You can set the default to BYTE or CHAR for CHAR/VARCHAR2 types.
If these parameters are the same on both datbases then maybe the table was created by explicitly specifying it that way.

Why is it necessary to specify length of a column in a table

I always wonder why should we limit a column length in a database table to some limit then the default one.
Eg. I have a column short_name in my table People the default length is 255 characters for the column but I restrict it to 100 characters. What difference will it make.
The string will be truncated to the maximum length ( in characters usually ).
The way it is actually implemented is up to the database engine you use.
For example:
CHAR(30) will always use up 30 characters in MySQL, and this allows
MySQL to speed up access because it is able to predict the value
length without parsing anything;
VARCHAR(30) will trim any lengthy strings to 30 characters in MySQL when strict mode is on, otherwise you may use longer strings and they will be fully stored;
In SQLite, you can store strings in any type of column, ignoring the type.
The reason many features of SQL are supported in those database engines eventhough they are not being utilized, or being utilized in different ways, is in order to maintain compliance to the SQL schema.

oracle: what is the oracle equivalent data type for COMMENT?

What is the datatype in oracle i should be using to store comment boxes? I was going to use LONG but it only allows one. Or should I just use VARCHAR2 and set it really large?
What is the longest comment you want to be able to support?
If your comments are less than 4000 bytes in length, you can use a VARCHAR2(4000). If your comments are longer than 4000 bytes in length, you can use a CLOB. A CLOB can store any character data supported by your database character set.

Resources