Is there a bulk unload utility in Oracle - oracle

I am trying to unload a large oracle table as a JSON file. Is there a BCP utility similar to what we have in SQL Server?
Thanks

Using SQL*Plus or SQLcl to spool to a file is one option (methods to generate CSV would work similarly for JSON):
https://blogs.oracle.com/opal/fast-generation-of-csv-and-json-from-oracle-database
https://oracle-base.com/articles/misc/sqlcl-format-query-results-with-the-set-sqlformat-command#json
https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9536328100346697722
You could also use PL/SQL functions and write to a file using UTL_FILE:
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/adjsn/generation.html#GUID-6C3441E8-4F02-4E95-969C-BBCA6BDBBD9A
https://oracle-base.com/articles/9i/generating-csv-files
Or use ROracle:
https://oralytics.com/2015/05/14/extracting-oracle-data-generating-json-data-file-using-roracle/
There are most likely several other ways, too.

Related

How to use bcp utility with oracle dB or any other better options

I have a csv file which has to be bulk imported to oracle dB. I was working on other sybase dB engine before so I had a sample script which has the environment setup for it. Right now I have to do the process in a oracle dB so what should be the first line I know about the rest other parameters but want to know the path which has to be defined when I write
path/bcp dbtable in data.txt
If anyone could help what should be the path for oracle dB
The primary tools for bulk or flat file loading are:
SQL*Loader
External Tables (and here)
GUI Tools like SQL*Developer
It is much more cumbersome, but if necessary you can roll your own solution with the UTL_FILE PL/SQL package.

How to create flat file from toad for oracle using script OR stored procedure?

I need to create a flat file using script/stored procedure in toad for oracle. I can't use UTL_FILE here because of the privilege reason.
Please do not suggest me export wizard.
Thanks in advance.
Creating an external table that writes into a file might be an option too: External Table Concepts
The advantage is you can use/execute it anywhere (Toad, procedure call in DB, SQL console, etc)
If you need it only once or a few times I would use as already mentioned: spool file or the dbms_output package.

Export Oracle table using Stored Procedure to an excel file

I am using SQL Developer 1.5.5 and I need to export some tables from an Oracle 11g database to an xls file. I have tried using spool, but I cannot put in a stored procedure as error comes up. Is there some other alternative to do this?
I am trying to create reports from data base by executing the procedure.
Thanks.
Anton Scheffer (from AMIS.NL) wrote an APEX plugin to load Oracle data into a Excel file. It works very well and it can be used alone (without APEX) with a additional work.
Check out: http://technology.amis.nl/2011/02/19/create-an-excel-file-with-plsql/
You can also use SQLX (see http://technology.amis.nl/2006/01/20/generate-anative-excel-file-with-sqlx/) but it could be very complex depending on what you ha

Loading data from a web-hosted CSV into Oracle?

I don't have time to write a perl or anything like that nor do I have admin access to the back end, so how can I get data from a file on the intranet (http://) and parse it to create a table? Maybe somehow via PL/SQL? Keep in mind I don't have much admin access.
If you want it to be completely automated
You can use the UTL_HTTP package to retrieve the data from the HTTP server
You can either parse the CSV response yourself using INSTR and SUBSTR or you can use the UTL_FILE package to write the data to a file on the database server file system and then create an external table that parses the CSV file you just created.
You can then insert the parsed data into a table you've already created (I'm assuming that the CSV data is in the same format each time).
You can use the DBMS_SCHEDULER or DBMS_JOB package to schedule the job
The Oracle database account you're using will need to be granted access to all of these packages.
You may download the file into your host machine and then use SQL*Loader to populate a table.
Other ways there are some wizards that may be easier than SQL*Loader, if you are using IDEs like PLSQLDeveloper(Tools->Text Importer) or SQLDeveloper(right click on Tables-> Import Data).
Create an external table that references your CSV file. That means you can run select statements on the file from within Oracle.

Getting output in flat file using oracle on UNIX

How to get the output of a query into a flat file using Oracle on UNIX?
For example:
I have a TEST table; I want to get the content of the TEST table into a flat file and then store the output in some other folder in .txt format.
See Creating a Flat File in the SQL*Plus User's Guide and Reference.
in the oracle SQLplus terminal you could type
spool ;
run your query
spool off;
Now the would contain the results of the query.
In fact it would contain all the output to the terminal since the execution of the spool command till spool off.
If you have access to directories on the database server, and authority to create "Directory" objects in Oracle, then you have lots of options.
For example, you can use the UTL_FILE package (part of the PL/SQL built-ins) to read or write files at the operating system level.
Or use the "external table" functionality to define objects that look like single tables to Oracle but are actually flat files at the OS level. Well documented in the Oracle docs.
Also, for one-time tasks, most of the tools for working SQL and PL/SQL provide facilities for moving data to and from the database. In the Windows environment, Toad's good at that. So is Oracle's free SQLDeveloper, which runs on many platforms. You wouldn't want to use those for a process that runs every day, but they're fine for single moves. I've generally found these easier to use than SQL*Plus spooling, but that's a primitive version of the same functionality.

Resources