Update Clob over a db link - oracle

I am trying to update a clob column over a db link. Is there any best way to do it. Below is my sample code. Currently doing the below has a lot of performance impact.
Running gather stats also does not help much.
The db where the db link points to is an AWS RDS Standard edition.
UPDATE xx_table#rds_dblink
SET finish_timestamp = SYSTIMESTAMP,
api_response = (SELECT api_response
FROM xx_table_gtt
WHERE api_log_id = g_log_id),
response_code = p_response_code,
status = CASE
WHEN p_response_code = 200
THEN
'Success'
WHEN p_response_code = 201
THEN
'Success'
ELSE
'Error'
END
WHERE api_log_id = g_log_id
There is an unique index on the api_log_id column. API Response is a CLOB type.
xx_table_gtt: Is a global temporary table.

I also faced this issue about updating clob through dblink, finally my solution was to create bridge service(I have created service using java) between two databases and update clob through this service. It is an alternative solution, without using dblink.
Will be glad if I could help.

Related

Problem calling a function in a remote spatial database in which a transform function is used

I need to retrieve the coordinates (x,y) in a "spatial" database from a "classic" database through dblink.
here is my Oracle version:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
the dblink between the 2 database works fine.
I have created a Function in the Spatial database which get the SGO_GEOMETRY of an object and return the sdo_point.x
=> that workd fine through dblink
Now I need to transform the current x in another spatial unit.
to do that, I use
MDSYS.SDO_CS.transform
It works fine if a run the function in the Spatial database.
It crashes if I call the function through dblink.
here is my function in the spatial database:
FUNCTION TEST_GEOMETRY
(
p_compteur E_COMPTEUR_ABONNE.numero_reel%type
)
return number is
w_geometry MDSYS.SDO_GEOMETRY;
w_geometry_transformed MDSYS.SDO_GEOMETRY;
begin
begin
select geometry into w_geometry from E_COMPTEUR_ABONNE where numero_reel = p_compteur;
EXCEPTION WHEN no_data_found then return null; -- Compteur non trouvée
end;
return w_geometry.sdo_point.x;
end TEST_GEOMETRY;
if I run it from the "none spatial" database it works fine:
select test.test_geometry#elyx('09P010650') from dual;
result:1711071,438
Now, I replace
return w_geometry.sdo_point.x;
by
w_geometry_transformed :=MDSYS.SDO_CS.transform(w_geometry,4326);
return w_geometry_transformed.sdo_point.x;
it works fine if I run it in the spatial database.
I've got this through DBLINK:
Your database connection has been reset. Any pending transactions or sesseion state has been lost.
At first, I thought it was some kind of authorization missing on my DBLINK user, but MDSYS is PUBLIC.
So I have try another function from the package MDSYS.SOD_CS and it works:
w_test := MDSYS.SDO_CS.tfm_axis_orientation_to_wkt('test');
return 1;
only functions using a MDSYS.SDO_GEOMETRY parameters seemed to failed.
Do you have an idea why and what should be done?
I'm not particularly good at Oracle Spatial, but I know that SDO_GEOMETRY just won't work over a database link.
Fortunately, there are some workarounds, one of them being WKT (Well Know Text) which represents geometry as text. There are two function you can use:
SDO_UTIL.TO_WKTGEOMETRY
SDO_UTIL.FROM_WKTGEOMETRY
so - see if these could help.
For some more reading, have a look at Alex Paterson's blog, describing what else you could do (http://www.tolon.co.uk/2012/09/geometry-objects-across-dblink/).

copy milion record from oracle to another oracle

i have to "copy" 30 milions of record form a table of Oracle12C to the same in another Oracle12C istance (placed on another server, on another subnet, no way to connect both at same time ) via select statement, like:
SELECT * ENVELOPE WHERE ENVELOPE.SUB_DELIVERY_DATE < :dateMax AND ENVELOPE.FLAG_EXTRACTED = 'S'
googling and serching here on s.o. I read somthing about exp or expdp Oracle tools, but i don't want to export all table ( schema, indexs, constraint ), just data.
Can someone help me solve this problem, or show me an alternative solution? thank you so much

CLOB data in Oracle not displaying /fetching completely

I'm trying to fetch out clob data from a table.
In ORACLE SQL DEVELOPER, when am trying to execute a query, its displaying "..." at the end beyond 3800 characters. Could you please help me here to fetch out complete data?
Ex:
select data_clob from sample
Note:
I have tried to use dbms_log.substr as well. but still the error persists.
I have tried to set buffer as well but keep on saying its "skipped."
So please let me know if anyother possibility.

