An example of ORACLE calling DLL

Source: Internet
Author: User

Note: The following procedures are tested through the delphi7+oracle9i

1, first use Delphi to prepare a DLL program, of course, with VB,VC other languages can also,
I recently used Delphi, so the following DLLs using Delphi programming:

PROJECT1.DPR Engineering Documents
Library Project1;
Uses
Sysutils,
Classes,
Unit1 in ' Unit1.pas ';

{$R *.res}
Exports
Dlltest;
Begin
End.


Unit1.pas interface function Implementation file
Unit Unit1;

Interface

function Dlltest (a,b:double): double; Cdecl interface functions

Implementation
function Dlltest (a,b:double): double; Cdecl interface functions
Begin
Result:=a*b;
End

End.

2, will compile the generated Project1.dll copy to the $oracle_home/bin path, I $oracle_home=c:/oracle/ora92
So copy the Project1.dll to the c:/oracle/ora92/bin/path.


3, the ORACLE database to add a library name "Mylib"

Create or replace library Mylib
As ' C:/oracle/ora92/bin/project1.dll ';

4, the ORACLE database to add a function name "Mytest1"
CREATE OR REPLACE FUNCTION mytest1 (a double precision,b double PRECISION) return double PRECISION as
LANGUAGE C NAME "Dlltest"
LIBRARY Mylib
PARAMETERS (a double,b DOUBLE,
return DOUBLE);


5. Test

Select Mytest1 (3.51,8.2) from dual;

------------return 28.782

6, to this simple example to complete, in fact, this is a simple example, the actual application needs to be done according to the requirements,
I do this example is just for you to open the way, the actual application also need to refer to Oracle Help documentation.

SOURCE program and script download address:

http://www.cnoug.org/attachment.php?aid=20557

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.