We have moved to www.dataGenX.net, Keep Learning with us.

Sunday, January 15, 2012

bc command : tips & tricks

bc stands for bench calculator
Here are some examples of bc command :

a) addition
$ echo '57+43' | bc 100

b) subtraction
$ echo '57-43' | bc 14

c) multiplication
$ echo '57*43' | bc 2451


scale
The scale variable determines the number of digits which follow the decimal point in your result. By default, the value of the scale variable is zero.

d) division
$ echo 'scale=25;57/43' | bc 1.3255813953488372093023255

Friday, January 13, 2012

Export , Import & Load utility in DB2 : Part - 3

LOAD Operation :: The LOAD utility write pages of data directly to the database instead of using SQL statements & does not record changes in any log files. This means that LOAD operation is faster than IMPORT transaction. However if LOAD transaction failes , the data cant be reloaded by performing a roll- forward recovery operation. To compensate for this , we have to create a backup copy of all data that is loaded so that it can be reloaded if necessary.

Syntax ::
LOAD <CLIENT> FROM [Filename of [DEL | ASC | IXF] | Pipename | Device| CursorName of Cursor , ...]
<LOBS FROM [LOBpath , ..]>
<MODIFIED BY [Modifier , ..]>
<Method>
<SAVECOUNT [SaveCount]>
<ROWCOUNT [RowCount]>
<WARNINGCOUNT [WarningCount]>


eg:
(i) LOAD from Cust.ixf of ixf messages load_msgs.txt insert into customers 







Export , Import & Load utility in DB2 : Part -2

IMPORT UTILITY :  To  import data into database

IMPORT from [filename] of [asc|del|wsf|ixf]
<lobs from [lobpath,...]>
<modified by [modifier,..]>
<method>
<commitcount[CommitCount]>
<restartcount[RestartCount]>
<messages[MsgFileName]>
[CRETAE | INSERT | INSERT_UPDATE | UPDATE|REPLCAE]
INTO [TABLENAME] <([ColumnName,....])>
IN [TSNAME] <INDEX IN [TSNAME]> <LONG IN [TSNAME]>>


CREATE :-  if this option is used , table is first created in the database before any data is imported. This option can only be used with IXF files.
INSERT:-  new data is added to the table without altering any of the existing data
INSERT_UPDATE:- new data is either added to the table or existing records are updated
REPLACE :- All existing data is deleted from the table before the new data is added.The table needs to be exist already
REPLACE_CREATE :- the table is first created if it does not already exist. Otherwise existing data is deleted from the table before new data is added.This option can only be used with IXF files. Also this option cant be used if the target table is a parent table that is referenced by foreign key.

eg: (i) import from cust.ixf of ixf insert into customers
(ii) import from cust.ixf of ixf lobs from c:\lobs modified by lobsinfile replace into customers
(iii)The following example shows how to import the table MOVIETABLE from the input file delfile1, which has data in the DEL format:

db2 import from delfile1 of del
modified by dldel|
insert into movietable (actorname,description,url_making_of,
url_movie) datalink specification (dl_url_default_prefix
"http://narang"), (dl_url_replace_prefix "http://bomdel"
dl_url_suffix ".mpeg")


Notes:

  1.  The table has four columns:

       actorname              VARCHAR(n)
       description            VARCHAR(m)
       url_making_of          DATALINK (with LINKTYPE URL)
       url_movie              DATALINK (with LINKTYPE URL)

 2.   The DATALINK data in the input file has the vertical bar (|) character as the sub-field delimiter.
 3.   If any column value for url_making_of does not have the prefix character sequence, "http://narang" is used.
 4.   Each non-NULL column value for url_movie will get "http://bomdel" as its prefix. Existing values are replaced.
 5.   Each non-NULL column value for url_movie will get ".mpeg" appended to the path. For example, if a column value of url_movie is "http://server1/x/y/z", it will be stored as "http://bomdel/x/y/z.mpeg"; if the value is "/x/y/z", it will be stored as "http://bomdel/x/y/z.mpeg".




Export , Import & Load utility in DB2 : Part -1

Types of External file formats 

Db2 Supports 4 different types of External Files ::
-->Delimited ASCII(DEL)
-->NON Delimited ASCII
-->PC Integrated Exchange Format(IXF) {**Binary Format**}
-->Worksheet Format(WSF) {for exporting a table to Lotus 1-2-3 & Symphony Spreadsheet)

Storing data in External Files ::(3 methods )
1)Name Method : its is used when you export data from DB2 UDB database.its is used when exporting data between DB2 product in IXF format oir when you export data to Lotus products in WSF format.Similarly its used when importing data from Db2 & Lotus products to Db2

2)Location Method : Used with Non Delimited ASC files. Db2 wont support exporting data in this format. So you can only use when importing data.

3)Position method : Its used when importing or exporting files in IXF or DEL format.You an use this method when transferring data between DB2 products in IXF. ALSo you can use it for transferring data between DB2 UDB & other databases that reqire DEL format.

EXPORT UTILITY :: It enables you to Extract data form tables & views in Db2 database in format that can be used by other databse or applications.The files formats are , DEL , IXF, WSF.
==>To use Export Utility u should have SYSADM or DBADM authority or CONTROL or SELECT priveleges on each relevant table

syntax-->>
Export to [filename] of [del|wsf|ixf]
<LOBS TO [LOBPath,...]>
<MODIFIED BY [Modifier , ...]>
<METHOD N ([ColumnName, ...])>
<MESSAGES[MsgFileName]>
[SELECT statement ]


for Eg::
(i) db2 export to myfile.ixf of ixf messages msgs.txt select * from staff     {The following example shows how to export information from the STAFF table in the SAMPLE database to the file myfile.ixf. The output will be in IXF format.}

(ii) db2 export to awards.ixf of ixf messages msgs.txt select * from staff where dept = 20    {The following example shows how to export the information about employees in Department 20 from the STAFF table in the SAMPLE database. The output will be in IXF format and will go into the awards.ixf file.}

(iii)db2 export to myfile.del of del lobs to mylobs/lobfile lobs1, lobs2 modified by lobsinfile select * from emp_photo {The following example shows how to export LOBs to a DEL file: }

(iv) export to products.txt of del select * from products

(v) export to products.txt of del lobs to C:\lobs modified by lobsinfile select * from products


The Unix Time Command : tips & tricks


If you have a program ./prog.e then in the bash/ksh shell you can type this command and the output on the screen details how long the code took to run:
     
$ time ./prog.e
real   24m10.951s user    6m2.390s sys     0m15.705s



Real time - Elapsed time from beginning to end of program (or wall clock time).The real time is the total  time of execution.
CPU time - Divided into User time and System time.
User time - time used by the program itself and any library subroutines it calls.The user time is the time spent processing at the user/application process level.
System time - time used by the system calls invoked by the program (directly or indirectly).The sys time is the time spent by the system at the system/kernel level.

If the wall clock time is consistently much longer than the total of the system and user time, then the fetching of data to and from hard drives may be taking a good deal of time. In parallel codes, the code may be spending a good deal of time waiting on communication between processors.

By this command you can check your script performance.

happy scripting :-)

Tuesday, January 10, 2012

Script/Code Header

Hi Guys, I am sharing a Script Header or we can say a Code Header
which we can use in our code to provide more proper description of the code.


Please find the link.  download