|
The function doesn't "do" anything until it is invoked, either. That
doesn't appear to me to be a valid reason to avoid the use of views. What
the original poster and others are trying to achieve is to keep complex
join and selection predicates out of the application code, and to increase
reusability of the SQL code. From that standpoint, a view or a function
does the same thing.
At my last job, someone had written a general purpose function to convertI have had performance problems with SQL functions also. My default
date values from various formats to other formats. The function had three
parameters for input date value, from-format and to-format; I believe there
may have been a parameter for separator character as well. The function
returned a character value. I was asked to look at an application from a
DBA perspective because it was "too slow". The basic SQL was fine, and no
new indexes were needed. However, I noticed the use of that date function
right away. They were converting a date column defined as dec(9,0) that
had dates stored in 0yyyymmdd format to *ISO (I now recall that there was
indeed an input parameter to the function for the separator character.)
The process worked over a very large volume of data and was taking some
15-20 minutes. I replaced the function invocation with the following ugly
code in their statement:
substr(digits(dec_date),2,4) || '-' ||
substr(digits(dec_date),6,2) || '-' ||
right(digits(dec_date),2) as iso_date
and the process then ran in about two minutes over the same high volume of
data.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.