Skip to main content

sqlplus used in perl

sqlplus is a command line tool used to work with an Oracle database.

#!/bin/perl
my $sqlString ='sqlplus -s user/pass@SID << END
set heading off
set echo off
set feedback off
set pagesize 0';

$sqlString = "$sqlString\nSELECT 'test' FROM dual;";

my $result; = `$sqlString`;

print $result;
usage: sqlplus [-s] user/pass@SID
-s parameter enables a silent mode. Only result of statement executions will be returned to a standard output (data like 'SQL>' prompt or a connection confirmation will be skipped)

To disable a default human-redable format of returned data the following parameters are set: heading, echo, feedback, pagesize.

Comments

Popular posts from this blog

ShutDownHook - the last breath of an application

ShutDownHook allows you to perform operations (e.g. close opened resources, remove temporary files and so on) just before virtual machine shuts down. A documentation says that JVM may shut down in two cases: program finishes execution normally when all threads finishes their work (except deamon-threads like garbage collector) virtual machine receives a termination signal (for example after sending kill signal under unix or ctrl + C key combination under windows) Below is an example which will start endless loop which do nothing. But an important thing in this code is a part where shutDownHook is added. When an termination signal will be send to JVM a code from a run() method will be executed just before JVM shuts down. public class ShutDownHook { public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("Close opened resources"); } }); while (true) { // do nothing } } }

scala Hello World

The code below prints Hello World! Hello.scala file (a name of file doesn't matter) object HelloWorld { def main(args: Array[String]) { println("Hello World!") } } Key word object is used to create a singleton object. To run this script use scala interpretor (check scala command line tools ).