Use store blob image in database as a url in html - oracle

I'm storing images to a blob column in a Database table.
Then through a package i'm using htp.p to render some html elements and I also want to display the stored image in the tag.
I created an Application item "IMAGE_F" & Application process "IMAGE_PROCESS"
begin
for c1 in ( select *
from QUESTIONS_T
where ID =:IMAGE_F
) loop
--
sys.htp.init;
sys.owa_util.mime_header(
'image/png',
false
);
sys.htp.p('Content-length: '
|| sys.dbms_lob.getlength(c1.FILE_BLOB) );
sys.htp.p('Content-Disposition: attachment; filename="'
|| c1.FILENAME
|| '"');
sys.htp.p('Cache-Control: max-age=3600'); -- tell the browser to cache for one hour, adjust as necessary
sys.owa_util.http_header_close;
sys.wpg_docload.download_file(c1.FILE_BLOB);
apex_application.stop_apex_engine;
end loop;
end;
then I'm using the img tag as the following:
<img src="'
|| 'f?p='
||:app_id
|| ':10:'
||:app_session
|| ':APPLICATION_PROCESS=IMAGE_PROCESS:'
||:debug
|| '::IMAGE_F:'
|| IMAGE_ID
|| '">'
but it's not working and image is not showing.
I'm using ORACLE APEX version 21.2 , Oracle Database 19c.

Related

Oracle Apex Conditional Link

