How to handle bad files generated by external tables - oracle

I've always developed shell scripts on server Unix where the script before runs the SQL-Loader for loading the file to be inserted into an Oracle table and after verifies if it's been generated any BAD file and in that case for example it sends an email to me with a warning.
Instead, by using an external table, I've got the main advantage not to handle any shell scripts but since only at the moment I run the SELECT from my external table a BAD file might be generated on the server, how can I have an automated check on its existence and to handle it from Oracle?
Oracle version 10g
Thanks!

With external tables, everything you do, you do in Oracle (i.e. within the database).
Therefore, you could
create a PL/SQL program (anonymous PL/SQL block or a stored procedure)
access the external table
do whatever you do
after it is finished, use UTL_FILE to check log/bad file
use DBMS_MAIL to send an e-mail if there's something "wrong"

Related

Create tables in hive from ddl files

I am using JRuby to connect to Hive, which is happening successfully. Now I want to create tables, but instead of writing the create statement as a parameter to execute() method, I want to call a ddl file that has the table definition.
I cannot take the file contents and use them because they are usually more than one statement before the actual table creation (i.e. CREATE DATABASE IF NOT EXISTS, CREATE TABLE IF NOT EXISTS ..)
Is there a command that I can use through my JDBC connect that take the ddl file and executes it?
As per my knowledge there is no direct way with JDBC API to do an operation similar to hive -f ,
option 1)
you can parse your SQL file and write a method to execute the commands sequentially (or) use third party code,
here is one reference http://www.codeproject.com/Articles/802383/Run-SQL-Script-sql-containing-DDL-DML-SELECT-state
option 2) If your client environment where Jruby code is running also supports hive, write a shell script which can connect to remote JDBC and run SQL with beeline which will make remote Thrift calls
Reference : https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients

Is there a possible way to load a Oracle .dmp file to an SQL Server 2012?

This throws me the below error:
the media family on device is incorrectly formed 3241.
I tried loading the .dmp file as .bak file and restored the db. It did not work.
Only way I know to extract from dmp is to use the "INDEXFILE" parameter for IMP, this will generate a readable SQL script with the DDL and DML.
However often times this script is not 100% usable as it (usually) wraps the statements, so some pre-processing may be required, for example parse the file by each discrete statement (INSERT, CREATE), join each statement into a single line then squirt into the target database. Having said that, you would probably need to pre-process anyway to translate Oracle to SQL server dialogue anyway.
Also, might not be so good for BLOB/binary type data.
The other indirect way to do this would be to create a bridge Oracle database, import the file into there, then use the normal extract and load tools to push the data into SQL server.
A *.dmp file in Oracle is nothing but a backup file. You meant to say restoring a Oracle DB backup file in SQL Server.
AFAIK, the answer is NO. You can't do that. Probably you can check, if there is any third party utility present using which you can perform a DB migration.
The dmp file comes in an Oracle specific format that cannot be parsed/interpreted by anything other than Oracle's imp tool. So, that means you cannot import the dmp file into SQL Server.
Of course there are ways to transfer data from Oracle to SQL Server but which one is optimal depends on your needs, amount of data, number of tables, number of Oracle schemas, datatypes etc etc.

Is it possible to execute a SQL script file stored on the database server using a remote command?

Say I have a SQL script physically stored on the database server. Is there a SQL command I can send Oracle from an application to tell it to execute that script?
(Yes, I know this sounds ridiculous. I'm considering it as part of a work around of a very nasty problem that "shouldn't happen" but does.)
The easiest option would generally be to use the dbms_scheduler package to run an external job. This would let you invoke a shell script that started SQL*Plus, connected to the database, and ran your .sql script.
It would also be possible to create a Java stored procedure that uses Java's ability to call out to the operating system to run the same shell script. That tends to be a bit more of a security issue, though, since you're ending up granting the owner of this procedure privileges to run any command on the database server as the oracle user. That would include things like connecting to the database as SYSDBA or corrupting the database (accidentally or intentionally) so it's something that auditors would generally frown upon.

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.

Oracle APEX - grabbing script output

Does APEX make it possible to call a script using dbms_scheduler, utl_file or other
and grab it's output?
The goal is to pass a command to an external API and show a popup either if an exception is generated or a sucess message is received.
Thanks
Assuming that the script is a file on the database server's operating system, you should be able to invoke the script from APEX using either DBMS_SCHEDULER or via a Java stored procedure. Personally, I'd tend to use the Java stored procedure approach just because that's what I've used in the past but it's solely a matter of personal preference.

Resources