How to call CLOB to BLOB conversion function within stored procedure?
I have a tiny APEX application from which I need to be able to print. I’ve used these two resources: (Is there an inexpensive APEX report printer for invoices/checks/statements? and http://download.oracle.com/docs/cd/E14373_01/appdev.32/e13363/up_dn_files.htm#CJAHDJDA)
I guess that in order to be able to download the RTF document stored in CLOB, I need to convert it into BLOB. I’ve found this function for this purpose on Oracle forums:
CREATE OR REPLACE FUNCTION c2b( c IN CLOB ) RETURN BLOB
-- typecasts CLOB to BLOB (binary conversion)
IS
pos PLS_INTEGER := 1;
buffer RAW( 32767 );
res BLOB;
lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
BEGIN
DBMS_LOB.createTemporary( res, TRUE );
DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
LOOP
buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
IF UTL_RAW.LENGTH( buffer ) > 0
THEN
DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
END IF;
pos := pos + 16000;
EXIT WHEN pos > lob_len;
END LOOP;
RETURN res; -- res is OPEN here
END c2b;And I am trying to use it in the modified download procedure that I also have found on Oracle forums:
CREATE OR REPLACE PROCEDURE DOWNLOAD_WO(v_id IN NUMBER)
AS
v_mime VARCHAR2(48);
v_length NUMBER;
v_file_name VARCHAR2(2000):= 'WO_Download.rtf';
lob_loc CLOB;
v_blob BLOB;
v_company jobs_vw.company%TYPE;
v_project jobs_vw.project%TYPE;
v_description jobs_vw.description%TYPE;
v_date_ jobs_vw.date_%TYPE;
v_job_no jobs_vw.job_no%TYPE;
v_apqwo jobs_vw.apqwo%TYPE;
-- v_mime VARCHAR2(48) := 'application/msword';
BEGIN
SELECT mime_type, report, DBMS_LOB.GETLENGTH(report)
INTO v_mime,lob_loc,v_length
FROM report_layouts
WHERE rl_id = 22332925279634283;
-- JOB_VW record:
SELECT job_no
,date_
,description
,apqwo
,project
,company
INTO v_job_no
,v_date_
,v_description
,v_apqwo
,v_project
,v_company
FROM jobs_vw
WHERE id = 214;
-- Replace holders with actual values:
lob_loc := REPLACE(lob_loc, '#COMPANY#', v_company);
lob_loc := REPLACE(lob_loc, '#PROJECT#', v_project);
lob_loc := REPLACE(lob_loc, '#DESCRIPTION#', v_description);
lob_loc := REPLACE(lob_loc, '#DATE_#', TO_CHAR(v_date_, 'DD/MM/YYYY'));
lob_loc := REPLACE(lob_loc, '#JOB_NO#', v_job_no);
lob_loc := REPLACE(lob_loc, '#APQWO#', v_apqwo);
-- set up HTTP header
-- use an NVL around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
-- set the size so the browser knows how much to download
htp.p('Content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('Content-Disposition: attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
-- wpg_docload.download_file( Lob_loc );
v_blob := c2b(lob_loc);
wpg_docload.download_file( v_blob );
end DOWNLOAD_WO;
/Unfortunately when I try to compile the download_wo stored procedure I am getting this error:
Error at line 64: PL/SQL: Statement ignoredThe 64th line is:
v_blob := c2b(lob_loc);How should I correctly call c2b within download_wo? Any advice is greatly appreciated.
Thank you for your time.
Daniel
Hello there,
Well, its invalid :(
Object C2B is Invalid. I didn't know since when I run the create ... function, I only get this feedback:
Statement processed.
0.19 secondsI am investigating.
Daniel
Similar Messages
-
How to call EJB deployed on OC4J from java stored procedure?
Hello,
I'd like to call EJB from java stored procedure. My example works fine from command line, but the problem seems to be with deployment of this code into database. Especialy I'm wondering how to reference jars like oc4jclient.jar, ejb.jar, ... from java stored procedure.
Is there some example how to do that ?
Can You help me please ?
Many thanks,
Radim Kolek,
Eurotel Prague.Hi,
You may want to check up this thread
Calling JBoss EJBs from Java stored procedure
Hope this helps,
Sujatha.
OTN Group. -
How to call Microsoft SQL User defined function??
I am trying to call Miscrosoft SQL user defined function (not stored procedure) and experience problems. The function -- func_profile_history takes 3 inputs and returns resultSet.
Please let me know if there is any examples some where. All the examples I found are for stored procedure.
Thanks....
Siu
************ source *************
public Vector callSqlFunction(String eidTradcom, String idSku, String endDate, String idUserPost)
throws TradcomException, RemoteException
System.out.println("--------------in callSqlFunction--------------1");
Connection conn = null;
java.sql.CallableStatement cstmt = null;
ResultSet rs = null;
ForecastInfo info = null;
Vector v = new Vector();
try{
conn = TradcomUtils.getConnection();
String sql = "{call func_profile_history(?,?,?)}";
System.out.println("--------------in callSqlFunction--------sql="+sql);
cstmt = conn.prepareCall(sql);
System.out.println("--------------in callSqlFunction-------2");
cstmt.setString(1, eidTradcom);
cstmt.setString(2, idSku);
cstmt.setString(3, endDate);
System.out.println("--------------in callSqlFunction-------3");
rs = cstmt.executeQuery();
System.out.println("--------------in callSqlFunction-------4");
while (rs.next()){
info = new ForecastInfo ();
info.setEidTradcom(rs.getString("eid_tradcom"));
info.setIdSku(rs.getString("id_sku"));
info.setQtOnHand(rs.getDouble("qt_on_hand"));
info.setQtOnHold(rs.getDouble("qt_hold"));
info.setQtNetOnHand(rs.getDouble("qt_net_on_hand"));
info.setQtAlloc(rs.getDouble("qt_alloc"));
info.setQtAvailUnalloc(rs.getDouble("qt_avail_unalloc"));
info.setQtPoShip(rs.getDouble("qt_po_ship"));
info.setQtPoRcvd(rs.getDouble("qt_po_rcvd"));
info.setQtTransit(rs.getDouble("qt_transit"));
info.setQtAsn(rs.getDouble("qt_asn"));
info.setQtPo(rs.getDouble("qt_po"));
info.setQtPoBalance(rs.getDouble("qt_po_balance"));
info.setQtSoShip(rs.getDouble("qt_so_ship"));
info.setQt4Cast(rs.getDouble("qt_4cast"));
v.addElement(info);
System.out.println("--------------in callSqlFunction-------5");
System.out.println("--------------in callSqlFunction-------v="+v);
return v;
}catch(Exception ex){
System.out.println("Error in callSqlFunction:"+ ex.getMessage());
throw CachingManager.getTradcomException(ex, "Error in callSqlFunction");
}finally{
try{ if (cstmt != null) cstmt.close(); } catch(Exception ex){}
try{ if (conn != null) conn.close(); } catch(Exception ex){}
********************* error output ***************
********************* bef calling callSqlFunction
--------------in callSqlFunction--------------1
--------------in callSqlFunction--------sql={call func_profile_history(?,?,?)}
--------------in callSqlFunction-------2
--------------in callSqlFunction-------3
Error in callSqlFunction:The request for procedure 'func_profile_history' failed
because 'func_profile_history' is a function object. Severity 18, State 1, Proc
edure 'LAP_DUAL null', Line 4
ERROR=Error in callSqlFunction...The request for procedure 'func_profile_history
' failed because 'func_profile_history' is a function object. Severity 18, State
1, Procedure 'LAP_DUAL null', Line 4well, I tried the preparedStatemnet and it worked. Case closed.
-
Need Example on calling a unix shell script from oracle stored procedure
Hi
Can anybody give example on how to call unix shell script from an Oracle stored procedure. Please give a small example on how to do this .I need this urgently please.
Have a nice time.
Thanks & Regards
JogeshIf you are on 10g you can also use DBMS_SCHEDULER. See Re: Excute Unix command Using PL SQL
-
How to convert CLOB to BLOB with SQL Developer migration wizard?
Hi,
According to our requirement, we need to only migrate data from SQL Server 2008 to Oracle 11. I use the SQL Developer 3.0.04 migration wizard to do it.
I do migration from SQL Server (database name: SCDS41P2) to Oracle (User name: HCDS41P2).
My migration steps are as below: (I need to modify the target schema, so I add the steps 2) and step 3) )
1) Do migration by SQL Developer migration wizard;
2) Remove the Converted Database Objects node from migration project;
3) Re-do convert by SQL Developer migration wizard (contains changing the target schema);
When do step 1), the DBO_SCDS41P2 user is created automatically. CLOBTOBLOB_SQLDEVELOPER procedure is also created in this user.
I continued to run step 2) and step 3) with online mode. And find the table data which contains BLOB column can be moved into the target table. But from the Logging Page, I can't see the other detailed error info, so that I can't check which tables don't move data successfully.
Could you please tell me where the detail log file (e.g. contains every table's migration status) is if I use the online mode?
Additional, If I use offline mode to do step 3), I found the CLOB data can't be converted into BLOB automatically. Because in the load script (that is oracle_ctl.bat), only copy the source data to the CLOB column. After copy, it don't deal with the converting from CLOB to BLOB.
So could you please tell me how to convert CLOB to BLOB with offline mode?
Thanks so much.Hi,
For your first question about logging - after the migration there will be an entry in the right hand panel for the migration project. If you open this there are various fields that give information about the status of each part of the migration. Does this give you the information you need ?
For the second problem about offline moving blob data have a look at the SQL*Developer documentation -
Oracle® SQL Developer User’s Guide Release 3.0
in the section -
2.2.8.1.4 Populating the Destination Database Using the Data Files
which describes the problem and how to get round it.
Regards,
Mike
Edited by: mkirtley on Aug 12, 2011 10:49 AM -
How to use clob or blob data type in OWB
how to use clob or blob data type in OWB?
if OWB not surport these data type,how can i extract the large data type from data sourceThe same question was asked just two days ago No Data Found: ORA-22992
Nikolai Rochnik -
How to call a Asynchronous bpel process from a PLSQL procedure?
How to call a Asynchronous bpel process from a PLSQL procedure?
Hi,
You could do something smart and technical very spiffy with soap-stacks in the database and/or dbms_ws/dbms_http. But I allways find AQ with AQ-adapter the simplest. Let Pl/sql enqueue a message on an aq-queue and subscribe an aq-adapter process on it. That can call your async-bpel process. If you want to get answer back in pl/sql, let the aq-adapter process enqueue a response message on another queue or on the same queue with another consumer name. Give it a correlation-id that you provided in the payload of your request message. Your pl/sql process can then do a dequeue on that correlation-id. It will sit and wait until a message with that correlation id is enqueued on the queue.
Regards,
Martien -
Hello,
I'm using RPAD function in stored procedure 4 times in one query and then inserting to another table. from dm_exec_sql_text table I see that every time that procedure approach to Rpad function it's open and closing in the and so it's open and closing
function 4 times per one row, If I have 1000 rows to insert the function will open and close 4000 times and it's very slow.
My question if there is some way to change this functionality of open / close function every time ?
Thank You
DanielYes, avoid using UDF , means especially a scalar udf... See how you can re-write a scalar udf as table valued udf.
http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/05/23/reuse-your-code-with-cross-apply.aspx
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Create a View, function or stored procedure for query?
Hi All,
I like to know how I can create a view or function for the query below. If its going to be a function or stored procedure will I be able to union it with another view?
DECLARE
@BegDate DATE,
@EndDate DATE
SELECT
@BegDate = MIN(vl.VoidStartDate),
@EndDate = MAX(vl.LetDate)
FROM #VoidLoss vl
;WITH d(d) AS (
SELECT TOP (DATEDIFF(dd, @BegDate, @EndDate))
DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) -1, @BegDate)
FROM sys.all_objects o
), cal AS (
SELECT
d.d,
MONTH(d.d) AS m,
YEAR(d.d) AS y
FROM d
SELECT
vl.History_IND,
vl.PropCode,
vl.VoidCategory,
vl.ControlGroup,
CASE WHEN vl.VoidStartDate < MIN(cal.d) THEN MIN(cal.d) ELSE vl.VoidStartDate END AS VoidStartDate,
CASE WHEN vl.LetDate > MAX(cal.d) THEN MAX(cal.d) ELSE vl.LetDate END AS LetDate,
vl.MarketRent,
DATENAME(mm, CAST('1900-' + CAST(cal.m AS VARCHAR(2)) + '-1' AS DATE)) AS [Month],
cal.y AS [Year],
COUNT(*) AS DaysVoid,
COUNT(*) * vl.MarketRent AS VoidLoss
FROM
#VoidLoss vl
JOIN cal
ON cal.d BETWEEN DATEADD(dd, 1, vl.VoidStartDate) AND vl.LetDate
GROUP BY
vl.History_IND,
vl.PropCode,
vl.VoidCategory,
vl.ControlGroup,
vl.VoidStartDate,
vl.LetDate,
vl.MarketRent,
cal.m,
cal.y
ORDER BY
vl.History_IND,
vl.PropCode,
vl.VoidStartDate
ThanksA view or an inline-function is a single query, so this part does not fit in:
DECLARE
@BegDate DATE,
@EndDate DATE
SELECT
@BegDate = MIN(vl.VoidStartDate),
@EndDate = MAX(vl.LetDate)
FROM #VoidLoss vl
And you cannot have it multi-statement function either, since you cannot refer to temp tables in such a function. In any case, using a multi-statement function in a view definition or nest it in another function definition is likely to be a performance disaster.
The sole alternative that remains as long as you have the temp table is a stored procedure. You cannot use a stored procedure in a view or a function.
Erland Sommarskog, SQL Server MVP, [email protected] -
How in ColdFusion with in variables get a Oracle stored procedure to return values?
How in ColdFusion with in variables get a Oracle stored procedure to return values?
We have tried several things, we can get a stored procedure to return a result set if we are not passing in variables but we cannot get them when we are passing in variables.
We know how to do it calling MS SQL.
Thanks for any help,
Nathan Sr
P.S. we have heard this may not be possible with the current Oracle Driver is there a different Oracle driver?I can only barely understand what you're asking here (not from a technical perspective, but from understanding your written English), but I suspect you're wanting to know how to pass back values other than recordsets from Oracle?
You should be able to pass them back via a type=out proc param, shouldn't you?
If you could reword your post so it's a bit more coherent, and possibly post some code, that might help.
Adam -
Trouble referencing return values of a Function in Stored Procedure
Hello all,
I have the following Function and Stored Procedure (simplified for this post). The error I am getting is in the SELECT, WHERE clause of the UPDATE command. My function is returning a sys_refcursor and I am trying to reference column names but keep getting the error
ORA-00904: "PUBLISHEDDOCVERSIONID": invalid identifier
What am I doing wrong?
Function
CREATE OR REPLACE FUNCTION &HKDB_Schema_Name..QueryKnowdeDocVersion(aKGID int)
RETURN sys_refcursor
IS
aCur sys_refcursor;
BEGIN
OPEN aCur FOR
SELECT pkd.KnowdeID as "PublishedKnowdeID", pkd.DocumentID as "PublishedDocID", pkd.VersionID as "PublishedDocVersionID"
FROM KnowdeDocument pkd
WHERE pkd.KGID = aKGID;
RETURN aCur;
END;Stored Procedure
UPDATE KnowdeDocument
SET DocumentID = (SELECT PublishedDocID FROM (SELECT QueryKnowdeDocVersion(aKGID, aPublishedKGID, aTextVersionID) FROM DUAL)
WHERE PublishedKnowdeID = KnowdeDocument.KnowdeID
AND PublishedDocID = KnowdeDocument.DocumentID
AND ((PublishedDocVersionID is NULL and KnowdeDocument.VersionID is NULL) OR (PublishedDocVersionID is not NULL AND
PublishedDocVersionID = KnowdeDocument.VersionID)))Regards,
TobyHi redeye,
Your select is from:
(select queryknowdedocversion(akgid
,apublishedkgid
,atextversionid)
from dual)This has no publisheddocversionid. Unfortunately I cannot figure out what you are trying to do with that ref_cursor.
Edit:
Or perhaps publisheddocversionid is a column in KnowdeDocument? Could this be case sensitive as well? (Bad idea to use quotations when naming things)
Regards
Peter
Edited by: Peter on Aug 24, 2009 3:39 AM -
HELP!!! Problem of Calling external Web Service from a Java Stored Procedur
1.I read the topic on http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/wsclient/Readme.html about Calling external Web Service from a Java Stored Procedur.
2.After I import .jar to Oracle what is required by the topic,som error occued.
Like: ORA-29521: javax/activation/ActivationDataFlavor class not found,
ORA-29545: badly formed class.
3.These is not enough .jar required on the topic? What can I do for ORA-29545: badly formed class?
Thany you!Try this
Re: HELP! Loading Java Classes into Oracle ERROR -
How to call the Report program into Function module
Hi Experts,
Actually I want to create the DataSource. But I have only the ALV report program. I need to create function module but I dont know how to call the ALV report program using in function module
So could you please any one send the Document or step by step method?
Advance Thanks,
SathisIf the report is just based out of a table than create a Generic Extractor using View.
If its an InfoSet query than create a Generic Extractor on that InfoSet.
If its an ABAP report than create a Generic Extractor using FM
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a0f46157-e1c4-2910-27aa-e3f4a9c8df33 -
How we handle CLOB and BLOB Datatypes in HANA DB
Dear HANA Gurus,
We have would like to build EDW using HANA base on our source system Oracle and it's supports CLOB and BLOB datatypes
Would you please suggest how do we handle in HANA DB.
Let not say it's oracle specific.
Regards,
ManojHello,
check SAP HANA SQL Reference Guide for list of data types:
(page 14 - Classification of Data Types)
https://service.sap.com/~sapidb/011000358700000604922011
For this purpose might be useful following data types:
Large Object (LOB) Types
LOB (large objects) data types, CLOB, NCLOB and BLOB, are used to store a large amount of data such as text documents and images. The maximum size of an LOB is 2 GB.
BLOB
The BLOB data type is used to store large binary data.
CLOB
The CLOB data type is used to store large ASCII character data.
NCLOB
The NCLOB data type is used to store a large Unicode character object.
Tomas -
hi
tell me some thong how we can convert clob to blobYou can use my procedure
create or replace procedure CLOB2BLOB (p_clob in out nocopy clob, p_blob in out nocopy blob) is
-- transforming CLOB â BLOB
l_off number default 1;
l_amt number default 4096;
l_offWrite number default 1;
l_amtWrite number;
l_str varchar2(4096 char);
begin
begin
loop
dbms_lob.read ( p_clob, l_amt, l_off, l_str );
l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
utl_raw.cast_to_raw( l_str ) );
l_offWrite := l_offWrite + l_amtWrite;
l_off := l_off + l_amt;
l_amt := 4096;
end loop;
exception
when no_data_found then
NULL;
end;
end;
Best regards, Victor
Maybe you are looking for
-
How to retain folders from External drive on the sidebar?
I dragged some folders from my external hard drive that I regularly use when I am in the office. Sometimes I take my MBP out without the external drives. I realize that these aliases I had created on the sidebar disappears. When I connect up to my ex
-
Is my website really lost? All the files are in my .Mac account but what?!
I have read several of the threads on the topic and have become quite disillusioned by the thought of having to start from scratch again. HELP! I originally created my personal website, web.mac.com/username (I've moved the files to a different direct
-
this problem started last fall after upgrading to Mavericks. If I shut down my computer (or restart) I have problems getting it going again. This is getting progressively worse. I hadn't shut down in over a month, forgot about this issue and shut dow
-
Javascript to check for duplicate entries in 2 pull-down lists
I have created an application form in Acrobat 8 Professional, using LiveCycle and would like to compare selections in 2 drop-down lists so that the same option is not selected twice. I think this is something that could be done with javascript, but m
-
I have an 08 iMac. I have not upgraded to Snow Leopard yet but recently installed iTunes 9. Now my FrontRow app doesn't work properly; it can't find any of the files. When I use the remote and select a Movie, Music, Photos, etc.. category it says tha