How query from another database that is in another machine/server

I've been looking for answer to this but I can't seem to find the right answer online and my problem goes like this.
I'm trying to query a set of records from another table which is in an another database installed in a different machine. To make it clearer:
My stored procedure is running on IP: 192.168.XX.X1. I get to retrieve all the information I need in this server but I have another set of information or records that can only be retrieved from IP: 192.168.XX.X2.
I was thinking to achieve something like:
DECLARE
-- given that both queries will only return 1 record
CURSOR IS curSample1
SELECT * FROM Database1.Table1;
colSample curSample1%ROWTYPE;
CURSOR IS curSample2
SELECT * FROM Database2.Table1;
colSample curSample2%ROWTYPE;
vText1 VARCHAR(20);
vText2 VARCHAR(20);
BEGIN
OPEN curSample1;
LOOP
FETCH curSample1 INTO colSample1;
EXIT WHEN curSample1%NOTFOUND;
vText1 := colSample1.Column1;
END LOOP;
CLOSE curSample1;
OPEN curSample2;
LOOP
FETCH curSample2 INTO colSample2;
EXIT WHEN curSample2%NOTFOUND;
vText2 := colSample2.Column2;
END LOOP;
CLOSE curSample2;
dbms_output.put_line(vText1 || ',' || vText2);
END;
Any help you could provide will be much appreciated. Thank you very much.
Note: I'm trying this approach as this is the only way we could possibly do it as of now. Thanks again.
You will have to create a db link between your database 1 and database 2. For creating a database link it is not required to have both databases on the same server. Since in your case the databases are on different server you can start with the following steps.
You need a tns entry (pointing to database 2) in the tnsnames.ora file on your database 1 server. You can check if you have this entry by connecting to SQLPLUS from your database 1 machine to database 2.
sqlplus <username>/<password>#<tnsnames of database2>
If you are able to connect from your database 1 server then you can proceed with the following steps for creating the db link.
CREATE DATABASE LINK <dblink_name> CONNECT TO <username> IDENTIFIED BY <password> USING <tnsnames of database2>
Post this you can test your database link by running the following SQL command.
select * from Table#<dblink_name>;
as i know you cannot query data cross database directly.
1,maybe you can use DBlink or DataSync to let the data which in other database can be query.
2,instead of pl/sql procedure, use other development language to do cross DB process is a good idea(ex independent java program).
3,instead of pl/sql procedure, use Oracle Java Procedure to do this.

Oracle single-table constant merge with CLOB using JDBC

As a follow-up to this question, I need help with the following scenario:
In Oracle, given a simple data table:
create table data (
id VARCHAR2(255),
key VARCHAR2(255),
value CLOB);
I am using the following merge command:
merge into data
using (
select
? id,
? key,
? value
from
dual
) val on (
data.id=val.id
and data.key=val.key
)
when matched then
update set data.value = val.value
when not matched then
insert (id, key, value) values (val.id, val.key, val.value);
I am invoking the query via JDBC from a Java application.
When the "value" string is large, the above query results in the following Oracle error:
ORA-01461: cannot bind a LONG value for insert into a long column
I even set the "SetBigStringTryClob" property as documented here with the same result.
Is it possible to achieve the behavior I want given that "value" is a CLOB?
EDIT: Client environment is Java
You haven't mentioned specifically in your post, but judging by the tags for the question, I'm assuming you're doing this from Java.
I've had success with code like this in a project I just finished. This application used Unicode, so there may be simpler solutions if your problem domain is limited to a standard ASCII character set.
Are you currently using the OracleStatement.setCLOB() method? It's a terribly awkward thing to have to do, but we couldn't get around it any other way. You have to actually create a temporary CLOB, and then use that temporary CLOB in the setCLOB() method call.
Now, I've ripped this from a working system, and had to make a few ad-hoc adjustments, so if this doesn't appear to work in your situation, let me know and I'll go back to see if I can get a smaller working example.
This of course assumes you're using the Oracle Corp. JDBC drivers (ojdbc14.jar or ojdbc5.jar) which are found in $ORACLE_HOME/jdbc/lib
CLOB tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
// Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);
// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();
// Write the data into the temporary CLOB
tempClobWriter.write(stringData);
// Flush and close the stream
tempClobWriter.flush();
tempClobWriter.close();
// Close the temporary CLOB
tempClob.close();
myStatement.setCLOB(column.order, tempClob);
Regards,
Dwayne King

Resources