bulk import pdf files into oracle table - oracle

i have multiple folders on my disk and each folder has pdf files (4 files in each folder). How can i insert files in each folder in oracle table rows. the folder name will make primary key (being unique social svc #). i have used code as is from this link but i get following error:-
ora-22285 non-existent directory or file for fileopen operation
ora-06512 at sys.dbns_lob line 805
i ve also granted all permissions on the directory to my user with command:-
grant all on directory blob_dir to testuser
pl tell me what am i doing wrong.

if you going to use BLOB data type then you can upload data from external file using SQL*Loader. In case you are going to use BFILE then you just need to copy files into Oracle Server file system and grant access to it via DIRECTORY object with READ privelege. BFILE provides read only access to external files via SQL.

Related

how use UTL_FILE package for write file on map drive?

I use UTL_FILE package in my procedure for saving file on database server but i need to save file on another server for that i make a map drive but this UTL_FILE not saving files on my MAP Drive me also check manually drive Read and write the file but through procedure UTL_FILE not ABLE TO save the file on map drive and i got this error "Data Base Error: ORA-29283: invalid file operation ORA-06512: at "SYS.UTL_FILE", line 536 ORA-29283: invalid file operation "
If it is a directory on a server that is not the database server, option that used to work for me was to use UNC (Universal Naming Convention) while creating directory (as an Oracle object). For example:
No : Z:\files_4005
Yes: \\my-another-server\d$\home\gis\files_4005"

Oracle 18c external table importing csv file from UNC path

Preface
This script has worked previously when importing a csv file into an external table when using a local path for the created directory (with a local drive like F:\stats) instead of a UNC path (\\station-1\...)
Script
CREATE OR REPLACE DIRECTORY csvdir AS '\\Station-1\mainFolder\stats';
DROP TABLE EXT_index;
CREATE TABLE EXT_index(
SESSION_STATION NVARCHAR2(60),
"user" NVARCHAR2(20),
"type" NCHAR(4),
"date" DATE,
"hour" NVARCHAR2(8),
BATCH NUMBER,
STEP NUMBER,
VARIANTE NUMBER,
TIME_MS NUMBER,
NB_FOLDER NUMBER,
NB_DOC NUMBER,
NB_FIELDS NUMBER,
NB_FIELDS_SHOW NUMBER,
NB_FIELDS_CONFIRM NUMBER,
NB_FIELDS_EMPTY NUMBER,
NB_KEY NUMBER,
NB_CHAR NUMBER,
NB_USEFUL_CHAR NUMBER
)organization external (
type oracle_loader
default directory csvdir
access parameters (
records delimited by newline skip 1
fields terminated by ';' lrtrim
missing field values are null (
SESSION_STATION,
"user",
"type",
"date" date 'yyyy-mm-dd',
"hour",
BATCH,
STEP,
VARIANTE,
TIME_MS,
NB_FOLDER,
NB_DOC,
NB_FIELDS,
NB_FIELDS_SHOW,
NB_FIELDS_CONFIRM,
NB_FIELDS_EMPTY,
NB_KEY,
NB_CHAR,
NB_USEFUL_CHAR
)
)
location('INDEX.csv')
)
reject limit unlimited;
DROP TABLE TMP_index;
CREATE TABLE TMP_index AS(SELECT * FROM EXT_index);
Information
Database used : OracleXE 18c
The folder containing the csv we need to import is '\\Station-1\mainFolder\stats' and is situated on a remote station, different than my local computer running the database
Problem
As said previously, this script works fine when csvdir is a local path (F:\mainFolder\stats), the csv is imported into the external table and the temp table can be created from it afterwards just fine.
When csvdir is a UNC path the error is the following : KUP-04027: file name check failed: INDEX.csv
When csvdir is a network drive mapped to the previous UNC path (J:\ mapped to \\Station-1\mainFolder, such as csvdir=J:\stats) the error is the following : KUP-04040: file INDEX.csv in CSVDIR not found
Both these errors occur when trying to create TMP_index from EXT_index :
CREATE TABLE TMP_index AS(SELECT * FROM EXT_index)
Error report -
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
--> Either KUP-04027 or KUP-04040 here, depending on how csvdir was created <--
When checking in SQL Developer, EXT_index is always empty, the table doesn't seem to be created properly (i.e. the Data tab of that table doesn't even show column names)
Steps taken for attempted resolution
The folder '\\Station-1\mainFolder' is shared with 2 users having full control over it : Everyone and User1 (my account)
On the computer that has the database (My local computer) this '\\Station-1\mainFolder' is mapped to a network drive : J:\
When using J:\, csvdir is created as 'J:\stats'
When using \\Station-1\mainFolder, csvdir is created as '\\Station-1\mainFolder\stats'
As per this link both services TNSListener and OracleServiceXE are started logging in to my account, User1
Question
How can I import a csv file situated on a remote server into a local external table?

