me,myself,english and programming..

Archive for the ‘Database’ Category

AutoIt – Connecting to oracle without TNS Names

Monday, March 2nd, 2009

In my previous post, I’m showing the way how to connect to oracle database using AutoIt. If you see the connect string, you will find it is very simple since we already define the entry ORCL in tnsname.ora file.

$DSN = "Driver={Microsoft ODBC for Oracle};Server=ORCL;Uid=myID;Pwd=myPwd;"

If for a some reason, you need to connect to oracle database without doing an entry in tnsname.ora file, below is the way how to do it.

$DSN =   "Driver={Microsoft ODBC for Oracle}; " & _
         "CONNECTSTRING=(DESCRIPTION=" & _
         "(ADDRESS=(PROTOCOL=TCP)" & _
         "(HOST=192.168.1.6)(PORT=1521))" & _
         "(CONNECT_DATA=(SERVICE_NAME=orcl))); uid=myID;pwd=myPWD;"

That’s all.

 

Happy coding !!

p/s: Time is running so fast. do you think so ??

AutoIT – Connecting to Oracle.

Wednesday, February 18th, 2009

Previously I wrote about how to connect to SQL Server using AutoIt. Since that I’m using Oracle as my main database in my new workplace, I will show how to do the same thing for Oracle.

$conn = ObjCreate( "ADODB.Connection" )
$DSN = "Driver={Microsoft ODBC for Oracle};Server=ORCL;Uid=myID;Pwd=myPwd;"
$conn.Open($DSN)
$rs = ObjCreate( "ADODB.RecordSet" )
$rs.Open( "select BANNER from v$version where banner like 'Oracle%'", $conn )
MsgBox(0, "AutoIT-SQL Result", "Value = " & $rs.Fields( "BANNER" ).Value )
$conn.close

The codes will produce something like below.

autoit-oracle

 

Till then..

Happy coding..!

Generate DROP TABLE Statement in ORACLE.

Monday, February 16th, 2009

I’ve come to this site while gooling around for generating drop tables statement in Oracle. Thanks.

As for my future reference, I will write those SQL statement in my post.

select 'drop table '||table_name||' CASCADE CONSTRAINTS;' from USER_TABLES where table_name like '%_XXX%'

Happy SQL-ing !

p/s: Is there anyone know about replication in oracle ?? it gives me headache !! grrrrrr

MSSQL – Useful query for my reference

Friday, November 7th, 2008

This will me my reference of SQL statement. I will update this post if I find anything that I feel useful for me..and for you. :)

1. Check for temporary table and Drop table if exist.

IF object_id('tempdb..#myTempTable') IS NOT NULL drop table #myTempTable

2. Convert SQL string to HEX

select CONVERT(varbinary(100),'select getdate() as MyDateInHex')

(more…)

Download Malaysia Postcode

Thursday, October 30th, 2008

While everyone is talking about fatwa on yoga , I’m here to share Malaysia postcode that I use to do some of my analysis work. (which I also get it from someone else. :) )

You will be expecting the file to be in this CSV format.

postcode csv

This is the only postcode list I have. If you are expecting postcode to be tag by City, I’m sorry for that. I don’t have any. If you do have it, kindly share it with me :)

(more…)