sql function : NVL can be used to provide a default value when a field is null.
if salary = Null
then salary = 0
else
salary = emp_salary from emp_table
end if
This can be reduced to
select nvl(emp_salary,0) from emp_table;
---------------------------------------------------------------------------
sql function : DECODE can be used instead of a nested if condition or a case statement.
DECODE(expression or column,if_value,then_return_this_value,[ if_value,then_return_this_value,...],default_return_value)
e.g.
Following sql will assign state codes for Washington or Ohio and default to Florida if the state is neither of the two.
select emp_id, decode(emp_state,'Washington','WA','Ohio','OH','FL')
from emp_table;
Following sql will assign tax percentage as 30 if salary >=60000 else 20.
select emp_id, decode(emp_tax_pct,emp_salary >= 60000,30,20)
from emp_table;
Thursday, May 14, 2009
Monday, May 11, 2009
awk world
awk executes the instructions for each line of input
$ cat testfile
1
2
3
4
$ awk '{print $1}' testfile
1
2
3
4
$ awk '{print "Hello, World"}' testfile
Hello, World
Hello, World
Hello, World
Hello, World
awk will wait for the input file name and will consider 'ENTER or RETURN' as valid input.
prefixing BEGIN keyword to any script lets awk execute the instructions without waiting for input file.
$ awk 'BEGIN {print "Hello, World"}' <== No input file
Hello, World
This instruction would be executed only once at the beginining.
$ awk 'BEGIN {print "Hello, World"}' testfile
Hello, World
$ awk 'BEGIN {print "Hello, World"} {print $1}' testfile
Hello, World
1
2
3
4
END keyword can be used to add a closing instruction.
$ awk 'BEGIN {print "Hello, World"} {print $1} END {print "Good bye"} ' testfile
Hello, World
1
2
3
4
Good bye
#
$ cat testfile
1
2
3
4
$ awk '{print $1}' testfile
1
2
3
4
$ awk '{print "Hello, World"}' testfile
Hello, World
Hello, World
Hello, World
Hello, World
awk will wait for the input file name and will consider 'ENTER or RETURN' as valid input.
prefixing BEGIN keyword to any script lets awk execute the instructions without waiting for input file.
$ awk 'BEGIN {print "Hello, World"}' <== No input file
Hello, World
This instruction would be executed only once at the beginining.
$ awk 'BEGIN {print "Hello, World"}' testfile
Hello, World
$ awk 'BEGIN {print "Hello, World"} {print $1}' testfile
Hello, World
1
2
3
4
END keyword can be used to add a closing instruction.
$ awk 'BEGIN {print "Hello, World"} {print $1} END {print "Good bye"} ' testfile
Hello, World
1
2
3
4
Good bye
#
Friday, May 8, 2009
Wednesday, May 6, 2009
Available packages/ ports on MacPorts :
http://www.macports.org/ports.php?by=category&substr=archivers
To install a package using MacPorts :
sudo port install <package name>
sudo port uninstall <package name>
http://www.macports.org/ports.php?by=category&substr=archivers
To install a package using MacPorts :
sudo port install <package name>
sudo port uninstall <package name>
Caret M or ^M creeps into files imported to unix from windows/dos. It is a bad line break or carriage return. It can be seen in vim.
Caret M is a single character that can be created by pressing control+v and control+m. Writing Shift+6M would not work.
To remove caret M from the files give "%s/^M//g" on vi in escape mode.
Caret M is a single character that can be created by pressing control+v and control+m. Writing Shift+6M would not work.
To remove caret M from the files give "%s/^M//g" on vi in escape mode.
IE6 bugs - float:left and png transparency
My html code in IE6 was not working right while Firefox worked fine. There were two issues -
png files were not displayed with transparent background instead a solid color.
Fixed it by adding javascript code in head. Credit to tech_support @ http://www.dynamicdrive.com/forums/showthread.php?t=22176
float:left with the image was not working. The image continued to be above the text rather than on left of it.
Fixed it by
1. Using "display:inline" with the text; and
2. Setting height for the div since the same image on Firefox slopped after doing #1.
#
Friday, May 1, 2009
while editing a file in vim, to do any of the following, get into vim command mode.
1. invoke shell using :sh. Return to vim using exit in shell.
2. see output of a vim command using :!cmd
3. insert the output of a vim command using :!rcmd
this last command is highly useful if we have to insert data from a different file into the current. it saves copy/paste efforts.
1. invoke shell using :sh. Return to vim using exit in shell.
2. see output of a vim command using :!cmd
3. insert the output of a vim command using :!rcmd
this last command is highly useful if we have to insert data from a different file into the current. it saves copy/paste efforts.
Subscribe to:
Posts (Atom)