Why do I get ORA-39001: invalid argument value when I try to impdp in Oracle 12c?

When I run this command in Oracle 12c SE2:
impdp system/Oracle_1#pdborcl directory=DATA_PUMP_DIR dumpfile=mydb.dmp nologfile=Y
I get this:
ORA-39001 : invalid argument value
ORA-39000 : bad dump file specification
ORA-39088 : directory name DATA_PUMP_DIR is invalid
We used to import this into 11g all the time.
How can I solve these errors?
From the 12c documentation:
Be aware of the following requirements when using Data Pump to move data into a CDB:
...
The default Data Pump directory object, DATA_PUMP_DIR, does not work with PDBs. You must define an explicit directory object within the PDB that you are exporting or importing.
You will need to define your own directory object in your PDB, which your user (system here) has read/write privileges against.
create directory my_data_pump_dir as 'C:\app\OracleHomeUser1\admin\orcl\dpdump';
grant read, write on directory my_data_pump_dir to system;
It can be the same operating system directory that DATA_PUMP_DIR points to, you just need a separate directory object. But I've used the path you said you'd prefer, from a comment on a previous question.
Then the import is modified to have:
... DIRECTORY=my_data_pump_dir DUMPFILE=mydb.dmp

Oracle 11g. Unable to import dump files, even though schema is created

I have created a user in Oracle 11gR2, using the following script
create user cata
identified by cata
default tablespace tbs
temporary tablespace temp;
grant DBA to cata;
After trying to import a dump file using the command
impdp system/password#ORCL11 schemas=cata dumpfile=cata.dmp logfile=log.txt
i'm getting the following error
ORA-39002: invalid operation
ORA-39165: Schema ATGDB_CATA was not found.
Surprisingly, when i try to export a dump from the same schema, i'm able to do that. So, if the schema was not created properly then i should not be able to export the dump file as well, right ?
I have also checked in dba_users & the schema is created. Is there anything else that i can do which could resolve this problem
Out of the error message I guess that the original schema name was "atgdb_cata".
As you are now trying to import into a schema named "cata" you need to specify the parameter remap_schema
So for your case:
impdp system/password#ORCL11 schemas=atgdb_cata dumpfile=cata.dmp logfile=log.txt remap_schema=atgdb_cata:cata
Grant the roles of read and write on the Directory in which you created to the New User: EX:
GRANT READ, WRITE ON DIRECTORY dir_name TO NEW_USER:
Also grant the following role to the new user:
GRANT IMP_FULL_DATABASE TO NEW_USER;
Thanks!
NC
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
SOLUTION:
create or replace directory test_ dir as 'FOLDER_NAME' ;
that 'FOLDER_NAME' must has that dump file
step : 1
create folder SAMPLE under orcle_installed_path/sql/SAMPLE
put that dump file into that SAMPLE folder.
go to bin and execute ./sqlplus
and login
SQL>create or replace directory test_ dir as 'SAMPLE' ;
SQL> SQL> GRANT READ, WRITE on directory test_dir to 'USER';
SQL> GRANT IMP_FULL_DATABASE to 'USER';
exit
then impdb to import that dump

Howto import an oracle dump in an different tablespace

