472,378 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

usage of Dual table in oracle

kiss07
99
Hi deba,

What is the usage of dual table in oracle?Use any applications?
what is difference between decode and if-the -else(any restrictions)between two:?

pls explain..


ARUN..
May 5 '07 #1
5 7826
debasisdas
8,127 Expert 4TB
Hi,

Actually what happens when we issue create database command, Oracle automatically creates the tablespace and tables using the sql.bsq script found in the $oracle_home/rdbms/admin directory (oracle\product\10.2.0\db_1\RDBMS\ADMIN------in 10g)this scripts the dual table and is owned by the sys and has one column and one row.

Dual is a table which is created by oracle along with the data dictionary. It consists of exactly one column whose name is dummy and one record. The value of that record is X.

The owner of dual is SYS but dual can be accessed by every user.

As dual contains exactly one row (unless someone manipulates it), it is guaranteed to return exactly one row in select statements.
Therefor, dual is the prefered table to select a pseudo column (such as sysdate
Expand|Select|Wrap|Line Numbers
  1. select user,sysdate from dual;
  2.  
  3. SELECT CHR(78) FROM DUAL;
  4.  
  5. SELECT (319/212)+10 FROM DUAL;
  6.  
  7.  
Although it is possible to delete the one record, or insert additional records, one really should not do that!.

U can use any predefined function from this table.
Also if user creates any function that can also be used with the help of this DUAL table .
May 5 '07 #2
debasisdas
8,127 Expert 4TB
This is regarding your second question--DECODE ver IF-THEN-ELSE
----------------------------------------------------------------------------------------------------------
In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.

The syntax for the decode function is:

decode( expression , search , result [, search , result]... [, default] )

Expression is the value to compare.

Search is the value that is compared against expression.

Result is the value returned, if expression is equal to search.

default is optional. If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).

For Example:

You could use the decode function in an SQL statement as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT supplier_name, 
  2. decode(supplier_id, 10000, 'HCL', 
  3.  10001, 'SPA', 
  4.  10002, 'SPIDER', 
  5.   'SVNT') result 
  6. FROM suppliers; 
  7.  
The above decode statement is equivalent to the following IF-THEN-ELSE statement:
Expand|Select|Wrap|Line Numbers
  1. IF supplier_id = 10000 THEN
  2.      result := 'HCL';
  3. ELSIF supplier_id = 10001 THEN
  4.     result := 'SPA';
  5. ELSIF supplier_id = 10002 THEN
  6.     result := 'SPIDER';
  7. ELSE
  8.     result := 'SVNT';
  9. END IF;
  10.  
The decode function will compare each supplier_id value, one by one.

The main difference is Decode can be used directly in SQL where as
IF-THEN-ELSE
being a structure can only be used in PL/SQL

You can use CASE instead of if-then

Performance wise case is faster than if-then and can be used in SQL .
May 5 '07 #3
what is a pseudo column
May 7 '07 #4
debasisdas
8,127 Expert 4TB
As u know the word pseudo means virtual

so pseudo column means a column which doesnot exist physically bust still can be used.

For alist of pseudo columns follow the Link

and go to the first post in the tread at the bottom of the page.
May 7 '07 #5
This is regarding your second question--DECODE ver IF-THEN-ELSE
----------------------------------------------------------------------------------------------------------
In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.

The syntax for the decode function is:

decode( expression , search , result [, search , result]... [, default] )

Expression is the value to compare.

Search is the value that is compared against expression.

Result is the value returned, if expression is equal to search.

default is optional. If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).

For Example:

You could use the decode function in an SQL statement as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT supplier_name, 
  2. decode(supplier_id, 10000, 'HCL', 
  3.  10001, 'SPA', 
  4.  10002, 'SPIDER', 
  5.   'SVNT') result 
  6. FROM suppliers; 
  7.  
The above decode statement is equivalent to the following IF-THEN-ELSE statement:
Expand|Select|Wrap|Line Numbers
  1. IF supplier_id = 10000 THEN
  2.      result := 'HCL';
  3. ELSIF supplier_id = 10001 THEN
  4.     result := 'SPA';
  5. ELSIF supplier_id = 10002 THEN
  6.     result := 'SPIDER';
  7. ELSE
  8.     result := 'SVNT';
  9. END IF;
  10.  
The decode function will compare each supplier_id value, one by one.

The main difference is Decode can be used directly in SQL where as
IF-THEN-ELSE
being a structure can only be used in PL/SQL

You can use CASE instead of if-then

Performance wise case is faster than if-then and can be used in SQL .


There is however, a very important point regarding decode. It automatically converts the second return value to the datatype of the first return value. And if the first return value is null, then the second return value is converted to varchar2. BE VERY CAREFUL USING DECODE FUNCTION IF THE FIRST RETURN VALUE IS NULL i.e.
max(decode(status,'BC',NULL,create_date))
In this case, the create_date column will be converted to varchar2 type, and so
the max may give errors (we faced this issue just a month ago)
CASE-WHEN is obviously a better choice in this regard.
Jun 8 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Frank | last post by:
Hi, we are using oracle clients (Release 9.0.1.0.1 - Production) on an NT4 (Service Pack6) computers. the server is a W2K, (Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production With the...
1
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
3
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
2
by: Christian | last post by:
HI, Is there a usage for something like this: Select MyColumn From MyTable Start with MyCol = aNumber Connect By MyCol = MyOtherCol If not, its a bit weird that Oracle does not raise an...
5
by: premmehrotra | last post by:
I am using Microsoft Access 2000 and Oracle 9.2.0.5 on Windows 2000. When I export a table from Access to Oracle using ODBC I get error: ORA 972 identifier too long I think the error is because...
2
by: webwarrior | last post by:
Hi, Is there a reason why we have to pay more for licensing for a different kind of processor? Why are we not charged for the Hyperthreading on some processors also. If Oracle is really...
15
by: Woody Ling | last post by:
I am starting to config a 64 bits DB2 in IBM 595 AIX box with 2 dual core CPU and I would like to assigned one 'processor' for one db partition. Should I config it as a 4 nodes or 2 nodes...
1
by: Luting | last post by:
Hi everyone, I am working on a project using Access as the frontend of a Oracle database. I'd like to use the Dual table in Oracle so I made a link table in Access for the Dual. However, it...
2
by: sanQUEST | last post by:
hi, If I can create a dual table ,then why can't I select from it? like :select sysdate from dual ? thanks sanQUEST
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.