Friday, March 29, 2013

How could you split a field or a column in AWK?

echo "DD-MM-YYYY" | awk '{split($0, TM, "-"); print "Date = "TM[1] "\tMonth = "TM[2] "\tYear = "TM[3]}'

What is the difference between NR and FNR in AWK?

NR - The ordinal number of the current record from the start of input.
FNR - The ordinal number of the current record in the current file.

So NR counts the lines from the very beginning continuously until the end. FNR restarts the counting at the beginning of each input file.

Saturday, March 16, 2013

How could you dereference an anonymous subroutine?

$ref_to_welcome = sub
{
     print "Welcome, @_!";
};

&$ref_to_welcome("Rabindra");
$ref_to_welcome->("Rabindra");

Thursday, March 14, 2013

What is the difference between UNION and UNION ALL?

UNION eliminates duplicate records whereas UNION ALL retains duplicates.

How could you import or export bulk data in SQL Server?

Import/Load data:
bcp itinerary.dbo.tariff in "C:\mobile\itinerary.txt" -N -S <ServerName/IP> -U <userid> -P <password> -T

Export/Extract Data:
bcp itinerary.dbo.tariff out "C:\fruit\inventory.txt" -c -S <ServerName/IP> -U <userid> -P <password> -T -h "TABLOCKX"

What is the maximum number of columns in a row in SQL Server?

1024 columns.

How many columns per SELECT statement are possible in SQL Server?

4096

What are the types of temp tables in Ms SQL Server?