I want to import an oracle dump into a different tablespace.
I have a tablespace A used by User A. I've revoked DBA on this user and given him the grants connect and resource. Then I've dumped everything with the command
exp a/*** owner=a file=oracledump.DMP log=log.log compress=y
Now I want to import the dump into the tablespace B used by User B. So I've given him the grants on connect and resource (no DBA). Then I've executed the following import:
imp b/*** file=oracledump.DMP log=import.log fromuser=a touser=b
The result is a log with lots of errors:
IMP-00017: following statement failed with ORACLE error 20001: "BEGIN DBMS_STATS.SET_TABLE_STATS
IMP-00003: ORACLE error 20001 encountered
ORA-20001: Invalid or inconsistent input values
After that, I've tried the same import command but with the option statistics=none. This resulted in the following errors:
ORA-00959: tablespace 'A_TBLSPACE' does not exist
How should this be done?
Note: a lot of columns are of type CLOB. It looks like the problems have something to do with that.
Note2: The oracle versions are a mixture of 9.2, 10.1, and 10.1 XE. But I don't think it has to do with versions.
You've got a couple of issues here.
Firstly, the different versions of Oracle you're using is the reason for the table statistics error - I had the same issue when some of our Oracle 10g Databases got upgraded to Release 2, and some were still on Release 1 and I was swapping .DMP files between them.
The solution that worked for me was to use the same version of exp and imp tools to do the exporting and importing on the different Database instances. This was easiest to do by using the same PC (or Oracle Server) to issue all of the exporting and importing commands.
Secondly, I suspect you're getting the ORA-00959: tablespace 'A_TBLSPACE' does not exist because you're trying to import a .DMP file from a full-blown Oracle Database into the 10g Express Edition (XE) Database, which, by default, creates a single, predefined tablespace called USERS for you.
If that's the case, then you'll need to do the following..
With your .DMP file, create a SQL file containing the structure (Tables):
imp <xe_username>/<password>#XE file=<filename.dmp> indexfile=index.sql full=y
Open the indexfile (index.sql) in a text editor that can do find and replace over an entire file, and issue the following find and replace statements IN ORDER (ignore the single quotes.. '):
Find: 'REM<space>' Replace: <nothing>
Find: '"<source_tablespace>"' Replace: '"USERS"'
Find: '...' Replace: 'REM ...'
Find: 'CONNECT' Replace: 'REM CONNECT'
Save the indexfile, then run it against your Oracle Express Edition account (I find it's best to create a new, blank XE user account - or drop and recreate if I'm refreshing):
sqlplus <xe_username>/<password>#XE #index.sql
Finally run the same .DMP file you created the indexfile with against the same account to import the data, stored procedures, views etc:
imp <xe_username>/<password>#XE file=<filename.dmp> fromuser=<original_username> touser=<xe_username> ignore=y
You may get pages of Oracle errors when trying to create certain objects such as Database Jobs as Oracle will try to use the same Database Identifier, which will most likely fail as you're on a different Database.
If you're using Oracle 10g and datapump, you can use the REMAP_TABLESPACE clause. example:
REMAP_TABLESPACE=A_TBLSPACE:NEW_TABLESPACE_GOES_HERE
For me this work ok (Oracle Database 10g Express Edition Release 10.2.0.1.0):
impdp B/B full=Y dumpfile=DUMP.dmp REMAP_TABLESPACE=OLD_TABLESPACE:USERS
But for new restore you need new tablespace
P.S. Maybe useful http://www.oracle-base.com/articles/10g/OracleDataPump10g.php
What version of Oracle are you using? If its 10g or greater, you should look at using Data Pump instead of import/export anyway. I'm not 100% sure if it can handle this scenario, but I would expect it could.
Data Pump is the replacement for exp/imp for 10g and above. It works very similar to exp/imp, except its (supposedly, I don't use it since I'm stuck in 9i land) better.
Here is the Data Pump docs
The problem has to do with the CLOB columns. It seems that the imp tool cannot rewrite the create statement to use another tablespace.
Source: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:66890284723848
The solution is:
Create the schema by hand in the correct tablespace. If you do not have a script to create the schema, you can create it by using the indexfile= of the imp tool.
You do have to disable all constraints your self, the oracle imp tool will not disable them.
After that you can import the data with the following command:
imp b/*** file=oracledump.dmp log=import.log fromuser=a touser=b statistics=none ignore=y
Note: I still needed the statistics=none due to other errors.
extra info about the data pump
As of Oracle 10 the import/export is improved: the data pump tool ([http://www.oracle-base.com/articles/10g/OracleDataPump10g.php][1])
Using this to re-import the data into a new tablespace:
First create a directory for the temporary dump:
CREATE OR REPLACE DIRECTORY tempdump AS '/temp/tempdump/';
GRANT READ, WRITE ON DIRECTORY tempdump TO a;
Export:
expdp a/* schemas=a directory=tempdump dumpfile=adump.dmp logfile=adump.log
Import:
impdp b/* directory=tempdump dumpfile=adump.dmp logfile=bdump.log REMAP_SCHEMA=a:b
Note: the dump files are stored and read from the server disk, not from the local (client) disk
my solution is to use GSAR utility to replace tablespace name in the DUMP file. When you do replce, make sure that the size of the dump file unchanged by adding spaces.
E.g.
gsar -f -s"TSDAT_OV101" -r"USERS " rm_schema.dump rm_schema.n.dump
gsar -f -s"TABLESPACE """USERS """ ENABLE STORAGE IN ROW CHUNK 8192 RETENTION" -r" " rm_schema.n1.dump rm_schema.n.dump
gsar -f -s"TABLESPACE """USERS """ LOGGING" -r" " rm_schema.n1.dump rm_schema.n.dump
gsar -f -s"TABLESPACE """USERS """ " -r" " rm_schema.n.dump rm_schema.n1.dump
I wanna improve for two users both in different tablespaces on different servers (databases)
1.
First create a directories for the temporary dump for both servers (databases):
server #1:
CREATE OR REPLACE DIRECTORY tempdump AS '/temp/old_datapump/';
GRANT READ, WRITE ON DIRECTORY tempdump TO old_user;
server #2:
CREATE OR REPLACE DIRECTORY tempdump AS '/temp/new_datapump/';
GRANT READ, WRITE ON DIRECTORY tempdump TO new_user;
2.
Export (server #1):
expdp tables=old_user.table directory=tempdump dumpfile=adump.dmp logfile=adump.log
3.
Import (server #2):
impdp directory=tempdump dumpfile=adump_table.dmp logfile=bdump_table.log
REMAP_TABLESPACE=old_tablespace:new_tablespace REMAP_SCHEMA=old_user:new_user
The answer is difficult, but doable:
Situation is: user A and tablespace X
import your dump file into a different database (this is only necessary if you need to keep a copy of the original one)
rename tablespace
alter tablespace X rename to Y
create a directory for the expdp command en grant rights
create a dump with expdp
remove the old user and old tablespace (Y)
create the new tablespace (Y)
create the new user (with a new name) - in this case B - and grant rights (also to the directory created with step 3)
import the dump with impdp
impdp B/B directory=DIR dumpfile=DUMPFILE.dmp logfile=LOGFILE.log REMAP_SCHEMA=A:B
and that's it...
Because I wanted to import (to Oracle 12.1|2) a dump that was exported from a local development database (18c xe), and I knew that all my target databases will have an accessible tablespace called DATABASE_TABLESPACE, I just created my schema/user to use a new tablespace of that name instead of the default USERS (to which I have no access on the target databases):
-- don't care about the details
CREATE TABLESPACE DATABASE_TABLESPACE
DATAFILE 'DATABASE_TABLESPACE.dat'
SIZE 10M
REUSE
AUTOEXTEND ON NEXT 10M MAXSIZE 200M;
ALTER DATABASE DEFAULT TABLESPACE DATABASE_TABLESPACE;
CREATE USER username
IDENTIFIED BY userpassword
CONTAINER=all;
GRANT create session TO username;
GRANT create table TO username;
GRANT create view TO username;
GRANT create any trigger TO username;
GRANT create any procedure TO username;
GRANT create sequence TO username;
GRANT create synonym TO username;
GRANT create synonym TO username;
GRANT UNLIMITED TABLESPACE TO username;
An exp created from this makes imp happy on my target.
---Create new tablespace:
CREATE TABLESPACE TABLESPACENAME DATAFILE
'D:\ORACL\ORADATA\XE\TABLESPACEFILENAME.DBF' SIZE 350M AUTOEXTEND ON NEXT 2500M MAXSIZE UNLIMITED
LOGGING
PERMANENT
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT MANUAL
FLASHBACK ON;
---and then import with below command
CREATE USER BVUSER IDENTIFIED BY VALUES 'bvuser' DEFAULT TABLESPACE TABLESPACENAME
-- where D:\ORACL is path of oracle installation

Resources