I recently needed to find out the schema names of certain Oracle tables that belonged to schemas other than the connecting user. This is because the four-part queries in SQL Server require the schema/owner name of the tables referenced. This query (run in SQL*Plus) lists the owners and names of all tables that can be seen by the connecting user:
SELECT OWNER, TABLE_NAME FROM ALL_TABLES;
A full reference for the ALL_TABLES view can be found here.
Thursday, June 14, 2007
Friday, June 1, 2007
Casting to NUMERIC/DECIMAL with E notation
Found this neat tidbit on some other guy's blog. Basically, NUMERICs/DECIMALs are exact numeric types and cannot contain the E notation in their representations. FLOATs are approximate numeric types and can contain the E notation. FLOATs can also be CASTed to NUMERIC/DECIMAL with no problems (other than a loss of precision).
For example, take the VARCHAR value X = '10000000E-2'. To cast it to NUMERIC/DECIMAL, use the following:
SELECT CAST(CAST(X AS FLOAT) AS NUMERIC(15, 4))...
You would obviously lose some precision if you cast with a NUMERIC field of less precision than what is represented by the contents of the VARCHAR value.
For example, take the VARCHAR value X = '10000000E-2'. To cast it to NUMERIC/DECIMAL, use the following:
SELECT CAST(CAST(X AS FLOAT) AS NUMERIC(15, 4))...
You would obviously lose some precision if you cast with a NUMERIC field of less precision than what is represented by the contents of the VARCHAR value.
Truncate the last n bytes of a file
Use FileStream.SetLength():
Dim strFile As String = "C:\Path\To\File.txt"
Dim fi As New FileInfo(strFile)
Dim fs As New FileStream(strFile, FileMode.Open, FileAccess.Write)
fs.SetLength(fi.Length - n)
fs.Flush()
fs.Close()
Dim strFile As String = "C:\Path\To\File.txt"
Dim fi As New FileInfo(strFile)
Dim fs As New FileStream(strFile, FileMode.Open, FileAccess.Write)
fs.SetLength(fi.Length - n)
fs.Flush()
fs.Close()
Thursday, May 24, 2007
Opening a Windows Explorer window in VB.NET
Use Process.Start:
Dim ps As New ProcessStartInfo("explorer")
ps.Arguments = "C:\Directory\to\open"
Process.Start(ps)
Dim ps As New ProcessStartInfo("explorer")
ps.Arguments = "C:\Directory\to\open"
Process.Start(ps)
Friday, May 18, 2007
.NET Regular Expression Escape Characters
\w - matches any word character
\W - matches any non-word character
\s - matches any whitespace character
\S - matches any non-whitespace character
\n - newline
\f - formfeed
\r - carriage return
\t - tab
\v - vertical tab
\0x0020 - space
\d - digit
^ - beginning of string
$ - end of string
\W - matches any non-word character
\s - matches any whitespace character
\S - matches any non-whitespace character
\n - newline
\f - formfeed
\r - carriage return
\t - tab
\v - vertical tab
\0x0020 - space
\d - digit
^ - beginning of string
$ - end of string
Tuesday, February 13, 2007
Filling in gaps in incrementing INT column in SQL Server
Suppose you have a unique integer column i in a table T. i may contain gaps. i contains m rows.
Suppose you wish to insert n values into i starting at some value x0 and incrementing. Let x equal the first integer greater than or equal to x0 not found in i.
In general, this can be solved by performing the following:
SELECT TOP n * 2 IDENTITY(INT, x, 1) AS j
INTO #temp
FROM T T1
CROSS JOIN T T2
GO
INSERT INTO T (i)
SELECT TOP n j
FROM #temp
LEFT OUTER JOIN T
ON T.i = #temp.j
WHERE T.i IS NULL
GO
There should now be m + n rows in T.
Suppose you wish to insert n values into i starting at some value x0 and incrementing. Let x equal the first integer greater than or equal to x0 not found in i.
In general, this can be solved by performing the following:
SELECT TOP n * 2 IDENTITY(INT, x, 1) AS j
INTO #temp
FROM T T1
CROSS JOIN T T2
GO
INSERT INTO T (i)
SELECT TOP n j
FROM #temp
LEFT OUTER JOIN T
ON T.i = #temp.j
WHERE T.i IS NULL
GO
There should now be m + n rows in T.
Thursday, January 25, 2007
Getting System Icons into a PictureBox control
A simple solution for getting system icons into a PictureBox control at runtime is to set the PictureBox's Image property to SystemIcons.xxxxxx.ToBitmap().
Subscribe to:
Posts (Atom)