Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: EXTRACT versur TO_CHAR
"Mark D Powell" <Mark.Powell_at_eds.com> a écrit dans le message de news: 1172762941.536318.30930_at_31g2000cwt.googlegroups.com...
| On Feb 28, 9:51 pm, "Dereck L. Dietz" <diet..._at_ameritech.net> wrote:
| > Is there any performance differences between using:
| >
| > EXTRACT(MONTH FROM variable) and TO_CHAR(variable,'MM')
| >
| > or do they both perform just as efficiently as the other?
| >
| > I have some PL/SQL code where it is using the EXTRACT to compare date
| > portions of one field against date portions of another field.
| >
| > Thanks.
|
| The EXTRACT function was provided to support the new with 9i TIMESTAMP
| data types. It has limited use on traditional DATE data types being
| limited to extracting Year, Month, and Day only. So I would use
| to_char on DATE datatypes and on TIMESTAMP data types where you want
| to reformat the output and I would use EXTRACT where only a specific
| portion of the data is needed.
|
| I have not ran performance tests but I suspect that you will need
| large row counts to be able to measure the difference. Perhaps
| someone has tested and saved the results and will share them with us.
|
| HTH -- Mark D Powell --
|
SQL> declare
2 i pls_integer; 3 month pls_integer; 4 sttim pls_integer; 5 run1 pls_integer; 6 run2 pls_integer;
18 dbms_output.put_line ('Run1 ran in ' || run1 || ' hsecs'); 19 dbms_output.put_line ('Run2 ran in ' || run2 || ' hsecs'); 20 dbms_output.put_line ('Run1 ran in ' || round(run1/run2*100,2) || 21 '% of Run2 time');22 end;
PL/SQL procedure successfully completed.
Regards
Michel Cadot
Received on Fri Mar 09 2007 - 09:47:39 CST
![]() |
![]() |