Archive for the ‘Batch Script’ Category

Execute SQLLdr without tnsnames.ora entry

February 1, 2012

In my last post, I discovered that we can run sqlplus without having an entry in tnsnames. I was under the impression that it will work the same way in sqlldr also. But it was a mistake as sqlldr told me I am giving it the wrong syntax. I spend lots of time on that to find out finally that, I need to escape the brackets and need to put a double quotes which itself should be escaped around the connection string. So it goes like this :

sqlldr username/pwd@\”\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=TCP\)\(HOST=yourhost.domain\)\(PORT=1521\)\)\(CONNECT_DATA=\(SERVER=DEDICATED\)\(SID=yourservice\)\)\)\” control=control_file.ctl errors=1000 ROWS=50000

That’s it guys. Happy Coding. 🙂

How to connect SQLPlus without tnsnames.ora entry

January 31, 2012

In some weird companies, like the one am working, will restrict many things in our machine which will reduce the productivity. Recently I was trying to add a new entry in tnsnames when our database server got changed. And hell, I was not having rights to change the tnsnames file in my local machine!!! WTF!!! At the end of day I need to run one sqlplus command from the command prompt. SQLPlus needs an entry in the TNS Names file in order to work. Then I found out an way to execute the command by directly giving the connection string in the sqlplus command itself. Like this :

sqlplus username/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost.mydomain)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=servicename)))

BINGO! It works as hell. Please remember that there shouldn’t be any space in the connection string, also no carriage return (which might happen if you are copying the string from the tnsnames file.

Thats it guys. Happy Coding. 🙂

Echo Current Date and Time in Batch File

January 24, 2012

How stupid I am! In one batch file I need to print the current date and time and I googled for 5 mins to find it out. 😛 So here it is. For the other guys like me. he he.

ECHO Starting stored procedures execution at %date% – %time% >> log_file.log

Happy Coding. 🙂

Unix Tail command in DOS Batch

December 20, 2010

I was struggling the last days for converting my applications from UNIX servers to Windows servers. The main difficulty I faced was the conversion of the shell scripts to DOS Batch scripts. Since I was not that expert in UNIX Shell commands, it was a challenge for me. I will keep on posting the different conversions I did. This is the first one.

The tail command in UNIX will take the last specified number of lines from the input given. The below line of command will take last 20 lines from del_temp.log and put into value.log.

tail -20 del_temp.log >> value.log

This single line tail command can be converted to its equivalent DOS Batch by the below block of code.

SETlocal EnableExtensions
SET tailCount=20
SET fileName=del_temp.log
SET output=value.log
FOR /F “usebackq tokens=3,3 delims= ” %%l IN (`find /c /v “” %fileName%`) DO (call SET find_lc=%%l)
SET /a linenumber = %find_lc% – %tailCount%
IF %linenumber% LSS 1 (
more +0 %fileName% >> %output%
) ELSE (
more +%linenumber% %fileName% >> %output%
)
endLocal

Enjoy and Happy Coding Guys 🙂


%d bloggers like this: