Oracle sql or pl/sql command for checking if remote database is available i.e. similar to OS command tnsping - oracle

In my PL/SQL script, I have requirement to test the connectivity of remote data. Normally, in OS shell, we use command tnsping. Is there any command in SQL or PL/SQL so that I can test connectivity.
Basically, I am getting some data using database link. I want my script to execute immediately. If remote database is available then I want to run query using database link. If remote database is unavailable then I want to skip the getting of data using database link. So, this is the reason why I am looking for.
Kindly guide me for proper way. So, that my script does not hang in case of unavailability of remote database.
I am using Oracle 12.1C.

Related

PL/SQL is executed by Oracle Database not the host system

I have just started with Basics of PL/SQL and encountered with this statement and I am unable to get this .Please guide .
If I understood what you are saying, then: PL/SQL is executed within the database which is installed on the database server.
Although you can "save" your PL/SQL code into a script which resides on your hard disk (local PC), there's no use of it - it has to be "stored" in the database. That's why we call those procedures "stored procedures". True - there are anonymous PL/SQL blocks, but they also run in the database.
Opposed to those are .SQL scripts, files you can store to your hard disk and execute them "locally" by e.g. connecting to the database via SQL*Plus, a command line tool, and call those locally stored files (if that's what you call "host system").

Running Unix commands from Oracle apex application

Is it possible to run commands on another Unix server from an Oracle apex application ?
Oracle apex and Unix are on different machines .
Apex is just a layer on top of the database.
From within the oracle database you can execute OS commands, so you could execute a script that connects from your database server over ssh.
or you could wrap your unix command in a cgi script and have it run of http. In pl/sql you could then invoke it via apex_web_service.make_rest_request
Make sure you check security
No you cannot. If your requirement is just to transfer the files, you can use ftp or sftp commands. But to perform unix operations, you cannot run in different machines

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.

Oracle Data Pump expdp to local computer that does not have oracle installed

Hi I've been reading this instruction:
http://www.oracle-base.com/articles/10g/oracle-data-pump-10g.php#NetworkExportsImports
From my understanding, I need to login my local oracle database, establish a database link to the remote oracle server, then use expdp to export database to local.
But now I only have sqlplus installed in local computer, how can I expdp to local?
Thank you very much.
You can't. expdp only works locally. The database link is just a kludge to make the Oracle instance on your current machine be able to see the data in the other database. If you truly need a remote back up, your only non-custom or third party option would be exp, but that's deprecated. (I'm not aware of any third party solutions, either.)
Another option to consider is running the command on the remote server and then using something else to copy the file. This is more feasible if you run a Linux server, since you can likely use SSH and SFTP.
You could try Oracle Express on your local machine if you want to pursue the database link option. That is a very heavy solution, of course.
(In all honesty, I have had endless troubles with expdp anyway. Well, more with impdp, but still. The data dump/restore situation in Oracle is not very good, in my opinion.)

Run commandline command at remote Oracle server using SQL*Plus

I have a machine running Oracle 10g server in windows server 2008. I want to take backup of the database. I also want to take backup of some files saved on hard disk by oracle server that users have uploaded using my website.
I can connect to the Oracle server using sql developer and sqlplus. I can run sql queries on the server.
In order to take backup of database I have to run the command "exp" (this is the only way of taking backup of databases that I know). There might be some other way but there is another problem because of which I must run dos command. That problem is to take backup of files. These files are stored in c:\mydir. The folder mydir is not accessible anyway through web and is not a shared folder.
I have tried running "host " in sqlplus after connecting to oracle server, that is at "sql>" prompt. The command ran successfuly but at local machine, not at oracle server.
Edit: The "host" command is provided by sqlplus and is not an oracle command, means cannot be used in a query. Sqlplus even when connected to remote machine run the "host" command at local machine.
The target is to either make sqlplus run the "host" command at remote machine, Or run the dos command from inside a pl/sql query (independent of sqlplus).
In addition to what Justin has written:
If you want to take a logical snapshot of the database the new DataPump tool is preferred over the old (and deprecated) exp tool.
DataPump is a commandline tool (expdp) but also has a SQL API through Oracle packages and procedures.
The Data Pump API (including examples)
DBMS_DATAPUMP (reference)
But if you want a "real" backup you should look into RMAN
It is possible to create a Java stored procedure on the database server that executes an operating system command on the Oracle server. But it would be extremely unusual to use the export utility to backup a database-- that only creates a logical backup not a more appropriate physical backup. And it would be extremely unusual to run a backup by connecting to the database via SQL*Plus and spawning a job on the server operating system. It would make much more sense to create a job using the Windows scheduler on the database server that ran whatever export commands you want to run.

Resources