Struggling with LOBs - sql

I am struggling on figuring out how to search in a LOB. I was trying the following but got the ORA-19011: Character string buffer too small, error
select * from gtpintr_data.sagadata sa where SA.DATA like '4780471';

The SQL LIKE command only works on varchar-type datatypes like VARCHAR2. Oracle has to convert the LOB to a string in order to run your query, so if it cannot fit it into the maximum size for a string it will fail.
You could use DBMS_LOB.INSTR in a PL/SQL program instead:
http://docs.oracle.com/database/121/ARPLS/d_lob.htm#ARPLS66715
But that will be slow as you would need to call it for each row in the table.
A better alternative is to add an Oracle Text index on the column and use the CONTAINS operator.
http://docs.oracle.com/database/121/CCREF/toc.htm

Related

Query remote oracle CLOB data from MSSQL

I read different posts about this problem but it didn't help me with my problem.
I am on a local db (Microsoft SQL Server) and query data on remote db (ORACLE).
In this data, there is a CLOB type.
CLOB type column shows me only 7 correct data the others show me <null>
I tried to CAST(DEQ_COMMENTAIRE_REFUS_IMPORT AS VARCHAR(4000))
I tried to SUBSTRING(DEQ_COMMENTAIRE_REFUS_IMPORT, 4000, 1)
Can you help me, please ?
Thank you
No MSSQL but in my case we were pulling data into MariaDB using the ODBC Connect engine from Oracle.
For CLOBs, we did the following (in outline):
Create PLSQL function get_clob_chunk ( clobin CLOB, chunkno NUMBER) RETURN VARCHAR2.
This will return the the specified nth chunk of 1000 chars for the CLOB.
We found 1,000 worked best with multibyte data. If the data is all plain text single byte that chunks of 4,000 are safe.
Apologies for the absence of actual code, as I'm a bit rushed for time.
Create a Oracle VIEW which calls the get_clob_chunk function to split the CLOB into 1,000 char chunk columns chunk1, chunk2, ... chunkn, CAST as VARCHAR2(1000).
We found that Oracle did not like having more than 16 such columns, so we had to split the views into sets of 16 such columns.
What this means is that you must check what the maximum size of data in the CLOB is so you know how many chunks/views you need. To do this dynamically adds complexity, needless to say.
Create a view in MariaDB querying the view.
Create table/view in MariaDB that joins the chunks up into a single Text column.
Note, in our case, we found that copying Text type columns between MariaDB databases using the ODBC Connect engine was also problematic, and required a similar splitting method.
Frankly, I'd rather use Java/C# for this.

Inserting large xml data into DB2

I have the following situation,
in my database table I have a column for storing xml data. When I try to insert data into this table by using Insert query, I am getting string is too large exception.
I tried keeping the type as XML and VACHAR(32000), I get the same exception.
Can anyone help me with this?
UPDATE
This is the error I am getting while inserting.
The string constant beginning with "'<!--Sample XML file generated by XMLSpy v2013 sp1 (http://www.altova." is too long.. SQLCODE=-102, SQLSTATE=54002, DRIVER=3.59.81
The XMLPARSE function is useful for converting text strings into DB2's XML data type. Have you tried wrapping your XML text with a call to XMLPARSE?
If your XML document is in a file, there's a UDF you can add that makes it easier to pull the file contents directly into an XML column.
you can set the size of each column in your table. Try changing the default size(which is not max size) to an appropriate one.
Also when you try to query directly using SQL command line, the DBMS has to create a large string constant form its string pool that can hold your XML(which in this case, is very large and hence String cannot be created). If you query the same programmatically though, it works.
If the same error persists or if DBMS throws Data Integrity error, then try changing the data structure to a bigger one like CLOB(most likely in this case) or BLOB(in case of images and multi media).
It's a bit silly but the answer is use the XMLPARSE and segment your XML string in 32K chunks and prepend a CLOB statement to override the string size limitation
XMLPARSE ( DOCUMENT
CLOB('<?xml version="1.0"?>') ||
'<aLotOfVeryBigXmlData32kPart1 ......
' ||
'<aLotOfVeryBigXmlData32kPart2 ......
' ||
... etc ...
'<aLotOfVeryBigXmlData32kPartN ......
' )

inserting value in long raw column

I am required to test something with a long raw column in Oracle DB. For this I need to insert a value of length, say 4000, in that column. The data can be something simple like "AAAA ..." 4000 times. I tried inserting a large value using sqlplus but get the following error (perhaps due to length limitations in sqlplus ?
ERROR:
ORA-00972: identifier is too long
Is it possible to insert a large value into the long raw column using sqlplus ?
This is a limitation of sqlplus where the input cannot be more than 2499 characters.
I would suggest that you do the insert as part of a two step process.
Insert data into the table.column but keep the data less then 2500 characters.
Update the same column and concatenate the rest of the data to the already inserted data.
Not an ideal scenario, but as far as I can see, this is the only way if you want to use sqlplus.
In Oracle, "AAA" is an identifier, and 'AAA' is a string value.

Varchar2 and Oracle quick question

Hi guys I'm using varchar2 for a product name field, but when I query the database from the run SQL command line it shows too many empty spaces, how can I fix this without changing the datatype
here is the link to the ss
http://img203.imageshack.us/img203/20/varchar.jpg
The data that got inserted into the database (probably through some ETL process) had spaces which were not trimmed.
You could update using (pseudo code)
Update Table Set Column = Trim(Column)
If TRIM does not change the results, that tells you that there are not trailing spaces in the actual database rows; they're just being added as part of the formatted screen output.
By default, sqlplus (the command-line Oracle tool you appear to be using) uses the maximum length of the varchar2 column as the (fixed) width when displaying the results of a select statement.
If you want to change this, use the column format sqlplus command before running the select. For example:
column DEPT_NAME format a20
Hi
Try to use trim on both sides,
Update TableName set FieldName = RTrim(LTrim(FieldName))
Regards

Change SQL decimal delimiter

I am trying to import data into my table using
INPUT INTO
The problem is my decimals is using , as a delimiter, and it expects .. So it won't work!
How can i change this? Search and replace in the input file is not an option!
I am using SQL Anywhere 10
I don't believe that it's possible to change the decimal delimiter. You could either preprocess the file (which I know you said is not an option) or load it into a temporary table with the decimal column defined as a string and then use an insert from the temporary table to your real table, performing the necessary conversion at that point.