For the DB installed in Linux platform
Compiled the C code and generated .so file
gcc -o calc_tax.so -shared calc_tax.c
Step1: Conn scott/tiger@orcl
Step2: CREATE OR REPLACE LIBRARY c_lib
AS
'/tmp/calc_tax.so';
Note : You should have CREATE LIBRARY privelege
Step3: CREATE OR REPLACE FUNCTION tax_amt(x BINARY_INTEGER)
RETURN BINARY_INTEGER
AS LANGUAGE C
LIBRARY c_lib
NAME "calc_tax";
calc_tax.c is given below
-----------------------------------------------------
calc_tax(n)
int n;
{
int tax;
tax = (n*8)/100;
return(tax);
}
main()
{
int tot_ord;
printf("Enter the Order Total ");
scanf("%d",&tot_ord);
printf("\n%d", calc_tax(tot_ord));
printf("\n\n");
}
Step4: SELECT tax_amt(10000)
FROM DUAL;
Monday, January 25, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment