Save PDF-File into BLOB-Column Oracle DB with INSERT statement - sql

I have to save a PDF-File into a BLOB-Column from a Oracle DB.
I can't use Java and have to use an INSERT-Statement.
The only solutions I've found while searching were very complex.
Is there an easy solution like: INSERT INTO (BLOB_COLUMN) VALUES(BLOBPDF("myPDF.pdf") or something like that?

I would suggest that you use a stored procedure in Oracle where you pass the path to your PDF file and calling the stored procedure does the insert.
Look at the last two sample example here.

If the load is "one-shot" you can use SQLDeveloper.
Otherwise you can use sqlloader (http://docs.oracle.com/cd/B19306_01/server.102/b14215/ldr_params.htm) that is designed for this type of operations

Related

Inserting a single row in SQL, but loading the contents from a file

I can INSERT a row into SQL like this:
INSERT INTO MyTable VALUES (0, 'This is some text...');
However, what if I wanted This is some text... to be the contents of C:\SomeFile.txt. Is there a method in Oracle that makes this possible?
I dug through the Docs a bit and found the LOAD FILE method, however it appears to be for bulk loading data. For example, it wants a FIELDS TERMINATED BY parameter and what not. I want to simply INSERT a single row and set a single column to by the contents of a file on the local disk.
You should never be reading files from the DATABASE SERVER's file system to insert into the db.
Why do you want to do this? You really should read the file in your application code, then insert the string or binary data through standard SQL.
If you really must do this you will need to use the oracle UTL_FILE function. and write some PL/SQL to store in a variable, then insert.
My first time answering a question, so forgive me.
If you're using PHP (which you may well not be, but this is what I know), then you could do something like this:
File: "importantfile.php"
$variable 1 = "0";
$variable 2 = "This is some text...";
File that inserts text: "index.php"
require "importantfile.php";
$query = mysql_query("INSERT INTO MyTable VALUES ('$variable1', '$variable2')");
I hope this helps you in some way :)
To do this I think you would have to use PL/SQL. This is technically an "advanced SQL".
search up a bit about PL/SQL. You can copy your SQL directly into PL/SQL and use the same database.

How to fetch data dynamically from an oracle table whose structure is known only at runtime using pl sql procedure?

I have been given a requirement to create a pl/sql procedure which will accept select statement as an input parameter. All data must be fetched from the query and printed in DBMS_OUTPUT.
I've researched native dynamic SQL and DBMS_SQL but was unable to figure out how to fetch and process data from a table whose structure is unknown.
Since the table name will be provided during run time, i just want to know how to store the data fetched from the query because i cant define variables or collections since the structure of table is unknown
First off, the requirement seems incredibly dubious. You should never depend on data that is written to the DBMS_OUTPUT buffer-- it is entirely up to the client to enable a buffer, to ensure that the buffer is large enough, and to display the data from the buffer to the user. By default, none of that will happen. And writing a procedure to manipulate a table whose structure is completely unknown would be incredibly unusual.
If you are really determined, however, you would likely want to take Tom Kyte's SQL Unloader which uses DBMS_SQL to write data from an arbitrary query to a flat file and modify it to write it to DBMS_OUTPUT instead.
There is an open-source utility package for generating Excel readable files within PL/SQL.
https://code.google.com/p/plsql-utils/
However, I would recommend you look into using a more general purpose language for your tool if at all possible. PL/SQL can be incredibly useful for database logic, but for interacting with the outside world, I expect you will achieve a more maintainable solution using something like Python or Java.
Although, as always YMMV :-)

How to call a big Stored procedure in Qlikview having 3 parameter

I have a stored procedure which contains 3 input parameters with multiple SELECTs and INNER JOINs. I want to Call the stored procedure in QlikView. I followed lots of tutorials, but I make it work.
I am Using OLE DB and I'm trying to call as follows:
SQL CALL [DB NAME].[dbo].[ABC] #_ End-Time ='2012-12-31 00:21:06.550', #_ Start-time = '2012-12-31 00:21:06.550',
#_ Username = 'XYZ';
Is this correct? If not, what are the ways to call stored procedures into Qlikview and what permission do I need for this?
i'm not sure that you checked this thread (http://goo.gl/IiGD2) but it might be useful. Couple of things that i'm noticing from it: there is additional string that need to be added to the connection string "(mode is write)" and also to activate the "Open Databases in Read and Write mode" in qv.
Also make sure that you have sql rights to execute.
Regards!
Stefan
A workaround could be to retrieve the three input variables from a table instead, and update this table from qlikview using SQL insert.
It may be possible to run an store procedure from QlikView, but it is not possible to pull any output you get from it. You should convert that to a function if you want to retrieve any data from QlikView.
Creating a MV is your best course of action, and you will have a better performance.

Get all values from one column of a CSV string using Stored Procedure

Within a stored procedure, I need to take a whole CSV file as a string, then pick out all the values in one "column" to do a further query on the database.
I cannot use a saved doc - so i think that rules out openrowset, and the whole thing has to be done within a stored procedure.
Have spent hours googling and trying, but can find a good answer. One possible was http://www.tainyan.com/articles/entry-32/converting-csv-to-sql-data-table-with-stored-procedure.html but it doesnt work and i can find the error.
How should this be done please?
I don't really like this but it will work, provided your csv column remains at the same column index. I'd be wary of the performance of this but it might work.
See Fiddle here: http://sqlfiddle.com/#!3/336b7/1
Basically convert your csv file to xml, cast to an xml type, then perform queries on the xml.

Using an sql-function when reading and writing with NHibernate

I have the following problem.
I have a special column in my tables (a blob). In order to read and write to that column, I need to call an SQL function on its value - to convert to a string when I read, and to convert from a string to this blob when I write.
The read part is easy - I can use a formula to run the sql function against the column. But formulas are read only. Using IUserType also did not seem to assist - I can get the blob and write my own code to convert it to my own type, but I don't want to do that - I already have a database function that does this work for me.
Any ideas?
You can specify sql to insert and update, see the reference documentation, "Custom SQL for create, update and delete". Here is an example from Ayende which uses stored procedures (which is not the same, just to see how it works).
Or you could write a database trigger which does this transformation.