1. Local Temp Table
Table prefixed with a single hash (#) denotes a local temporary table available to the current connection for the user. It disappears when the user disconnects.

CREATE TABLE #tempLocal ( Uid int, Fname varchar(50), Lname varchar(50) )

2. Global Temp Table
Table prefixed with double hash (##) denotes a global temporary table available to all users via all connections. They are deleted only when all connections are closed.

CREATE TABLE ##tempGlobal ( Uid int, Fname varchar(50), Lname varchar(50) )

What is the maximum no. of SPROC nesting in Ms SQL Server?

The maximum level of SPROC nesting is 32.

Which TCP/IP port does Ms SQL Server run on?

Ms SQL Server runs on port 1433.

How could you select top N records in Ms SQL Server?

SELECT TOP N * FROM <TableName>

Or

SELECT TOP N PERCENT <Column_01>, <Column_02>
FROM <TableName>
WHERE <Condition>

Or

( For SQL Server 7.0 or earlier )
SET ROWCOUNT N
SELECT <Column_01>, <Column_02>, <Column_03>
FROM <TableName>
ORDER BY <Column_Name> DESC

What is the difference between ROWNUM and ROWID in Oracle?

ROWID is the unique physical address of every row of a table maintained by database automatically. ROWNUM is the sequential number allocated to each row in the result set object during query execution.

ROWID is permanent whereas ROWNUM is temporary. ROWID is 16-bit hexadecimal whereas ROWNUM is numeric.

How could you embed external image for background in Perl-CGI?

print $cgi->start_html ( -background=>"http://localhost/images/bg.jpg" );

How could you embed external CSS file in Perl-CGI?

print $cgi->start_html ( -style => {'src' => 'http://localhost/styles/bg.css'} );

Full form of some Banks.


ICICI   => Industrial Credit and Investment Corporation of India
HSBC  => Hongkong and Shanghai Banking Corporation
HDFC  => Housing Development Finance Corporation
IDBI     => Industrial Development Bank of India
DENA  => Development Enterprenure National Association
BNP     => Banque Nationale de Paris
UTI      => Unit Trust of India
UCO    => United Commercial Bank
YES     => Youth Enterprise Scheme
EXIM  => Export Import Bank Of India
SIDBI  => Small Industries Development Bank of India
NABARD => National Bank for Agriculture and Rural Development

Tuesday, March 12, 2013

How could you set default value for a variable in UNIX?

Set default values for variables using ":-".

VARIABLE=${1:-DEFAULT_VALUE}

sets VARIABLE with the value of 1st Arg to DEFAULT_VALUE, if 1st arg is not entered.

How could you perform bulk upload & download in DB2?

Utilities available for bulk upload & downoad are:
  1. Export
  2. Import
  3. Load

How could you determine size of file in UNIX?

stat -c %s <FileName>  # Size in bytes

How could you estimate the elapsed time for execution of a script in Perl?

#!/usr/bin/perl
use Time::HiRes;

my $start = Time::HiRes::gettimeofday();
## -- Your Code -- ##
my $end = Time::HiRes::gettimeofday();

printf("$0 took %.4f seconds!\n", $end - $start);

Monday, March 11, 2013

How could you force all users off the specified instance or database in DB2?

Use 'QUIESCE' command which doesn't allow all users ( except SYSADM, SYSMAINT, DBADM, or SYSCTRL ) to connect to the database until the 'UNQUIESCE' command is given.

For example:

-- Forces off all users with connections to an instance
quiesce instance <Instance_Name> immediate force connections

-- Forces off all users with connections to the database
quiesce database <Database_Name> immediate force connections

How could you connect Oracle and Python?


#!/usr/bin/python

import os
import cx_Oracle

SQL_STMT="SELECT * FROM TABLE_NAME"

# set Oracle Environment variables in case it has not been
os.putenv('ORACLE_HOME', '/oracle/product/10.2.0/db_1')
os.putenv('LD_LIBRARY_PATH', '/oracle/product/10.2.0/db_1/lib')

connection = cx_Oracle.connect('userid/password@127.0.0.1:1521/SID')

cursor = connection.cursor()
cursor.execute(SQL_STMT)
for row in cursor:
    print row

cursor.close()
connection.close()

How could you swap values of variables in Python?


#!/usr/bin/python
   
a = 5
b = 6

print "Before Swapping : a =", a , "b =", b
a, b = b, a
print "After Swapping : a =", a , "b =", b

Friday, March 8, 2013

How could you check the existence of a function (say new) within a package (say CGI) in Perl?

use CGI;

$cgi=CGI->new;

if (exists &CGI::new)
{
    print "Exists\n";
}

Or

if ( defined( &CGI::new ) )
{
print "Defined\n";
}

Or

if ( CGI->can('new') )
{
print "Exists\n";
}

Or

if ( $cgi->can('new') )
{
print "Defined\n";
}

How could you list out all the variables defined in a package in Perl?

use CGI;

no strict 'refs';

foreach ( keys %CGI:: )
{
print "$_\n";
}

How could you list all the methods defined in the package (say CGI) in Perl?

use CGI;

no strict 'refs';
print join ', ', grep { defined &{ "CGI::$_" } } keys %{ CGI:: };

When is “use lib” implemented in Perl?

use lib’ is used in two cases:
  • When you have a fixed, but not standard company-wide environment in which you put modules in a common standard location.
  • When you are developing an application and you'd like to make sure the script always picks up the modules relative to their own location.

Thursday, March 7, 2013

Wednesday, March 6, 2013

Tuesday, March 5, 2013

How could you execute command stored in a string or variable in Shell Scripting?

#!/bin/bash

CMD="ls -lrt"
eval $CMD

How could you run commands/scripts when you log out session in UNIX?

Run commands/scripts when you log out by appending required lines to the ".logout" file in your HOME directory.

sh shell : ~/.sh_logout
bash shell : ~/.bash_logout
ksh shell : ~/.ksh_logout
tcsh / csh : ~/.logout

Next add the below line to your ".profile" file :
trap '. $HOME/.sh_logout; exit' 0

Saturday, March 2, 2013

How could you generate a sequence of numbers in Shell Scripting?

#!/bin/bash

for (( count=1; count <= 3 ; count++ ))
do
 echo "Value of count = $count."
done

# Or

#!/bin/bash

for count in $(seq 4 7)
do
 echo "Value of count = $count."
done

# Or

#!/bin/bash

for count in {7..10}; do
 echo "Value of count = $count."
done