Running Unix commands from Oracle apex application - oracle

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

Related

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

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.

Execute a .sql File from cmd to IBM server (db2)

I'm trying to import a .sql file into IBM db2 Server using cmd
Here is my cmd line prompt that I'm using
cmd /c db2 -u<USER> -h<HOST> -p<PASSWORD> -D<DATABASE> <<My File Repository>/<FileName>.sql
Is this cmd prompt correct or not?
Available to give more informations
This question is frequently asked, so do your research.
With cmd.exe on MS-Windows, you cannot use such syntax, because the Db2 clp does not accept arguments like -u ... -h... -p... -D....
Instead there are other ways to achieve what you need.
If the Db2-database is on the same hostname as your clp (i.e. is is a local database), then you can use db2 connect to DATABASENAME and then use db2 -tvf filename.sql. When the database is remote (on a different hostname from your clp), you must supply a userid/password (or certificate, or token, depending on Server configuration)and the remote database has to be pre-catalogued locally (either via XML file or via catalog commands). With local databases you do not need to specify either a userid or a password, it will connect as the currently logged in operating-system user.
If you prefer to use a connection-string, you can rework your scripts to be compatible with the CLPplus program which is a java app that accepts arguments on its command line. For people who are familiar with Oracle SQL*Plus, this is often their go-to tool when using Db2.
If you really want to use cmd.exe with the Db2 clp to run SQL scripts (for both local and remote databases) , then you can do it if you are prepared to first perform some basic configuration steps. You have a choice of old style catlog configuration steps, or XML file.
The old style actions are: catalog tcpip node, then catalog database on that node, then db2 termainate and finally connect to the remote catalogued database with db2 connect to $database user XXXX using YYYY and db2 -tvf filename.sql. You can also have the connect statement inside the SQL script. All of these actions are well documented in the Db2 Knowledge Center online, so do your research.
If you do not wish to perform the catalog actions, you can also have a pre-prepared XML file (called db2dsdriver.cfg) which contains all of the connection details for all Data-Source-Names and databases you use. You can either create the XML file manually, or programatically with the db2cli tool and its command line. The IBM supplied CLI drivers for Db2 read and interpret that file at runtime. This lets you connect to local and remote DSNs without the need to use explicit catalog actions because the XML file has all the details. The CLP will then let you run scripts against those DSNs. This file is documented in the Db2 Knowledge Centre, and can be located (by defailt) in the CLI driver cfg directory, or anywhere via the environment variable DB2DSDRIVER_CFG_PATH. Refer to the documentation for all details.
If your remote database runs on Db2-for-i, or Db2-for-z/os then different considerations apply. First IBM supplied CLI drivers both require a license before the connect will succeed. Refer to documentation. Second, for Db2-for i (as/400), you should only consider using the separate IBM product for IBM i series access and its odbc option.
If your remote Db2-database is on Linux/Unix/Windows/zLinux/cloud then you do not need any license locally.

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.

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.

Invoke oracle stored procedure from shell script without SQLPLUS

Can anyone please suggest a way to invoke an Oracle stored procedure from a shell script without the use of SQL*Plus, or any such client for that matter. The inability to install clients is a limitation of the server that I work on.
I have to schedule an Autosys script to invoke the job which invokes the Oracle stored procedure. Can you please suggest in what direction should I proceed?
You could do this using Java and jdbc. If you can not even copy the thin jdbc driver, I see no other option than to schedule the job in Oracle Using Oracle Scheduler.
Without client software installed, you'll have a hard time getting to Oracle from a shell script; however, Oracle has it's own batch facility--see Database jobs here

Resources