I have a conditional link as follows:
case
when My_Flag = 'Y' then
'<a href="' || apex_util.prepare_url('f?p=&APP_ID.:65:&APP_SESSION.::&DEBUG.:65:
:P65_MY_ID_ITEM,:P65_MY_ID_ITEM_2:' || TABLE_ID || ',' || TABLE_ID_2) || '">
<p>Details</p>'
else
'<a href="' || apex_util.prepare_url('f?p=&APP_ID. :65:&APP_SESSION.::&DEBUG.:65::
P65_MY_ITEM_3,:P65_MY_ITEM_4:' || TABLE_ID3 || ',' || TABLE_ID4) || '"><p>Details</p>'
end my_link
This link takes me to page 65 as intended but...items are not being populated.
Any idea what might be happening?
Thanks!
You may consider using the apex_page.get_url procedure to ensure your parameters are in the correct location. Currently you have an extra colon after the clear cache parameter.
I would also recommend using the :APP_SESSION bind variable in SQL instead of the substitution string, otherwise you'll blow out your SQL pool.

PL/SQL query error that I am running into. I have no clue what could be wrong

I'm trying to create a pl/sql query that fetches certain data and from tables and outputs the data. Here is what I have tried but I keep getting an error and I cannot begin to see where the problem is.
SET SERVEROUTPUT ON
DECLARE
TEMP_CUSTNAME CUSTOMER.FIRST_NAME%TYPE;
TEMP_CUSTSURNAME CUSTOMER.SURNAME%TYPE;
TEMP_COINPUR COIN.PRODUCT%TYPE;
TEMP_CPRICE COIN.PRICE%TYPE;
TEMP_DNOTES COIN_DELIVERY.DELIVERY_NOTES%TYPE;
CURSOR CURSOR1 IS
SELECT C.FIRST_NAME,C.SURNAME FROM CUSTOMER C, COIN.PRODUCT, COIN.PRICE, COIN_DELIVERY.DELIVERY_NOTES
WHERE COIN.PRICE > 8000;
BEGIN
OPEN CURSOR1;
LOOP
FETCH CURSOR1 INTO TEMP_CUSTNAME, TEMP_CUSTSURNAME, TEMP_COINPUR, TEMP_CPRICE, TEMP_DNOTES;
EXIT WHEN CURSOR1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE ('CUSTOMER: ' || TEMP_CUSTNAME || ',' ||TEMP_CUSTSURNAME);
DBMS_OUTPUT.PUT_LINE ('COIN: ' || TEMP_COINPUR || );
DBMS_OUTPUT.PUT_LINE ('PRICE: ' || TEMP_CPRICE || );
DBMS_OUTPUT.PUT_LINE ('NOTES: ' || TEMP_DNOTES || );
DBMS_OUTPUT.PUT_LINE ('------------------------------------' );
END LOOP;
CLOSE CURSOR1;
END;
It would be helpful if you've provided us with the error you're facing.
So far I see number of fields in the cursor (2) is not the same as number of variables being fetched into (5).
In other words, you need to add more columns here:
SELECT C.FIRST_NAME,C.SURNAME FROM CUSTOMER C, COIN.PRODUCT, COIN.PRICE,
so there will be enough data to fetch to this variables here:
FETCH CURSOR1 INTO TEMP_CUSTNAME, TEMP_CUSTSURNAME, TEMP_COINPUR, TEMP_CPRICE, TEMP_DNOTES;
Or, probably, you need to reduce number of variable you're fetching into like this. It depends on result you're trying to achieve
FETCH CURSOR1 INTO TEMP_CUSTNAME, TEMP_CUSTSURNAME;
UPD. wrong concatenation. Based on the error message from comments I see now there are problems here too. Remove trailing "||" in lines below
DBMS_OUTPUT.PUT_LINE ('COIN: ' || TEMP_COINPUR || );
DBMS_OUTPUT.PUT_LINE ('PRICE: ' || TEMP_CPRICE || );
DBMS_OUTPUT.PUT_LINE ('NOTES: ' || TEMP_DNOTES || );

Appending values to a CLOB in an 'after update' trigger

CREATE TABLE COPPER_TAN_META
(
ID decimal(22,0) PRIMARY KEY,
NOTES clob,
ERROR varchar2(2000)
);
CREATE UNIQUE INDEX SYS_C0070016 ON COPPER_TAN_META(ID);
Before update
ID ERROR NOTES
20 <null> 27-APR-21 08.48.18 AM - XML is not a full-text article;
Update
update COPPER_TAN_META set error = 'trigger warning' where id = 20;
With trigger, I'd like to see this:
ID ERROR NOTES
20 trigger warning 27-APR-21 08.48.18 AM - XML is not a full-text article; <timestamp> - trigger warning;
My trigger doesn't work:
CREATE OR REPLACE TRIGGER copper_error_appends_to_note
AFTER UPDATE of error on COPPER_TAN_META
for each row
begin
IF :new.error is not null THEN
:new.notes := :old.notes || localtimestamp(0) || ' - ' || :new.error || '; ';
END IF;
end;
/
Error: ORA-04098: trigger 'B026.COPPER_ERROR_APPENDS_TO_NOTE' is invalid and failed re-validation
This works fine using a normal update statement, like
update copper_tan_meta
set notes = notes || localtimestamp(0) || ' - ' || :fileError || '; '
where id = :tanMetaId
I'm running this on SQuirreL SQL Client Version 3.5.3
new values cannot be changed for AFTER trigger type, but possible for BEFORE
localtimestamp without argument might be used within the direct concatenation, but localtimestamp with precision argument such as localtimestamp(0) could be used within a SQL statement.
So, rewrite the code block as
CREATE OR REPLACE TRIGGER copper_error_appends_to_note
BEFORE UPDATE OF ERROR ON copper_tan_meta
FOR EACH ROW
DECLARE
ts TIMESTAMP;
BEGIN
SELECT localtimestamp(0) INTO ts FROM dual;
IF :new.error IS NOT NULL THEN
:new.notes := :old.notes || ts || ' - ' || :new.error || '; ';
END IF;
END;
/

Can't Select Oracle Apex Card Link Value

I have created a standard report page and selected the "cards" for the Report Template (in the Layout and Presentation).
The following is the code that loads the data
DECLARE
l_query VARCHAR2(4000);
l_app number := v('APP_ID');
l_session number := v('APP_SESSION');
//Bug happens on the ':11:' part, page 1 works fine
l_url VARCHAR2(500) := (APEX_UTIL.PREPARE_URL(
p_url => 'f?p=' || l_app || ':11:' || l_session || '::NO:::',
p_checksum_type => 'SESSION'));
BEGIN
l_query:=
'SELECT
post_id,
user_id CARD_SUBTEXT,
image CARD_IMAGE,
title CARD_TITLE,
''' || l_url || ''' CARD_LINK,
text CARD_TEXT
FROM posts';
IF v('P1_TEXT_SEARCH') IS NOT NULL THEN
l_query := l_query||' '||'
WHERE
(
CONTAINS(title, ''' || v('P10_TEXT_SEARCH') || ''') > 0
) OR
(
CONTAINS(text, ''$' || v('P10_TEXT_SEARCH') || ''') > 0
)
';
END IF;
htp.p(l_url || ': ' || l_query);
RETURN l_query;
END;
The l_url variable is my attempt to load the "Post" page which will eventually have the post_id sent in the URL. The page number for the Post page is 11.
When I use "1" (Home page) as the page number it worked fine. But when I used 11 an odd error occurs
Firstly the standard error
1 error has occurred
- Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-00911: invalid character
But the odd part is a line of text is spat out at the very top of the application that says the following:
javascript:apex.navigation.dialog('f?p=4000:11:15325469163221::NO:::\u0026p_dialog_cs=Q1H4HM_OXFo_ZS45s-NOciyBPvE0vUNqa7JH2d-wczZD8Yom-OFjYOrWO4XNE6ciYtHJ0MCQL8cbir4OVFGtUg',{title:'Create Master Detail',height:'480',width:'800',maxWidth:'1200',modal:true,dialog:null,resizable:true,minWidth:500,minHeight:400},'a-Dialog--wizard',this);: SELECT post_id, user_id CARD_SUBTEXT, image CARD_IMAGE, title CARD_TITLE, 'javascript:apex.navigation.dialog('f?p=4000:11:15325469163221::NO:::\u0026p_dialog_cs=Q1H4HM_OXFo_ZS45s-NOciyBPvE0vUNqa7JH2d-wczZD8Yom-OFjYOrWO4XNE6ciYtHJ0MCQL8cbir4OVFGtUg',{title:'Create Master Detail',height:'480',width:'800',maxWidth:'1200',modal:true,dialog:null,resizable:true,minWidth:500,minHeight:400},'a-Dialog--wizard',this);' CARD_LINK, text CARD_TEXT FROM posts Content-Type:text/html; charset=utf-8 Cache-Control:no-store Pragma:no-cache Expires:Sun, 27 Jul 1997 13:00:00 GMT X-Frame-Options:DENY
It's just plain and doesn't look like it's meant to happen.
I tried copying page 11 and trying it on page 12 but that didn't work.
The odd error looks like it could be fixed by allowing embed in frames.
http://www.danielmcghan.us/2011/08/new-browser-security-attributes-in-apex.html
The query parse may have failed if l_url contains quotes, so maybe try
replace(url,'''','"')
And I don't think there's no need to use v() in these locations
IF :P10_TEXT_SEARCH IS NOT NULL THEN -- this also referred to different page
l_app number := :APP_ID;
CONTAINS(title, '$'||:P10_TEXT_SEARCH) > 0

Writing in ExcelSheet using UTL_FILE package in Oracle

I have no problem in writing data in excel sheet which is stored in some predefined directory.
Now I have 10 sets of data and for each set I have to create 10 seperate excel sheet.
But what I want is to create Workbook conating sheet1,sheet2,. Sheet10. Which will have all 10 sets of record. If my question is not clear let me know.
I'm using PL/SQL Oracle 9i
My Code which will write to excel for one set of data. What if I have more set of data and I don't want to have multiple excel sheet instead I want one workbook with diff sheet.
CREATE OR REPLACE PROCEDURE SP_ORACLE_EXCEL(I_FILE_NAME IN VARCHAR2) AS
FILENAME UTL_FILE.FILE_TYPE;
FILENAME1 VARCHAR2(1000);
CURSOR C1 IS
SELECT * FROM MY_TABLE;
VARC1 C1%ROWTYPE;
BEGIN
FILENAME1 := 'TEST_' || I_FILE_NAME || '_' || SYSDATE || '.CSV';
FILENAME := UTL_FILE.FOPEN('TEMP_DIR', FILENAME1, 'W');
/* THIS WILL CREATE THE HEADING IN EXCEL SHEET */
UTL_FILE.PUT_LINE(FILENAME,
'HEADER1' || ',' || 'HEADER2' || ',' || 'HEADER3' || ',' ||
'HEADER4' || ',' || 'HEADER5');
OPEN C1;
LOOP
FETCH C1
INTO VARC1;
EXIT WHEN C1%NOTFOUND;
/* THIS WILL PRINT THE RECORDS IN EXCEL SHEET AS PER THE QUERY IN CURSOR */
UTL_FILE.PUT_LINE(FILENAME,
'"' || VARC1.COL1 || '"' || ' ,' || '"' ||
VARC1.COL2 || '"' || ' ,' || '"' ||
VARC1.COL3 || '"' || ' ,' || '"' ||
VARC1.COL4 || '"' || ' ,' || '"' ||
VARC1.COL5|| '"');
END LOOP;
UTL_FILE.FCLOSE(FILENAME);
END SP_ORACLE_EXCEL;
There's no ready-to-use implementation that I'm aware of.
Excel files (.xslx) since '07 are actually zip archives containing separate xml files for each worksheet.
The XML schema they're using is pretty straight forward. You'd have to use Java to create the folders and do the zip compression in order to write such files.
You can do this with the open source PL/SQL ExcelDocumentType. (Although I haven't tried it on 9i.)
I was able to find a solution to this problem recently posted here on SO (Create an Excel File (.xlsx) using PL/SQL).
i used a package called as_xlsx created by Anton Scheffer, Create an Excel-file with PL/SQL and did a few modifications to the package
so it creates multiple sheets inside a single Excel Workbook by putting it through a Loop.
Hope this helps!

Resources