Retrieving BLOBs via stored procedure
Hi all,
I'm trying to retrieve bigger blobs (>1 MB) from a database using a stored procedure, but it didn't work. I can't figure out were the problem is.
My stored prcedure looks like:
CREATE OR REPLACE PROCEDURE get_blobs (blob_id IN NUMBER, v_enterid out NUMBER, v_enterdate_s out VARCHAR2, v_name out VARCHAR2, BUFFER_CHARS out LONG, v_blob_size out NUMBER) IS
v_enterdate DATE;
v_content BLOB;
BUFFER LONG RAW;
AMOUNT BINARY_INTEGER := 100;
POS INTEGER := 1;
COUNTER INTEGER :=0;
BEGIN
SELECT EntryID,EnterDate,Name,Content
INTO v_enterid,v_enterdate,v_name,v_content
FROM test_blob WHERE EntryID=blob_id;
v_enterdate_s := to_char(v_enterdate,'dd.mm.yyyy');
v_blob_size := DBMS_LOB.GETLENGTH(v_content);
AMOUNT := cast(v_blob_size as BINARY_INTEGER);
DBMS_LOB.READ (v_content, AMOUNT, POS, BUFFER);
BUFFER_CHARS := 'aaaaa';
CAST_TO_VARCHAR2(BUFFER);
BUFFER2 := BUFFER2 || BUFFER_CHARS;
RETURN;
END;
I think there are several mistakes in this code, as I tried and tried many days.
When I execute the code using a sql script, it works (the output is just removed for testing), but if I try it with an PHP script I get the following error:
Warning: Ora_Exec failed (ORA-21560: argument 2 is null, invalid, or out of range ORA-06512: at "SYS.DBMS_LOB", line 640 ORA-06512: at "JAN.GET_BLOBS", line 21 ORA-06512: at line 1 -- while processing OCI function OEXEC/OEXN) in d:\eclipse\crf tracker\modules\manage\new.inc.php on line 60
The PHP routine looks like:
$v_index_in = 1;
$cursor = ora_open($conn);
$query = "BEGIN GET_BLOBS(:v_index_in,:v_index,:v_enterdate,:v_name,:v_content,:v_size); END;";
$stmt = ora_parse($cursor,$query);
ora_bind ($cursor, "v_index_in", ":v_index_in", 10,1);
ora_bind ($cursor, "v_index", ":v_index", 10,2);
ora_bind ($cursor, "v_enterdate", ":v_enterdate", 20,2);
ora_bind ($cursor, "v_name", ":v_name", 100,2);
ora_bind ($cursor, "v_size", ":v_size", 10000, 2);
ora_bind ($cursor, "v_content", ":v_content",$v_size,2);
$v_index = '';
$v_enterdate = '';
$v_name = '';
$v_content = '';
$v_size = '';
ora_exec($cursor,$stmt);
Could please anybody helps me with that problem. I really see no chance to solve it on my own, because I'm just starting to work with Oracle, but I have to finish this in two weeks.
It doesn't matter, if the output of the content will be a blob or whatever else, because the processing in PHP will not be a big problem.
Thanks a lot in advance,
best regards,
Jan.
Hi
You can use ref cursor to return the results from your stored procedure. Here is how you define .
CREATE OR REPLACE PACKAGE trial AS
TYPE m_refcur IS REF CURSOR;
END trial;
Create or replace procedure example ( var1 out trial.m_refCur, var2 out trial.m_refCur)
as
open var1 for select * from emp;
open var2 for select * from dept;
end;
You can call this stored procedure in Java using Callable Statement. I you are using C++ or VB you can use OLEDB or
ADO API's to call same stored procedure.
Hope this helps
Chandar
Similar Messages
-
How to retrieve exception in stored procedure via JDBC?
Hi all,
In many cases, my JDBC call to stored procedure returns sucessfully without any SQLException, but the operations failed due to exception within the stored procedure (eg multiple rows returned for SELECT INTO).
I can see these exception when running interactive in SQLPlus, but JDBC doesn't throw them.
So does anyone know how to track these exception in stored procedure?
Many thanks.Is your stored procedure catching these exceptions? If so, it may be failing to re-throw them.
Justin -
OIM: Retrieve data from stored procedure, pre populate it in Resource form
Hi,
I need to retrieve data form a stored procedure that i have created . This data needs to be per populated in the Iplanet resource from. The stored procedure will have one input string and one output string.
Thankz,
Sanjay Rulez1. Prepare OIM Admin Console to interact with an Oracle Database, by adding jdbc jar files in the lib Directory of OIM Console.
2. Restart OIM Console and Create a database Resource
3. Create an Pre-populate adapter Task with a "Stored Procedure" Type
4. Invoke you Procedure.
The main problems can be around datatype conversion between Java and Oracle database.
For instance, all Oracle NUMBER type are mapped on java LONG type, and you need to deal every time with conevsrion between INTEGER and LONG in the adapter task. -
Could I export and import my oracle database via Stored Procedure???
Hi all,
I need to export my database using stored procedure, the stored procedure will be called by java application and it works well
Now I still get the "BIG QUESTION", could I export and import database using stored procedure???
Really thanks for the response.
Regards,
KahlilHi,
I think you can use DBMS_DATAPUMP (10.1+), see [DBMS_DATAPUMP|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_datpmp.htm#i1007277], for examples see [http://www.psoug.org/reference/dbms_datapump.html]
Regards, -
Block transaction in A/R Reserve Invoice via Stored Procedure
Dear experts,
I found in many threads the object id or object type of A/R Reserve Invoice to be 13 which is same as A/R Invoice. But when I use this object id in SP_Transaction_Notification stored procedure to block a transaction, A/R Reserve Invoice document is not affected by this object id. Also I noticed that the table the A/R Reserve Invoice is using is same as A/R Invoice.
Can any one help on this issue?
I want to block transaction to A/R Reserve Invoice as well as A/P Reserve Invoice if the line item's Item cost (OITM.AvgPrice) field is not specified in the Item Master Data.
Regards
SanilThanks a lot Gordon. I got the answer.
-
Data access via stored procedure - Return type as PLSQLAssociate array
Hi,
I get an error as array bind type must match pl/sqldata type when i execute a stored proc.
My stored proc looks like this:
PROCEDURE Datasearch
(p_type in varchar2,
p_empid in varchar2,
p_empcode out tempid,
p_lname out tlname,
p_fname out tfname,
p_nickname out tnickname,
p_position out tposition,
p_startdt out tstartdt,
p_status out tstatus,
p_loastart out tloastart,
p_loaend out tloaend,
p_xchange out txchange,
p_trx out ttrx,
p_enddt out tenddt,
p_hfind out thfind)
is
... end Empsearch
And I am trying to fire this stored proc using the following C# code:
OracleConnection con = new OracleConnection();
con.ConnectionString = "ValidConnectionString";
con.Open();
Console.WriteLine("Connected to Oracle" + con.ServerVersion);
string cmdTxt = "begin MyPack.Datasearch(:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15); end;";
OracleCommand myCMD = new OracleCommand(cmdTxt, con);
//Input params
myCMD.Parameters.Add("1", OracleDbType.Varchar2).Value = "All";
myCMD.Parameters.Add("2", OracleDbType.Varchar2).Value = "1129";
myCMD.Parameters[0].Direction = ParameterDirection.Input;
myCMD.Parameters[1].Direction = ParameterDirection.Input;
//Output params
OracleParameter Param3 = myCMD.Parameters.Add("3", OracleDbType.Int16);
OracleParameter Param4 = myCMD.Parameters.Add("4", OracleDbType.Varchar2);
OracleParameter Param5 = myCMD.Parameters.Add("5", OracleDbType.Varchar2);
OracleParameter Param6 = myCMD.Parameters.Add("6", OracleDbType.Varchar2);
OracleParameter Param7 = myCMD.Parameters.Add("7", OracleDbType.Varchar2);
OracleParameter Param8 = myCMD.Parameters.Add("8", OracleDbType.Date);
OracleParameter Param9 = myCMD.Parameters.Add("9", OracleDbType.Varchar2);
OracleParameter Param10 = myCMD.Parameters.Add("10", OracleDbType.Varchar2);
OracleParameter Param11 = myCMD.Parameters.Add("11", OracleDbType.Varchar2);
OracleParameter Param12 = myCMD.Parameters.Add("12", OracleDbType.Varchar2);
OracleParameter Param13 = myCMD.Parameters.Add("13", OracleDbType.Varchar2);
OracleParameter Param14 = myCMD.Parameters.Add("14", OracleDbType.Date);
OracleParameter Param15 = myCMD.Parameters.Add("15", OracleDbType.Varchar2);
//test ends
for (int i = 2; i < 15; i++)
myCMD.Parameters.Direction = ParameterDirection.Output;
myCMD.Parameters[i].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
myCMD.Parameters[i].Value = null;
myCMD.Parameters[i].Size = 3;
myCMD.Parameters[i].ArrayBindSize = new int[3] { 20, 20, 20 };
myCMD.ExecuteNonQuery();
I get an error on the above ExecuteNonQuery statement..
Any help/pointer will be highly appreciated.
-Cheersit appears you are not creating the int array correctly (please correct me if I am wrong)
we've created a helper class to alleviate the need for most of the manual coding, so in a gist:
param.ArrayBindSize = BindArraysToSize()
'whereas the collectionObjects is a simple array list containing the values that we intend for our assoc. arry
Private Function BindArraysToSize() As Integer()
Dim ArrBindSize(collectionObjects.Count - 1) As Integer
For i As Integer = 0 To collectionObjects.Count - 1
ArrBindSize(i) = collectionObjects(i).ToString().Length
Next i
Return ArrBindSize
End Functionbut for the exact issue you are having; you need to assign the values on the NEW (VS ought to warn you: "The short has no constructors")
try
Dim ar(4) As Int16 '= {1, 2, 3, 4, 5}
For i as Integer = 1 to 5
ar(i-1) = i
Next i
pStatus.ArrayBindSize = ar
OR
Dim ar2 As Int16() = {1, 2, 3, 4, 5}
pStatus.ArrayBindSize = ar2
OR
Dim ar3 As Int16() = New Int16(4) {1, 2, 3, 4, 5}
pStatus.ArrayBindSize = ar3
OR
pStatus.ArrayBindSize = New Int16(4) {1, 2, 3, 4, 5} -
Calling a Stored Procedure with Parameter using an UDF
Hi All,
I have a requirement where I need to use database lookup. In that I am calling the Stored Procedure using UDF. For example sp_flow ., for this I have to pass<INTID> and <USDERID> to get the response.
I am using the below code to excute this.
Channel channel = null;
Map rowMap = null;
DataBaseAccessor accessor = null;
DataBaseResult resultSet = null;
String Query = null;
//Query ="EXECUTE dbo.sp_flow <INTID> <USERID>;
Query = "EXECUTE dbo.sp_flow \'304\' , \'shankar\' " ;
try{
//Determine a channel, as created in the Configuration
channel =
LookupService.getChanne"BS_XXX","CC_XXX_JDBC_Rcv");
//Get a system accessor for the channel. As the call is being made to an
DB, an DatabaseAccessor is obtained.
accessor = LookupService.getDataBaseAccessor(channel);
//Execute Query and get the values in resultset
resultSet = accessor.execute(Query);
for(Iterator rows = resultSet.getRows();rows.hasNext();){
rowMap = (Map)rows.next();
result.addValue((String)rowMap.get("FLOW_ID"));
I am getting the error "Error when calling an adapter by using the communication channel CC_NWLS_TLA_JDBC_Rcv (Party: , Service: BS_MICROSOFT_SQLWLS20DEV_D, Object ID: d30aace599de3cd69548bf145d0724b7) XI AF API call failed. Module exception: (No information available). Cause Exception: 'Error processing request in sax parser: Error when executing statement for table/stored proc. 'table' (structure 'statement'): com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set."
let me know how do this.
Regards
shankar
Edited by: Shankar on Jun 9, 2009 2:51 PM
Edited by: Shankar on Jun 9, 2009 3:02 PMfirst of all calling a SP via the lookup API, there is a workaround but it is not at all recommended
FYI
/people/arpil.gupta/blog/2008/11/03/workaround-for-jdbc-scenarios - DB Lookup via Stored procedure
http://help.sap.com/javadocs/NW04S/current/pi/com/sap/aii/mapping/lookup/DataBaseAccessor.html
The accessor does not support transactional behaviour. Therefore, the method should not be used to execute insert or update statements on the database which can lead to inconsistencies. The accessor should only be used to read data from a database table. -
File to JDBC Scenario using stored procedure Question
Does anyone have an aswer (or have you seen a Blog that covers it) to the problem of having to do a table refresh before doing inserts in a file 2 jdbc scenario?
Essentially the details are as follows:
I have an input file that has all the data for a table (it's a complete table dump) of lets say userdata (username, name, hiredate).
I need to pass that to an oracle database via stored procedure(s). But before I start issuing my insert (via insert stored procedure) I have to somehow issue a delete statement to delete all the contents of the table I'm about to update. I'm on XI 3.0 and aren't sure what the best solution to this may be.
Again if there is a blog that covers this then if you could point me in that direction it would be great. Otherwise if anyone has any good ideas it would be appreciated.Hi,
For structure refer this blog..
/people/sap.user72/blog/2005/06/01/file-to-jdbc-adapter-using-sap-xi-30
Use two <Statement> tags as shown here and there you may have separate tablenames.
http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm
Thanks,
Jogula Ramesh -
Model type for DB stored procedures back end?
I have to use a database via stored procedures (#>100) as a back end system in a web dynpro application.
And I wonder which type of model is the most appropriate for that usage szenario.
Of course, I have to create some kind of DAO to access the db and expose the stored procedures as methods of the DAO. But how to get the DAO functionality into the WD model?
Do I have to go via web services, even if the DAO and the WD application run on the same instance? I think it is some kind of oversized. Would'nt the JavaBean model fit better? But how to get the DAO functionality into the JavaBean model?
Thank you, best regards
Christian LueheHi,
For my knowledge create EJB and expose this as webservice and use webservice model in webdynpro.
Regards, Anilkumar -
Retreiving multiple rows with stored procedures
Hi,
I'm having a little problem over here. I need to retreive some data (from an oracle db) via stored procedures. But I don't know how I can retreive multiple rows because when I execute a stored procedure which gives more dan 1 row back, Jave throws an exception.
If someone could show me an example (or url) from how it should be done, it will be very much appreciated :-)
Thanks in advance.A collection of (mostly) fully working example programs is provided by Oracle.
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
I think what you're looking for it the RefCursor example, under "JDBC Basic Samples" -
How to retrieve 'long' column with 32K length in Java stored procedure
For some reasons, we are not using CLOB, BLOB, or BFILE to store large objects and I have to live with LONG. So I wrote a Java stored procedure to insert, select and manipulate a LONG column by retrieving the LONG into a java.lang.String class (which happens to be the Java class mapped to the LONG SQL datatype). It all works fine as long as the length of the value being retrieved is less than the magic figure of 32767 bytes (which is the restriction on LONG and VARCHAR2 datatype in PL/SQL as well). So looks like Oracle's implementation of the JVM limits String values to a max of 32767 bytes. Suggestions on how to overcome this limitation (other classes that you suggest or do I have to move to files)?
Thanks,
Jeet
nullthe jvm has nothing to do with it ...
this is a pol/sql limitation on parameters in stored procedures.
and java stored procedures require a clal spec that makes the j-s-p look like a pl/qsl stored proc. -
How do I retrieve a variable from a stored procedure in Access?
Given a stored procedure like the one below,
PROCEDURE getSomething(
pVar1 in float,
pVar2 in float,
pVar3 in float,
pVar4 in float,
pResults out varchar2
How would I retrieve the value in pResults using VBA on Access? Thanks.Using this, you can set the value to the session bean
<c:set property="docID" target="${SessionBean1}" value="${pg_view_doc.hiddenField3.value}"/>
But before that you have to create a property called docid in the sessionbean1.
So once the property is set, through getDocID() method u can retrieve the value
ex: String value=getSessionBean1().getDocID();
will return the value in the required JSF Page bean -
Retrieve a number from a stored procedure
I need to retrieve the number of rows returned from a query in a stored procedure. This is what I currently have:
PACKAGE PART_DATA AS
FUNCTION GetPartDataRowCount(Company IN PART_DATA.PART1_CO_SITE%TYPE) RETURN NUMBER;
END;
PACKAGE BODY PART_DATA AS
FUNCTION GetPartDataRowCount
Company IN PART_DATA.PART1_CO_SITE%TYPE
RETURN NUMBER
IS
RecordCount NUMBER;
BEGIN
SELECT COUNT(*)
INTO RecordCount
FROM PART_DATA
WHERE PART1_CO_SITE = Company;
RETURN RecordCount;
END GetPartDataRowCount;
END;
And the .NET part:
Public Function GetPartDataRowCount(ByVal Company As String) As Integer
Dim con As New OracleConnection(MyConnectionString)
'Open the connection
con.Open()
'Set the command text, type and connection
Dim cmd As New OracleCommand("PART_DATA.GetPartDataRowCount", con)
cmd.CommandType = CommandType.StoredProcedure
'Create parameter objects
Dim returnValue As New OracleParameter
returnValue.Direction = ParameterDirection.ReturnValue
returnValue.DbType = DbType.Int32
cmd.Parameters.Add(returnValue)
Dim pCompany As New OracleParameter
pCompany.Direction = ParameterDirection.Input
pCompany.DbType = DbType.AnsiStringFixedLength
pCompany.Value = Company
cmd.Parameters.Add(pCompany)
'Execute the query
cmd.ExecuteNonQuery()
'Capture the returned value
Dim rowCount As Integer = Convert.ToInt32(returnValue.Value)
'Return the returned value
Return rowCount
'Clean up objects
returnValue.Dispose()
cmd.Dispose()
con.Dispose()
End Function
I am using this as the SelectCountMethod on an ObjectDataSource for custom paging a GridView. Everything is working but because I'm new to Oracle I can't help thinking that there is a better way to achieve what I need, also I am confused as to whether I should be using a Function or a Procedure in my Package for this.
I would be grateful if someone could either confirm that what I am doing is the best/correct method or show me what I should be doing instead.
Any help much appreciated.Thanks Eric, that is a big help and has made things clearer for me. However I cannot get this to work using a Procedure instead of a Function. Just for the sake of completeness I would also like to make it work with a Procedure.
Here is what I have:
PACKAGE PART_DATA AS
PROCEDURE GetPartDataRowCount(mtmsCompany IN PART_DATA.PART1_CO_SITE%TYPE,rowCount OUT NUMBER);
END;
PACKAGE BODY PART_DATA AS
PROCEDURE GetPartDataRowCount
mtmsCompany IN PART_DATA.PART1_CO_SITE%TYPE,
rowCount OUT NUMBER
IS
BEGIN
SELECT COUNT(*)
INTO rowCount
FROM PART_DATA
WHERE PART1_CO_SITE = mtmsCompany;
END GetPartDataRowCount;
END;
And the .NET code:
Public Function GetPartDataRowCount(ByVal Company As String) As Integer
'Open the connection
con.Open()
'Set the command text and type
Dim cmd As New OracleCommand("PART_DATA.GetPartDataRowCount", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.BindByName = True
'Create parameter objects
Dim rowCount As New OracleParameter
rowCount.Direction = ParameterDirection.Output
rowCount.DbType = DbType.Int32
cmd.Parameters.Add(rowCount)
Dim mtmsCompany As New OracleParameter
mtmsCompany.Direction = ParameterDirection.Input
mtmsCompany.DbType = DbType.AnsiStringFixedLength
mtmsCompany.Value = Company
cmd.Parameters.Add(mtmsCompany)
(Exception handling is done in Global.asax hence no Try/Finally)
'Execute the query
cmd.ExecuteScalar()
'Capture the returned value
Dim returnValue As Integer = Convert.ToInt32(rowCount.Value)
'Return the returned value
Return returnValue
'Clean up objects
RowCount.Dispose()
cmd.Dispose()
con.Dispose()
End Function
The package compiles without errors, but when I run the app I get the following error:
Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 39: PLS-00103: Encountered the symbol ">" when expecting one of the following:
It then gives a long list of things it was expecting. Do I also need to return a Ref Cursor?
Once again any help much appreciated. -
Can you get values back from a stored procedure via OUTPUT parameters?
Can you get values back from calling a stored procedure via OUTPUT parameters/variables? I call the SP via a SQL statement from a script either in a WF or DF.
I thought I read some reference that DI could not get the values from OUTPUT parameters but I could not find it again (don't know if it is in any of the documentation or referred to in a forum.
I did try a couple of tests but it did not reutrn any values via OUTPUT. But before I give up I thought I'd see if you could and maybe I needed to change something.This isn't exactly an answer to your question, but I'll point out that, given that you're resorting to a SQL script in the first place, there's no reason you can't also turn the output parameters into a regular result or record set. (The following uses T-SQL, although I think it's pretty generic.)
declare @param1 int, param2 varchar(100), @return int;
exec @return = proc @param1 = @param1 output, @param2 = @param2 output;
select @param1 as param1, @param2 as param2;
That is, to get from output parameters to a "regular" output from the SQL script isn't much of a leap...
Jeff Prenevost
BI Consultant
Ann Arbor, MI -
Retrieving cursor from a stored procedure
Hi,
Is there any means to retrieve a cursor from a stored procedure using java.sql.* package, without using database specific type code like OracleTypes.CURSOR?
Regards,
Shalin.Hi,
I had some across this problem some time ago. Although, there is no direct answer to this solution, there is a "kloog" that you can apply.
Please note that the signature for registerOutParameter(int parameterIndex, int sqlType), and note that where ever sqlType is mentioned it is an int.
Now JDBC is an interface and the implementation is given by Oracle. So to register an "out" parameter all you have to do is registerOutParameter(1, OracleTypes.CURSOR). It works!
Or otherwise try and find out what the int value of CURSOR is and replace. This is because not all databases can support returning a "cursor" type, since ORACLE and few other databases have a concept of "STORED PROCEDURE" and PLSQL is specific to ORACLE.
I hope this helps!
Cheers,
John.
Maybe you are looking for
-
Convert TIF Binary data to PDF Binary data
Hi All, I have uploaded TIF file into table in system in Binary format. I need to create a spool from this Binary data, the spool should open in TIF format or PDF format. Can you help me in doing this. As I knw how to convert PDF to Spool, it would b
-
Retrieval of number of rows in table
Hi, I need to retreive information from a database and put it into a temp array, but i'm not sure howto go about doing it. while(rs.next()) { for(int i=0; i<selection.length; i++){ String[] selection = rs.getString("Virtual_host_name")
-
Hello, I recently bought lightroom 4.1. In the first days, everything worked. But now, the adjustment brush doesn't work anymore! What is the reason and what can i do?
-
New Windows laptop fails to print to Mac-shared printer
I prevoiusly had a shared HP DeskJet 5900 shared from my PowerBook G4 to a Toshiba Windows laptop via Bonjour. The printer was set up as a generic Postscript printer and printing worked fine. I replaced the PowerBook with a MBP C2D and the Windows la
-
TS3297 Why can I not purchase movies from iTunes?
I have tried on all of my devices to purchase a movie and a box pops up that says: Your Purchase Could Not Be Completed For assistance, contact iTunes Support at www.apple.com/support/itunes/ww/. I have checked to make sure my account and software is