Reputation: 425
I use a pl/sql procedure calling a webservice. This webservice returns me a large csv-string which I hold in a clob. Since I do not want to parse the csv by foot, I thought of using external tables. So what I need to do is storing the csv data in a corresponding table.
What I am doing at the moment is, that I store the clob using utl_file. the stored file is defined in a external table. Ok, when I am the only user this works very well. But since DBs are multiuser I have to watchout if someone else is calling the procedure and overwriting the external table data source file. What is the best way avoid a mess in table data source? Or what is the best way to store a cvs-sting into a table?
Thanks Chris
Upvotes: 1
Views: 653
Reputation: 35401
You can use UTL_FILE.FRENAME.
In similar situations, I have the external_table pointing to a file (eg "fred.txt"). When I get a new source file in, I use UTL_FILE.FRENAME to try to rename it to fred.txt. If the rename fails, then another process is running, so you return a busy error or wait or whatever.
When the file has finished processing, I rename it again (normally with some date_timestamp).
Upvotes: 0
Reputation: 764
Maybe you should generate temporary filename for each CSV? Something like:
SELECT TO_CHAR(systimestamp, 'YYYYMMDDHH24MISSFF') filename FROM dual
Upvotes: 0
Reputation: 67722
You want to make sure that the procedure is run by at most one session. There are several ways to achieve this goal:
DBMS_LOCK
package to request a lock specific to your procedure. Use the DBMS_LOCK.request
procedure to request a lock. You can ask for a lock that will only be released at the end of your session (this would allow intermediate commits to take place).Upvotes: 1