I have a application built using Oracle APEX 20.x.
The issue is need to programmatically upload the (.pdf,.txt,.png,.jpeg,.jpg) as a BLOB to table
I heard about the APEX_APPLICATION_TEMP_FILES.
How to utilize this table to upload my file as BLOB to this following table using Insert statement?
I want to achieve this activity on Button click -> dynamic action -> PLSQL coding
here on Stackoverflow, there are great examples about it. but in a nutshell:
if :P1_MY_FILE is not null then
select blob_content, filename, mime_type
into l_req_file, l_req_file_name, l_req_mime_type
from apex_application_temp_files
where name = :P1_MY_FILE ;
end if;
should give the idea
Related
I need to burn a blob column from an image that is saved in windows.
How do I declare the image path in Oracle PLSQL?
Ex:
DECLARE
dest_lob BLOB;
-- this line report ORA22285 "non-existent directory or file for %s operation"
src_lob BFILE := BFILENAME('MY_DIR', 'C:\Users\gus\Desktop\image.jpg');
BEGIN
INSERT INTO teste_gustavo_blob VALUES(2, EMPTY_BLOB())
RETURNING imagem INTO dest_lob;
DBMS_LOB.OPEN(src_lob, DBMS_LOB.LOB_READONLY);
DBMS_LOB.LoadFromFile( DEST_LOB => dest_lob,
SRC_LOB => src_lob,
AMOUNT => DBMS_LOB.GETLENGTH(src_lob) );
DBMS_LOB.CLOSE(src_lob);
COMMIT;
END;
Note: I'm trying to insert a record into a table through a Windows machine using SQLDeveloper. The database is on a remote server.
the path needs to be part of the directory object definition, and the file name is just that - just the file name. Example;
CREATE DIRECTORY MY_DIR AS 'C:\Users\gus\Desktop';
..
BFILENAME('MY_DIR', 'image.jpg');
Note that the directory is created on the server not your local machine. So if you are trying to create a file on a local machine, this will not work in pl/sql. PL/sql runs on the server, not the client. In that case, you need to code a client.
The database can only see directories which are local to it. It cannot see files on your PC (unless the database is running on that PC). So you cannot load your file through PL/SQL.
However, you say you are using SQL Developer. You can load a BLOB by editing the table's data in the Table Navigator. Click on the Data tab then edit the cell (the BLOB column of the row you want to load the file into). Use the Local Data > Load option to upload your file. That Jeff Smith has publish a detailed step-by-step guide on his blog.
I had a similar problem recently. I needed to dev test a feature and I needed a PDF file in my DB. I read few questions here and formulated an answer. I inserted a row manually with SQL and changed the file manually after that.
The SQL:
insert into ATTACHMENT_TABLE (id, file_content) values
(1, utl_raw.cast_to_raw('some dummy text'));
Using DBeaver, I edited the row and loaded the file from my windows PC. The end result is a row which contains the PDF file I wanted.
I have an plsql SP that creates multiple tables on a daily basis, however the number of tables are not always the same, however, the generated tables have a predefined pattern in its name.
I'm trying to create a plsql SP who exports those tables to a csv or excel file, based on a list input with the name of the generated tables.
Any ideas for achieving this rather than use PLSQL or is there any useful way of achieve this with it?
Thanks in advance
i think this question is very abstract and can have many solutions. Here is a solution that you can try if you want to create Excel from your data.
First you need a tool to create an excel file. Anton Scheffer has developed a package that you can use to create easily an Excel file from a cursor. Have a look: Create an Excel-file with PL/SQL.
Next, you can determine the created tables and create a query string that you can pass as parameter into query2sheet procedure of the Anton's package. All Tables you can find in user_tables View.
So your code could looks like:
for rec in (select * from user_tables where 1=1 /* or condition you need to filter the correct tables*/)
loop
-- as_xlsx - is a package created by Anton Scheffer
as_xlsx.query2sheet( 'select * from '||rec.table_name );
-- MY_DIR is a database Directory that you have to create
as_xlsx.save( 'MY_DIR', rec.table_name||'.xlsx' );
end loop;
Edit:
If you want to create a csv files, so you can use a package developed by William Robertson, Ref cursor to CSV converter.
The usage is quite similar to the Excel package.
Currently had a request to automatically add data in a form window into two tables at once. I was able to accomplish this with simple insert functions as processes, but for the life of me I can not figure out how to get the attached file in the file browse to attach to the other table using am insert function. The blob column always shows up as [unsupported datatype].
Here's my current insert code, let me know I'm being an idiot and missing something simple.
insert into ATTACHMENTS_AVAIL ("ADDED_FILE", "MIMETYPE", "FILENAME", "CONTRACTOR_ID", "DATE_ADDED", "TYPE")
values
(:P159_RESUME,
:P159_MIMETYPE,
:P159_FILENAME,
:P159_CONTRACTOR_ID,
sysdate,
'Resume');
ADDED_FILE is the blob column and :P159_RESUME is the file browse form.
Thanks again!
Inserting the BLOB
Your insert statement isn't getting the BLOB data, just the APEX file ID. You need to do something more like this:
insert into ATTACHMENTS_AVAIL ("ADDED_FILE", "MIMETYPE", "FILENAME", "CONTRACTOR_ID", "DATE_ADDED", "TYPE")
select blob_content,
:P159_MIMETYPE,
:P159_FILENAME,
:P159_CONTRACTOR_ID,
sysdate,
'Resume'
from apex_application_files where name = :P159_RESUME;
In fact, apex_application_files has other columns to tell you the mime type etc.
Viewing the BLOB
You are trying to view the BLOB data in APEX's SQL Workshop. That can't display BLOBs (it just shows "[unsupported datatype]" as you found), but that doesn't mean the BLOB data is invalid. A BLOB can contain anything - music in MP3 format, picture in JPEG, video in MP4, Microsoft Word document, etc. etc. No tool can "display" all of these.
If you create a new page with a report on it to show the data, you can set the BLOB column's Type to Display Image if the BLOB always contains an image, or to Download BLOB if it may contain non-image data.
I am trying to read the contents of a text file that I uploaded using the page item file browser but I cannot figure out how to get the files contents.
I don't need it to be pushed into a table or anything, I just want a string represetation of it in a text area, for example. Or to be stored into a variable so I can process.
Apologies for the vagueness if any. I have tried a few ways but I am not sure, can I get the contents somehow using the WWV_FLOW_FILE?
The only solutions I have seen are using the Wizard region with the data mapping/verification breadcrumbs which is not what I need.
You can find the uploaded file as a BLOB inside the WWV_FLOW_FILE. If you just want to show it, into lets say a text field named P1_some_text_field, you can simple add a procedure like this on the page where you do the upload:
BEGIN
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(blob_content))
INTO :P1_some_text_field
FROM wwv_flow_files
WHERE created_on =
(SELECT MAX(created_on) FROM wwv_flow_files WHERE CREATED_BY = :APP_USER
);
END;
Please note that this will retrieve at most the fist 32767 characters of your file.
When I upload the file to WWV_FLOW_FILES, I then used a pl/sql statement to get the ID of the last file uploaded by the user and send the ID through another pl/sql statement which launches a powershell script on the server to download the file. The file is then processed on the server.
I have an Oracle 10G database and I need to write a fairly straightforward query that joins two tables and selects some data. However, I'd like to export the result list to an excel, so end users can use this .xls document to see the results and filter by one of the fields (location)
When I write the query, is there an easy way I can generate/ create an excel document that would hold these results as described above? The SQL doesn't need to run from within excel, but I guess that would be a useful feature now that I think about it!
Thanks.
There is simple solution for your request.
By using ora_excel, small pl/sql package which generates Excel xlsx file, you can select data and export selected data to Excel and set filtering.
Please see following example:
BEGIN
ORA_EXCEL.new_document;
ORA_EXCEL.add_sheet('My sheet');
ORA_EXCEL.query_to_sheet('select * from employees'); -- Select data from database
ORA_EXCEL.set_cells_filter('A1', 'K1'); -- Add cell filtering from column A1 to column K1
-- Save generated Excel to file with name example.xlsx to Oracle folder EXAMPLE_XLSX
ORA_EXCEL.save_to_file('EXPORT_DIR', 'example.xlsx');
END;
For more details please check here
Cheers
Pretty easy to do in excel; and when done user can right click the data and say "Refresh" to get the latest updates.
but why reinvent the wheel lots of online articles already explain how to do this... Here's one
http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
After you've connected to a table, you can edit the properties on the connection and enter custom SQL (copy and paste from your developer tools)
Since you cannot use OLE DB in your version of Excel. Use SPOOL to create a CSV file.
SQL> SET echo off
SQL> SET verify off
SQL> SET colsep ,
SQL> SET pagesize 0
SQL> SET trimspool on
SQL> SET feedback off
SQL> SPOOL ON
SQL> SPOOL C:\data.csv
SQL> SELECT COLUMN1,COLUMN2,COLUMN3....
FROM TABLE;
SQL> SPOOL OFF
The .csv file should open in Excel by default. Use proper column aliases so that users understand the column headers.
Quick way:
At first create a view which contains your Query(Best way because you might need to change this query later).
Be sure to properly have installed oracle client.
In Excel(2007 and above) in Data tab go this way:
From Other sources -> From Data Connection Wizard -> Microsoft Data Access - OLE DB Provider for Oracle
Now Enter your DataSource Name(Stored in tnsnames.ora) and user password
Find you view and Then You'll have what you need.
You can save password and set option to refresh automatically in connection properties.
You are able to query an oracle database directly from Excel 2003 however, your sql statements are interpreted by MS Query and because of this it can often be frustrating. I will assume the machine in question already has the ability to query your database and has properly configured the database naming.
To query your database from excel 2003 you must:
Install and configure oracle's ODBC Driver (You must have the 32bit drivers installed since excel03 is a 32bit application). ODBC can be configured under start > administrative tools > ODBC Data Source Administrator
Open excel 2003 and goto data > import external data > new database query.
This should bring up MS Query which is an Access-like interface.
Obviously this is a very brief starter to get you stepping in the right direction. If you have any specific questions, please comment and I will try and help you.
Step 1
Run Your Query
Right Click on Resultenter image description here
Step 2
Click on Export
enter image description here
Step 3
Select Format To Excel
Enter datasheet name and location
Step 4
Click on Next and then finish
enter image description here
You can do one thing.
First generate the output in a form that includes column separators using symbols (like , or #).
Import the data to the excel and then define the placeholders as the column separators.