Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Nesting a Query to Improve Performance

BEGIN
-- Inefficient, calls function for every row
FOR item IN (SELECT DISTINCT (Sqrt(department_id)) col_alias
FROM employees)
LOOP
dbms_output.Put_line(item.col_alias);
END LOOP;
-- Efficient, only calls function once for each distinct value.
FOR item IN (SELECT Sqrt(department_id) col_alias
FROM (SELECT DISTINCT department_id
FROM employees))
LOOP
dbms_output.Put_line(item.col_alias);
END LOOP;
END;
/



OUTPUT:-

7.07106781186547524400844362104849039285
9.48683298050513799599668063329815560116
8.36660026534075547978172025785187489393
10.48808848170151546991453513679937598475
3.16227766016837933199889354443271853372
6.32455532033675866399778708886543706744
5.47722557505166113456969782800802133953
4.47213595499957939281834733746255247088
7.74596669241483377035853079956479922167
8.94427190999915878563669467492510494176
10
10
5.47722557505166113456969782800802133953
4.47213595499957939281834733746255247088
8.36660026534075547978172025785187489393
9.48683298050513799599668063329815560116
10.48808848170151546991453513679937598475
7.07106781186547524400844362104849039285
6.32455532033675866399778708886543706744
8.94427190999915878563669467492510494176
3.16227766016837933199889354443271853372
7.74596669241483377035853079956479922167

PL/SQL procedure successfully completed.

Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-