views:

248

answers:

4

How to coalesce a table in oracle and What is it's syntax ?

A: 

This documentation is very clear on explaining how we use COALESCE.

jpartogi
+2  A: 

coalesce is a function that takes two (or more) parameters and return the first that is not null.

Given a table with a nullable column called, say, Age, you could write the following:

select coalesce(Age, 18) from MyTable;
klausbyskov
what's the difference between this use of the function coalesce and the NVL function?Thanks - Jay
Jay
@Jay: `COALESCE()` is portable -- it's part of the ANSI standard.
Adam Musch
@Jay - besides what Adam says `COALESCE()` takes any number of parameters whereas `NVL()` takes only the two.
APC
The most important difference, imho, is COALESCE is short-circuited and NVL is not.
David
+3  A: 

I originally suspected that you were asking about coalescing tablespaces:

alter tablespace mytablespace coalesce;

This combines contiguous extents into larger extents. See Oracle 10G Docs

But now I think perhaps what you are looking for is

alter table mytable shrink space compact;

Thiis described in detail in this Oracle Magazine article.

Tony Andrews
I do not want to coalesce the whole tablespace, i just need to coalesce one table only.
The comments here may help: http://p2p.wrox.com/oracle/19758-oracle-8i-alter-table-table-coalesce-partition.html
Jeffrey Kemp
@usernnn, see my revised answer. Is that what you are looking for?
Tony Andrews
A: 

If I understand what you're trying to do, you'll need to:

ALTER TABLE blah MOVE TABLESPACE different-tablespace;

then move it back:

ALTER TABLE blah MOVE TABLESPACE original-tablespace;
cagcowboy