Талбаруудын өгөгдлийн төрлийг харах.
Select the column datatype using case when, concat function.
SELECT column_name,
CASE
WHEN data_type = 'DATE' then data_type
WHEN data_type = 'NUMBER' then concat( concat( concat( data_type, '(' ), concat( data_precision, case when data_scale > 0 then concat( ',', data_scale) end ) ), ')' )
WHEN data_type = 'NVARCHAR2' then concat( concat( concat( data_type, '(' ), char_length), ')' )
WHEN data_type = 'VARCHAR2' then concat( concat( concat( data_type, '(' ), concat( char_length, case char_used when 'B' then ' BYTE' end ) ), ')' )
END data_type
FROM user_tab_columns
WHERE table_name='table_name' AND (
column_name = 'columnname1' OR
column_name = 'columnname2' OR
column_name = 'columnname3'
) order by column_name;
Output:
COLUMN_NAME DATA_TYPE
columnname1 NUMBER(4)
columnname2 VARCHAR2(15 BYTE)
columnname3 DATE
Google adsense
Search
Tuesday, September 7, 2010
Oracle: Concat Function
In Oracle/PLSQL, the concat function allows you to concatenate two strings together.
The syntax for the concat function is:
concat( string1, string2 )
Хоёр текстийг хооронд нь холбоно.
The syntax for the concat function is:
concat( string1, string2 )
string1 is the first string to concatenate.
string2 is the second string to concatenate.
Applies To:
• Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
For example:
concat('Tech on', ' the Net'); would return 'Tech on the Net'.
concat('a', 'b') would return 'ab'.
Thanks,
Info source: http://www.techonthenet.com/oracle/functions/concat.php
string2 is the second string to concatenate.
Applies To:
• Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
For example:
concat('Tech on', ' the Net'); would return 'Tech on the Net'.
concat('a', 'b') would return 'ab'.
Thanks,
Info source: http://www.techonthenet.com/oracle/functions/concat.php
Oracle: Case when
case when x = y then a else b end
case when x < y then a when x = y then b else c end
case XYZ when 'foo' then 'moo' else 'bar' end
select a,
case
when b = '*' then 'star'
when b = '+' then 'plus'
when b = '-' then 'minus'
else '????'
end
from table_test_case_when;
Thanks,
Info source: http://www.adp-gmbh.ch/ora/sql/case_when.html
Monday, September 6, 2010
Oracle: Alter table
The ALTER TABLE statement allows you to rename an existing table. It can also be used to add, modify, or drop a column from an existing table.
Renaming a table
The basic syntax for renaming a table is:
ALTER TABLE table_name
RENAME TO new_table_name;
Adding column(s) to a table
Syntax #1
To add a column to an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
ADD column_name column-definition;
Syntax #2
To add multiple columns to an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
ADD ( column_1 column-definition,
column_2 column-definition,
...
column_n column_definition );
Modifying column(s) in a table
Syntax #1
To modify a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
MODIFY column_name column_type;
Syntax #2
To modify multiple columns in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
MODIFY ( column_1 column_type,
column_2 column_type,
...
column_n column_type );
Drop column(s) in a table
Syntax #1
To drop a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
DROP COLUMN column_name;
Rename column(s) in a table
(NEW in Oracle 9i Release 2)
Syntax #1
Starting in Oracle 9i Release 2, you can now rename a column.
To rename a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
RENAME COLUMN old_name to new_name;
Renaming a table
The basic syntax for renaming a table is:
ALTER TABLE table_name
RENAME TO new_table_name;
Adding column(s) to a table
Syntax #1
To add a column to an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
ADD column_name column-definition;
Syntax #2
To add multiple columns to an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
ADD ( column_1 column-definition,
column_2 column-definition,
...
column_n column_definition );
Modifying column(s) in a table
Syntax #1
To modify a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
MODIFY column_name column_type;
Syntax #2
To modify multiple columns in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
MODIFY ( column_1 column_type,
column_2 column_type,
...
column_n column_type );
Drop column(s) in a table
Syntax #1
To drop a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
DROP COLUMN column_name;
Rename column(s) in a table
(NEW in Oracle 9i Release 2)
Syntax #1
Starting in Oracle 9i Release 2, you can now rename a column.
To rename a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
RENAME COLUMN old_name to new_name;
Friday, September 3, 2010
Oracle: select column names and types
Хүснэгтийн талбарын нэр, төрлийг сонгож авах
select column_name, data_type, data_length
from user_tab_columns
where table_name = 'MY_TABLE';
select * from all_tab_columns where owner = 'THE_SCHEMA_OWNER';
thanks Dr. Xi (http://www.xinotes.org/notes/note/521/)
select column_name, data_type, data_length
from user_tab_columns
where table_name = 'MY_TABLE';
select * from all_tab_columns where owner = 'THE_SCHEMA_OWNER';
thanks Dr. Xi (http://www.xinotes.org/notes/note/521/)
Monday, February 15, 2010
Installing Go on Ubuntu
Info source: http://unixlab.blogspot.com/2009/11/installing-googles-go-language-on.html
See also: http://golang.org/doc/install.html
Tech talk (1 hour) (PDF)
Python + C = Go. Google's Programming Language
1. Install Pre-requisites on ubuntu.
You need gcc and some supporting software like bison to compile go. Install the following.
$ sudo apt-get install bison gcc libc6-dev ed
The go repository uses mercurial version controls system .
Install mercurial with the following command.
$ apt-get install mercurial
2. Set up the environment variables.
Create a folder named go in your home directory.
"/home/fermi"
$mkdir go
Create bin direcory inside go .
$ mkdir go/bin
The above directory will contain your go compiler.
Next, you have to set u several variables.
$ export GOROOT=/home/fermi/go/hg
$ export GOOS=linux
$ export GOARCH=386
$ export GOBIN=/home/fermi/go/bin
( Note: You need not create the folder hg. You can also add the above
four lines along with the PATH variable below to the .bashrc file
if you are planning to use go regularly.)
Update your PATH variable .
$ export PATH=$PATH:$GOBIN
Check the environment variables with.
$ env | grep '^GO'
show like this.
GOBIN=/home/fermi/go/bin/
GOARCH=386
GOROOT=/home/fermi/go/hg
GOOS=linux
3. Grab the source code from mercurial
$hg clone -r release https://go.googlecode.com/hg/ $GOROOT
Wait for downloading.
4. Compile Go
$ cd $GOROOT/src
$ ./all.bash
Wait for compiling. Process will be completed with the following message
--- cd ../test
0 known bugs; 0 unexpected bugs
5. Test go
Write a hello world program.
Create a folder named mysrc in go dir then hello.go inside mysrc dir.
hello.go as like
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
To compile hello.go run.
$ 8g hello.go
The above command produced and intermediate file hello.8.
Next you have to link it.
$ 8l hello.8
The executable is placed as 8.out. Finally run the executable.
$./8.out
Thank you, Fermi (http://unixlab.blogspot.com/)
See also: http://golang.org/doc/install.html
Tech talk (1 hour) (PDF)
Python + C = Go. Google's Programming Language
1. Install Pre-requisites on ubuntu.
You need gcc and some supporting software like bison to compile go. Install the following.
$ sudo apt-get install bison gcc libc6-dev ed
The go repository uses mercurial version controls system .
Install mercurial with the following command.
$ apt-get install mercurial
2. Set up the environment variables.
Create a folder named go in your home directory.
"/home/fermi"
$mkdir go
Create bin direcory inside go .
$ mkdir go/bin
The above directory will contain your go compiler.
Next, you have to set u several variables.
$ export GOROOT=/home/fermi/go/hg
$ export GOOS=linux
$ export GOARCH=386
$ export GOBIN=/home/fermi/go/bin
( Note: You need not create the folder hg. You can also add the above
four lines along with the PATH variable below to the .bashrc file
if you are planning to use go regularly.)
Update your PATH variable .
$ export PATH=$PATH:$GOBIN
Check the environment variables with.
$ env | grep '^GO'
show like this.
GOBIN=/home/fermi/go/bin/
GOARCH=386
GOROOT=/home/fermi/go/hg
GOOS=linux
3. Grab the source code from mercurial
$hg clone -r release https://go.googlecode.com/hg/ $GOROOT
Wait for downloading.
4. Compile Go
$ cd $GOROOT/src
$ ./all.bash
Wait for compiling. Process will be completed with the following message
--- cd ../test
0 known bugs; 0 unexpected bugs
5. Test go
Write a hello world program.
Create a folder named mysrc in go dir then hello.go inside mysrc dir.
hello.go as like
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
To compile hello.go run.
$ 8g hello.go
The above command produced and intermediate file hello.8.
Next you have to link it.
$ 8l hello.8
The executable is placed as 8.out. Finally run the executable.
$./8.out
Thank you, Fermi (http://unixlab.blogspot.com/)
Subscribe to:
Posts (Atom)
