NTEXT on SQL Server to NVARCHAR2(2000) on Oracle (ORA-12899: value too large for column) - sql-server

My source is in SQL Server and the target is Oracle. There are some tables having columns defined NTEXT in SQL Server and I created columns of NVARCHAR2(2000) which allows 4000 bytes, to store the data from the source.
When I pull the data defined NTEXT from SQL Server, I cast and substring the data to fit into 4000 bytes in the target. I'm using Data Stage by IBM to extract the source form SQL Server and the code below performs converting data type to varchar(4000) and extracting a substring with the specified length, 4000 bytes.
cast(substring([text],1,3950) as varchar(4000)) as "TEXT"
However, it often occurs an error ORA-12899 when it inserts into NVARCHAR2(2000) on Oracle which is sized 4000 bytes.
Error message: ORA-12899: value too large for column (actual: 3095, maximum: 2000).
First, it is hard to understand why it occurs the error even though the destination has a column sized 4000 bytes and I cut the data using SUBSTING already.
Second, I was wondering if I miss anything to handle the issue when my team does not consider CLOB on Oracle for those NTEXT type data.
Please help me to resolve this issue. I'm working on many tables and the error occurs often.

nvarchar2 is limited to 2000 chars, which requires 4000 bytes. You have to specify the limit in chars (so, 2000, not 4000). Try changing your function to:
cast(substr([text],1,2000) as nvarchar2(2000)) as "TEXT"

Related

SSIS: XML to Excel export, truncation may happen due to inserting data from data flow column with a length of 4000 to database column with length 255

I'm using SQL 2008 R2 & Excel of format xlsx. I'm trying to export data to Excel through XML source.Everything is working fine, than for columns where data is more than 255 characters. I get a warning:
truncation may happen due to inserting data from data flow column with
a length of 4000 to database column with length 255
I've tried changing registry and IMEX value as per the blog. This doesn't seem to help me. Also, for me connection string (Excel Connection Manager) is
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Extract_8202014.xlsx;Extended
Properties="EXCEL 12.0 XML;HDR=YES";
As per MDSN for memo type columns we should define datatype as longtext if table is getting created at run time. I've done same. But it's not helping.

Correct mapping of big Visual FoxPro CHAR column to the appropriate SQL Server data type

I am migrating a Visual FoxPro database to SQL Server. One of the tables has a Char column with length 2147483647. I am wondering if the correct data type to use in SQL Server 2008 R2 is Char(2147483647). Is there an alternative type I can use in SQL Server which will not result in any loss of information?
The following image gives a description of the column as shown within Visual Studio 2008.
Visual FoxPro's native CHAR type only allows up to about 255 characters. What you're seeing is a FoxPro MEMO field, translated to a generic OLE equivalent.
A SQL Server VARCHAR(MAX) is the usual proper equivalent, assuming the MEMO is simply user-entered text in a western dialect and not a multi-linqual or data-blob variation.
Be aware that FoxPro does NOT speak UTF natively, so you may have code-page translation issues.
Hope this helps someone else.
MSDN varchar description states:
Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.
The maximum storage for Char is 8000 bytes/characters. varchar(max) on the other hand will use a storage size equal to the actual length of the characters entered plus 2 bytes.

CakePHP truncating large varchar columns from SQL Server database

Using CakePHP 1.3.11 and SQL Server 2005 and the included MSSQL database driver.
I need to retrieve a varchar(8000) field, however the typical find() queries truncate this field to 256 characters; the actual array value array['comment'] is truncated, so the data beyond character 256 isn't accessed by my application at all.
I tried changing the field to a text datatype and with that change the query returns the full value of the column. Is there a way for cake to read the full value of the column or does it always truncate varchars to 256 characters?
Solution has been to use the text data type on the database side.

what advantage does TEXT have over varchar when required length <8000?

SQL Server Text type vs. varchar data type:
As a rule of thumb, if you ever need you text value to exceed 200
characters AND do not use join on this column, use TEXT.
Otherwise use VARCHAR.
Assuming my data now is 4000 characters AND i do not use join on this column. By that quote, it is more advantageous to use TEXT/varchar(max) compared to using varchar(4000).
Why so? (what advantage does TEXT/varchar(max) have over normal varchar in this case?)
TEXT is deprecated, use nvarchar(max), varchar(max), and varbinary(max) instead: http://msdn.microsoft.com/en-us/library/ms187993.aspx
I disagree with the 200 thing because it isn't explained, unless it relate to the deprecated "text in row" option
If your data is 4000 characters then use char(4000). It is fixed length
Text is deprecated
BLOB types are slower
In old versions of SQL (2000 and earlier?) there was a max row length of 8 KB (or 8060 bytes). If you used varchar for lots of long text columns they would be included in this length, whereas any text columns would not, so you can keep more text in a row.
This issue has been worked around in more recent versions of SQL.
This MSDN page includes the statement:
SQL Server 2005 supports row-overflow storage which enables variable
length columns to be pushed off-row. Only a 24-byte root is stored in
the main record for variable length columns pushed out of row; because
of this, the effective row limit is higher than in previous releases
of SQL Server. For more information, see the "Row-Overflow Data
Exceeding 8 KB" topic in SQL Server 2005 Books Online.

Size limit problem with ntext in Sql Server CE 3.5 and Visual Studio

I am experiencing some strange behavior with SQL Server CE 3.5 SP2.
I have a table with 2 columns; one of type int named ID, which is the primary key, and one of type ntext named 'Value'. The 'Value' column is supposed to contain rather long string values. However, when I try to store a string that is longer than 4000 characters, the value turns into an empty string!
I am using the Visual Studio 2010 server explorer to do this.
What's going on? I thought this 4000 character limit was for nvarchar and that ntext had a 2GB limit. Am I forgetting something or are these limits different for SQL Server CE? MSDN is not very clear on this.
According to the documentation the limit is 536,870,911 characters:
http://msdn.microsoft.com/en-us/library/ms172424(v=SQL.100).aspx
This seems to explain what you're seeing:
http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/9fe8e826-7c20-466c-8140-4d3b0649ac09
Alright, after trying a lot of things and reading many obscure posts on the subject, it turned out to be not a sql server CE problem at all, but an issue with Visual Studio.
There is a setting under Options->Database Tools->Query results, that specifies the maximum numbers of characters retrieved from a query. What happened was that after the string was entered in the Server Explorer table editor, it was actually persisted in SQL Server CE but visual studio could not display it due to the aforementioned setting.
The data type NTEXT SQL Server CE can actually store up to 536870911 characters.
This represents a physical space of 1073741822 bytes or about 1 gigabyte, or half of 2Gbytes that SQL Server would store.
But this ability is not so much: Observe other factors that limit this ability.
First, the data file can store a maximum of slightly less than 4 gigabytes, given the reservation of space needed will change pages. A single record with a quarter of that size, so it will be quite time consuming to be loaded, and may appear to be blank spaces (not null) when in fact it is not.
Second, observe some caution with commands to select the data, which can inadvertently convert one type to another.
As an example, can occur converting NTEXT to NVARCHAR, for example, when using an ALIAS for the selected fields. E values ​​above the capacity of the NVARCHAR in fields converted, may appear as blank spaces too.

Resources