Call (800) 766-1884 for Oracle support & training
Free Oracle Tips


Oracle Consulting Support
Oracle Upgrades
Use New Oracle Features
Oracle Replication Support
Oracle Training
Remote Oracle DBA
System Documentation
Oracle Tips
Oracle Performance
 

Free Oracle Tips


 

HTML Text

BC Oracle tuning

Oracle training

Oracle support

Remote Oracle

Redneck
 

Donald K. Burleson

Oracle Tips

New Oracle9i Scalar subqueries

Oracle9i scalar queries are one of the strangest changes in all of Oracle9i.  Oracle started by allowing SQL sub-queries in the FROM clause in SQL statements and Oracle9i has now extended this functionality to allow SQL sub-queries inside the SELECT statement:

For example, consider the following SQL.  Note the embedded SELECT statements inside the outer SELECT and inside the FROM clause.

select

   (select max(salary) from emp) highest_salary,

   emp_name,

   (select avg(bonus) from commission) avg_comission,

   dept_name

from

   emp,

   (select dept_name from dept where dept = ‘finance’)

;

From this example, we see that Oracle allows for single-row subqueries to be included in the SELECT clause of any SQL statement.  While this ability may be of interest for obtuse queries, this new feature is of little interest to Oracle9i developers.

However, scalar subqueries can also be used by DML.  Consider the example below where we include a subquery inside an insert statement:

Insert into
   customer
(
   name,
   max_credit
)
values (
   ‘Sam’,
   (select max(credit) from credit_table where name = SAM’)
       );

Here we see that scalar subqueries can useful for streamlining INSERT and UPDATE statements that might otherwise be forced to use subqueries in their WHERE clause to get the required data. 

If you like Oracle tuning, you might enjoy my latest book “Oracle Tuning: The Definitive Reference” by Rampant TechPress.  It’s only $41.95 (I don’t think it is right to charge a fortune for books!) and you can buy it right now at this link:

http://www.rampant-books.com/book_1002_oracle_tuning_definitive_reference_2nd_ed.htm

 

”call

  
 

Oracle performance tuning software 
 
 
 
 

Oracle performance tuning book

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 
   

Copyright © 1996 -  2009 by Burleson Enterprises, Inc. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.