Inserting to a clob field using cx_Oracle via a stored procedure
Hello,
Does anyone have experience using cx_Oracle to call a stored procedure which inserts to a clob field? I have found examples of doing this via straight SQL but I was hoping it was possible to do this via a stored procedure call. Thanks for any help you can provide.
Jason
And cursor.callproc('insert_clob_proc', (clob,))
doesn't work for you?
PrzemekYes - I should have been more clear in my original post. The callproc function works until we have a value which is over 32K. At values over 32K, we get an error message "ORA-01460: unimplemented or unreasonable conversion requested". I believe this is because we are sending the value as a string and so we would need to figure out how to send as a CLOB in cx_Oracle? Here is some code to use to test if interested...
Oracle (Oracle Database 10g Release 10.1.0.4.0 - Production):
CREATE TABLE clob_test (CLOB_FIELD CLOB);
CREATE OR REPLACE PROCEDURE ins_clob_test (v_clob_field IN CLOB)
AS
BEGIN
INSERT INTO clob_test (clob_field) VALUES (v_clob_field);
END ins_clob_test;
Python (2.5):
conn = cx_Oracle.connect(xhash['oraclelogin'])
cursor = conn.cursor()
clob_var = 'Some test data' * 10000
cursor.callproc('ins_clob_test',(clob_var,))
conn.commit()
cursor.close()
conn.close()
I should also mention that I am the Oracle developer and not the Python programmer - my knowledge of Python is very limited. I would like the Python programmers to use the procedures (packages) I have created to do their inserts but this situation has caused them to put the SQL directly in their code.
Thanks again for any assistance you can provide.
Jason
Similar Messages
-
Using temporary tables in stored procedures
Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
What is the way of using temporary tables in stored procedures?It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
Example:
Create or Replace Procedure Proc_TestDynamicSQL is
Begin
Execute Immediate 'Create table myTable as select * from user_tables' ;
Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
End;
In this case, Oracle wouldn't care about the table references during compilation. -
Use database inside a stored procedure
Hi guys, a stupid question: I'm working with several database and sometimes I'm afraid to run an alter or a create something in the wrong database, bear in mind that several database have the same tables. Sometime happens to run a query oin the db A
instead in the db B. So, the question: If I create a procedure like this,
create procedure creatingPillar as
use USA
begin
IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N'pillarretail') AND type in (N'U'))
DROP TABLE PillarRetail
create table PillarRetail (anid int , ancore varchar(20), period dec(18,6), settlem datetime2,
settlementper int, asf dec(18,6),astlf dec (18,6), tot dec (18,6) )
insert into PillarRetail select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot from createsemipillar2011
insert into PillarRetail select select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot createsemipillar
end
but I'm wondering if is useless to put the use USA in the stored procedure by the moment that I'm creating the procedure in USA. I mean, having the SP in the USA db even if I run the procedure from another db it should run in USA. Just a stupid question
I know but I got this doubt...
ThanksYou may try as below:
create proc as below: (This will create the proc in USA database.
use USA
Go
create procedure dbo.creatingPillar as
begin
IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N'pillarretail') AND type in (N'U'))
DROP TABLE PillarRetail
create table PillarRetail (anid int , ancore varchar(20), period dec(18,6), settlem datetime2,
settlementper int, asf dec(18,6),astlf dec (18,6), tot dec (18,6) )
insert into PillarRetail select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot from createsemipillar2011
insert into PillarRetail select select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot createsemipillar
end
Then you can call as below:
Exec USA.dbo.creatingPillar -
Using Copy statement in Stored procedure
The following statement works in sqlplus session:
copy from comment/password@servername append amcomment_temp using
select * from amcomment
where commentid in(1,2,3,4)
I want to use this in a stored procedure. There is a long datatype in this table. The
procedure will not compile. Have tried execute immediate and compiler rejects this statement also.'COPY' is a SQL*Plus command, not PL/SQL. This is why the PL/SQL compiler throws it out.
-
How to use order by in stored procedure base block?
How to use order by in stored procedure base block? I need to change order by dynamically
Use SET_BLOCK_PROPERTY('BLOCK_NAME',ORDER_BY,'COLUMN_NAME1, COLUMN_NAME2');
-
Using VIEW inside a stored procedure
Hi,
So I have a View designed in one file that validates someone who is authorized.
Then I have a stored procedure to display authorized stationeries created before a given date. Its takes a parameter @CreatedOn.
How can I use VIEW in my stored procedure so I can display all the authorized which are set 1 before a given date?
My VIEW:
ALTER VIEW vw_AuthorizedStationeries AS
SELECT Authorized
FROM dbo.Stationeries
WHERE Authorized = 1
And my stored procedure:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)ASBEGINSELECTFROMENDGO
Thanks!Try something like below, You need to replace CreatedDate column with appropriate date column in your table.
1. Alter the view to get the required date:
ALTER VIEW vw_AuthorizedStationeries AS
SELECT Authorized, CreatedDate
FROM dbo.Stationeries
WHERE Authorized = 1
2. Alter SP:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
AS
BEGIN
SELECT Authorized
FROM vw_AuthorizedStationeries
WHERE CreatedDate <= @CreatedOn
END
GO
OR
You can pull required information directly from your table:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
AS
BEGIN
SELECT Authorized
FROM dbo.Stationeries
WHERE CreatedDate <= @CreatedOn and Authorized = 1
END
GO
If this post answers your query, please click "Mark As Answer" or "Vote as Helpful". -
Can rs.last() be used after calling the stored procedure?
Can rs.last() be used after calling the stored procedure? If yes what should be the CURSOR types?
Can rs.last() be used after calling the stored
procedure? If yes what should be the CURSOR types?That would depend on the driver/database.
And as I said in your other post it is far more efficient to count records by just returning a count rather than a complete collection regardless of how you get to the end. -
Inserting to a CLOB field in Oracle 8i Database
Hi All,
I am trying to insert a value to a CLOB field in Oracle 8i DB.
The value gets inserted when the size is less (Up to around 80 Bytes).
When the size becomes larger the insertion does not take place but no exception is thrown.
Please see below the code I have written.
PreparedStatement preparedStatement = null;
try {
connection = getConnection(MMAKeys.WMDS_DATASOURCE);
String query = "UPDATE s_mmhp_batch SET MMHP_REPORT_CLOB=(?) WHERE MMHP_BATCH_ID=(?) AND MMHP_USER_ID=(?) AND MMHP_MEMBER_KEY=(?)";
preparedStatement=connection.prepareStatement(query);
Reader r = new StringReader(clobReport);
preparedStatement.setCharacterStream(1, r, clobReport.length());
oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(connection , false, oracle.sql.CLOB.DURATION_CALL);
newClob.putString(1,clobReport);
preparedStatement.setClob(1,newClob);
preparedStatement.setInt(2,batchId);
preparedStatement.setString(3,userId);
preparedStatement.setString(4,memberKey);
preparedStatement.executeUpdate();
System.out.println("inside the write to Batch method after executing the query");
} catch (SQLException exception) {
throw new DAOException(
"MREDMMSDAO -> writeToTable():SQLException"
+ exception.getMessage());
} catch (Exception exception) {
throw new DAOException(
"MREDMMSDAO -> writeToTable():Exception"
+ exception.getMessage());
} finally {
closeStatement(preparedStatement);
closeConnection(connection);
I came to know that this method is not supported in Oracle 8i.
I tried to create an empty CLOB and call the putValue() method.
But Then, I got an exception stating that the method is not supported.
Is there any other way to insert a CLOB value to Oracle 8i?
Please help.
Thanks in advance,
NeelambaryAnd cursor.callproc('insert_clob_proc', (clob,))
doesn't work for you?
PrzemekYes - I should have been more clear in my original post. The callproc function works until we have a value which is over 32K. At values over 32K, we get an error message "ORA-01460: unimplemented or unreasonable conversion requested". I believe this is because we are sending the value as a string and so we would need to figure out how to send as a CLOB in cx_Oracle? Here is some code to use to test if interested...
Oracle (Oracle Database 10g Release 10.1.0.4.0 - Production):
CREATE TABLE clob_test (CLOB_FIELD CLOB);
CREATE OR REPLACE PROCEDURE ins_clob_test (v_clob_field IN CLOB)
AS
BEGIN
INSERT INTO clob_test (clob_field) VALUES (v_clob_field);
END ins_clob_test;
Python (2.5):
conn = cx_Oracle.connect(xhash['oraclelogin'])
cursor = conn.cursor()
clob_var = 'Some test data' * 10000
cursor.callproc('ins_clob_test',(clob_var,))
conn.commit()
cursor.close()
conn.close()
I should also mention that I am the Oracle developer and not the Python programmer - my knowledge of Python is very limited. I would like the Python programmers to use the procedures (packages) I have created to do their inserts but this situation has caused them to put the SQL directly in their code.
Thanks again for any assistance you can provide.
Jason -
ORA-22275 inserting into the CLOB column using ODBC input parameters
Hi all,
I'm having problem with INSERT into the CLOB column via bound input parameters.
After calling SQLExecDirect() I'm getting following error:
[Oracle][ODBC][Ora]ORA-22275: invalid LOB locator specified
Adding defaults to the table definitions does not help. If I embed parameter values into the SQL statement - everything works just fine.
I use Oracle 9.2 with latest Oracle ODBC driver 9.2.0.4 under Windows XP.
Any ideas appreciated...
Vlad
Code looks like this:
SQLBindParameter(hstmt,1,...);
SQLBindParameter(hstmt,2,...);
SQLBindParameter(hstmt,3,...);
SQLExecDirect(hstmt,...);
SQL statement looks like this:
insert into tst_table (id,str_fld,clob_fld1,clob_fld2) values (50, ? , ? , ?)
Table looks like this:
CREATE TABLE tst_table (
id number (10,0) NOT NULL ,
str_fld nvarchar2 (50) NOT NULL ,
clob_fld1 nclob NOT NULL ,
clob_fld2 nclob NOT NULL ,
CONSTRAINT PK_tst_table PRIMARY KEY
id
I tried to add defaults to the table, but result is the same:
CREATE TABLE tst_table (
id number (10,0) NOT NULL ,
str_fld nvarchar2 (50) NOT NULL ,
clob_fld1 nclob default EMPTY_CLOB() NOT NULL ,
clob_fld2 nclob default EMPTY_CLOB() NOT NULL ,
CONSTRAINT PK_tst_table PRIMARY KEY
idYou need to provide the data at execution time (i.e. SQL_LEN_DATA_AT_EXEC(0) in the SQLBindParameter followed by a series of SQLPutData calls). If you go to Metalink
Top Tech Docs | Oracle ODBC Driver | Scripts & Sample Code
has some sample code that shows you how to do this.
Justin -
Insert into a clob field in a procedure based form
Hi,
I have a table with a clob field. I wrote a procedure to insert into this table. Then I built a form based on this procedure. Here is my code:
drop table clob_test;
create table clob_test(id NUMBER, note CLOB);
insert into clob_test values(10,empty_clob());
Create or Replace PROCEDURE PROJECTS.SET_CLOB
( p_id IN CLOB_TEST.id%TYPE,
p_note IN VARCHAR2 default null)
as
v_loc CLOB;
v_amt binary_integer;
v_pos integer :=1;
v_clob varchar2(32000);
Begin
insert into clob_test values(p_id,empty_clob());
v_clob := p_note;
v_amt := LENGTH(v_clob);
select note into v_loc from clob_test where id = p_id;
DBMS_LOB.WRITE(v_loc,v_amt,v_pos,v_clob);
End;
When I try to insert into note field more than 4000 charaters. I got this error:
An unexpected error occurred: ORA-06502: PL/SQL: numeric or value error: character string buffer too small (WWV-16016)
Why this happens? I know portal form doesn't support clob, but this procedure deal directly with database. Can anyone from Oracle give me help? Thanks in advance!I use a dynamic page instead of a form on the procedure. It's working.
Apparently Oracle is not supporting a varchar2 more than 4000 in any form format, even using textarea for p_note. -
How to parse/extract XML from clob field using ODI
Hi,
I am very new to ODI. I have an oracle table which has clob field. This clob field contains xml. I would like to parse this xml and convert it to oracle table. Means I would like to make all the tags of xml as oracle table columns.
I have created a PL/SQL procedure and used XMLTABLE function and I have achieved my goal. The same this I am trying to do with ODI. Since I am new to ODI so any help is appreciated.
ThanksIn 9.2, you are limited into your options. Have a look into, among others, updateXML. Updating tp 10gR2 will give you more options to succeed.
-
Export XML data from a CLOB field using sql developer
I have a table that contains a CLOB field, each record is a complete XML in itself. After running the select query i am exporting this data by right clicking on the answer set, while the export completes the data for each record gets truncated.
When i chose to save the export in loader format i get the complete records but now there are n files created for n records exported.
Is there a way i can get alll the records in a single file wirthout any truncation.
Thanks in advance!You might try delimited format or csv, with no enclosures if desired.
-
Insert Multiple records using Database adapter with Stored procedure func
Hi All,
I want to insert multiple records on a database using a stored procedure. I wanted to insert those records using a Database Adapter and the Database adapter should be invoked by a Mediator.
Can somebody suggest me with ideas whether it can be acheived with OOB capabtilities in SOA suite or not?
Thanks for your help in advance.
Thanks,
ShivThe use case you want to achieve is feature supported by the DBAdapter and it is possible to invoke the same from mediator.
Please have a look at the oracle documentation and you should be able to get the necessary information.
The below links should help you as well:
http://download.oracle.com/docs/cd/E15523_01/integration.1111/e10231/adptr_db.htm
http://blogs.oracle.com/ajaysharma/2011/03/using_file_adapter_database_adapter_and_mediator_component_in_soa_11g.html
There are some video tutorials as well :)
http://www.youtube.com/watch?v=dFldS-fDx70 This should also help
Thanks,
Patrick -
Parent-Child Table Update via Single Stored Procedure
Uses: Oracle 9i Server via a Remote Connection with restriction, Oracle 9i client, .NET 2.0+System.Data.Oracle namespace, Delphi+BDE;
I have an entry form which consists of a parent and a child table. I'm so keen in knowing whether there is any possibilities of updating the records via a single stored procedure? I mean if parent have a single record and corresponding to it, child have few records (more than 1 rows). I need to take the parent's value and child's value send it to the stored procedure and update it.
Regards,The entry form gets the raw data from the user. So yes the data is captured front end but not updated nor processed. Once the user clicks "Save" or what ever the values are taken to the SP. In the SP the operations are done either as update or insert. Lets concentrate on Inserts only at the moment.
I.e. there are 2 tables as:
tbl_Payment(_PaymentID_, PaymentMode,PaymentDate, TotalPaymentValue);
tbl_PaymentAccount(_PaymentID,AccountID_,PaymentValue);
So the form has a top part which is bounded to the Parent Table which is "tbl_Payment" to few text boxes, and below it has a Datagrid, bounded to Child Table which is "tbl_PaymentAccount". And assume the the Single Stored Procedure as "sp_payment_addchg".
I can pass newly entered values to the SP as:
Command.Text = "sp_payment_addchg";
/*so all the parent table bounded values are updated as*/
Command.Parameter[0].value = text1.text;
Command.Parameter[1].value = text2.text;
and so on
Since the DataGrid may have multiple rows, I cant figure it out how to get those rows into a single parameter.
Regards, -
Crystal Report not showing fields when connected to a stored procedure
I have a Stored Procedure that returns results when run in SQL Server, but when I add this to a Crystal Report it doesn't show any fields in the Field Explorer. But if I try any other SP, it works fine and I can see its fields.
As you can see in the picture below, I am unable to expand the fields in the report while creating the report using standard report procedure too.
I tried different ways, but nothing worked for me here. Please help me here.
(FYI, I am using Crystal Reports 2008, SQL Server 2008R2)Hi Jamie,
I just found out the reason for this issue.
I wrote the stored procedure using the fields in the Datamart but the fields in the datamart in backend are connected to a different database which doesn't have SQL Server Authentication (for the Credentials) and that's the reason I was getting this issue.
Once my BI team granted the permission, for that fields connecting to the backend database, I was able to see all fields in the Crystal Report.
Maybe you are looking for
-
Photo Gallery problem issue with explorer browser
Hi there, I made a personal website with a photo gallery from iweb and everything run cool in a Mac system but when I visualize my photogallery from my website in an Explorer Browser from windows, my pictures doesn´t appear, we cannot see anything. I
-
Long delay repairing a macbook air
Hello to everyone, I live in Argentina. Last september my 2012 MacBook Air crashed. I tried everything and nothing worked. The SSD was dead. I first talked over the phone with an authorized reseller and repairing service (MaximSoft) and they advised
-
If I deactivate all computers will all downloads, pictures and music libraries remain accessible after re-authorizing a computer?
-
Scanjet G3110."The system cannot find the path specified" when trying to import.
scans fine but won't import. This question was solved. View Solution.
-
There was a problem connecting to the printer. Make sure it's connected and try again
A test page prints ok. However when I come to print any document I get this message: "There was a problem connecting to the printer. Make sure it's connected and try again" I have uninstalled the printer and re-installed it and rebooted my computer.