Oracle SQL Developer not inserting XML in XMLTYPE via loading file - oracle

There is a table with a XMLTYPE column (NOT NULL), XML (string) can be inserted using SQLPLUS but SQL Developer inserts 'null' when XML is loaded from a file.

There is a workaround:- Set XMLTYPE column nullable
, insert null first time , COMMIT and insert XML after that.

Related

storing multibyte character in a single byte characterset environment oracle 12c

Earlier we were storing JSON containing latest 10 conversations in an NCLOB column in database for caching purpose. But now we have to store all the conversations in JSON format and also provide search functionality. To utilize oracle's text search, we tried using BLOB datatype instead of NCLOB. However we are facing problems storing multibyte characters and searching it. Any suggestions on how to use BLOB datatype?
Here's an example of what i'm attempting
--create table with blob column---
create table departments_json (
department_id integer not null primary key,
department_data blob not null
);
---add JSON check constraint ---
alter table departments_json
add constraint dept_data_json
check ( department_data is JSON FORMAT JSON STRICT );
---------------index json column for text search-------
create index deptj_ctx_ix on departments_json (department_data)
indextype is ctxsys.context parameters ('section group CTXSYS.JSON_SECTION_GROUP sync (on commit)');
--Insert Json With Multibyte Characters
insert into departments_json
values ( 100, utl_raw.cast_to_raw ('{"department_list":[{"Deptname":"DEPT-A", "value" : "məharaːʂʈrə"}]}'));
Insert fails with :
ORA-02290: check constraint (REGCOA_SPM.DEPT_DATA_JSON) violated

How to check whether CLOB is null or not in Oracle?

I created table that has one CLOB.
And I am developing web site with Spring framework and Ibatis.
and I try to do select Query like select CLOB_COL from table.
but Ibatis shows NPE.
I guess this problem is from returning null from CLOB column.
this error is shown only when CLOB column is null.
How can I check CLOB is null or not in Query?
And tips is welcomed. Thanks.

Convert ntext to clob

I have to copy data from one table to another which one table is in Oracle and one is in MSSQL Server. I want to copy the data from MSSQL Server table to Oracle table. The problem is that the MSSQL Server table has one column which is of data type ntext and the destination column in Oracle table is clob.
When I use the query
insert into oracle.table select * from sqlserver.table#mssql; I get the following error:
SQL Error: ORA-00997: illegal use of LONG datatype
Can anyone advice on this please?
I tried it through a PL/SQL Procedure and it worked. I created a cursor, passed in the values to my variables declared in VARCHAR2 and then run an EXECUTE IMMEDIATE for the INSERT INTO....SELECT * FROM <TABLE_NAME>#MSSQL.

Changing Storage Option for XMLType column in Oracle 11g

I am using XMLType column in some of my oracle database table. Earlier(in 11.2.0.2) the default storage type considered is CLOB. So If you issue a query for the XMLType columns, I can see the content of the column as XML string. But when I drop and re-create all the tables and inserted some data, I could not get the content of the XMLType columns. It simpley display the XMLType in the cloumn value. I have a doubt that whether the storage type is chaged in BINARY XML? So I issue the following alter statement:
ALTER TABLE "MYSCHEMA"."SYSTEMPROP"
MODIFY ("XMLCOL")
XMLTYPE COLUMN "XMLCOL" STORE AS CLOB;
Please note that there are already some data present in the table. Event after when I delete and insert a row, the content is showing as XMLType. I am using SQL developer UI tool. Can anybody suggest a way to fix this issue?
Edit:
Ok, Now we have decided that we will store the XMLType column content as SECURE FILE BINARY XML. So we have table like this:
CREATE TABLE XMYTYPETEST
(
ID NUMBER(8) NOT NULL,
VID NUMBER(4) NOT NULL,
UserName VARCHAR2(50),
DateModified TIMESTAMP(6),
Details XMLType
)XMLTYPE COLUMN Details STORE AS SECUREFILE BINARY XML;
Insert into XMYTYPETEST values(10001,1,'XXXX',sysdate,'<test><node1>BLOBTest</node1></test>');
Select * from XMYTYPETEST;
The XMLType colum is displayed as "SYS.XMLType" in sql developer. So how to get the content of the binary XML?
Edit:
SELECT x.ID,x.Vid, x.details.getCLOBVal() FROM XMYTYPETESTx where x.ID=100000;
The above query works out for me finally.
The underlying storage for xmldata inside oracle database is either CLOB or Binary.
And it defaults to Binary storage in 11g.
But irrespective of the storage, your queries on the xmltype column should yield you consistent results.
>>>> So how to get the content of the binary XML?
The way to get the content of an xmltype column using queries does not change.
select xmlquery(..)
select xmlcast(xmlquery(...))
select extract(), extractValue(), ...
These are some of the ways data within xml is extracted.
Hope this helps.

ODBC with Oracle Trigger Key Column

I'm trying to update some existing code that is supposed to write data to a variety of Databases (SQL, Access, Oracle) via ODBC, but I'm having a few problems with Oracle and am looking for any suggestions.
I've set my Oracle database up using a Trigger (basic tutorial online, which I'd like to support).
CREATE TABLE TABLE1 (
RECORDID NUMBER NOT NULL PRIMARY KEY,
ID VARCHAR(40) NULL,
COUNT NUMBER NULL
);
GO
CREATE SEQUENCE TABLE1_SEQ
GO
CREATE or REPLACE TRIGGER TABLE1_TRG
BEFORE INSERT ON TABLE1
FOR EACH ROW
WHEN (new.RECORDID IS NULL)
BEGIN
SELECT TABLE1_SEQ.nextval
INTO :new.RECORDID
FROM dual;
end;
GO
I then populate a DataTable using a SELECT * FROM TABLE1. The first problem is that this DataTable doesn't know that the RecordId column is auto-generated. If I have data in my table then I can't alter it because I get a error
Cannot change AutoIncrement of a DataColumn with type 'Double' once it
has data.
If I continue, ignoring this, then I quickly get stuck. If I create a new DataRow and try to insert it, I can't set RecordID to DBNull.Value because it complains that the column has to be non-null (NoNullAllowedException). I can't however generate a value myself, because I don't know what value I should be using really, and don't want to screw up the trigger by using the next available value.
Any suggestions on how I should insert data without ODBC complaining?
It does not appear that your first problem is with an Oracle database. There is no such thing as an "Autoincrement" column in Oracle. Are you sure that message is coming from an Oracle database?
With Oracle, you should be able to provide any dummy value on insert for the primary key, and the trigger will overwrite it.
There is also nothing in your provided description that would prevent you from updating this value in Oracle (since your trigger is on insert only) unless you have foreign key references to the key.

Resources