PL/SQL FUNCTION
A. SQL FUNCTION
SQL function is an
collection of queries. It’s usually detailed that save into one long query and
database. If want to call it, we just call it with simple select query.
Example:
I’ll teach you about
simple SQL function. This SQL function is about converting degree value from
fahrenheit to celcius. Because formula for convert fahrenheit to celcius is (fahrenheit-32)x5/9, so we must type like
this:
After success with the code,
lets try with some value. I’ll put 66 degree of fahrenheit and see the result
from the program.
B. PL/PGSQL FUNCTION
PL/PGSQL is another
language for using function. It’s usuallu used for complex function that normal
SQL can’t handdle.
Example:
For PL/PGSQL function,
I’ll give example about convert value into word predicate.
First, we need to
describe range of values
> 100 or
<0
|
Incorrect
Value
|
≥ 90
|
A
|
≥ 70
|
B
|
≥ 60
|
C
|
≥50
|
D
|
≥ 0
|
E
|
Now, we’ve the range.
Lets typo some code
After typo code, we need to test. For this example, I’ll
use value 70



No comments:
Post a Comment