Question

Calling VB functions

Asked by: swtirs

I have read in oracle help that oracle supports user defined functions written in VB. But unfortunately that help topic did not cover much in detail. Can anyone show the way to VB functions from Oracle.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2001-05-14 at 11:28:14ID20117906
Tags

vb

,

oracle

,

calling

,

function

Topic

Oracle Database

Participating Experts
3
Points
200
Comments
3

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Convert functions written in C++ to VB
    I have written few functions in C++ but have to switch to VB now. I would still want to use the utility functions and classes I have developed in C++ into VB. Quick answers are really appreciated at this point. Thanks, Suhas
  2. vb and oracle
    Hi I have a doubt regarding oracle and vb: I am developing a front end using vb to connect oracle 8i. I am having a vb form like this: A check box with a label 'CONNECT' I am clicking this check box and I want it to call the encrypt function(refer to the quey belew) ...
  3. VB and Oracle
    hi all i would like to know which is a better option to insert and update the records in a table of an Oracle database which is in a remote server. The table consists of 50 odd fields. currently i'm calling a function in visual basic which would execute the package which ...
  4. Checking if something was written in VB?
    How do you check if someone elses program was written in VB? I'd prefer a solution that doesn't require any external tools. Thanks.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ser6398Posted on 2001-05-14 at 11:35:55ID: 6078834

go to:  technet.oracle.com

If you don't have an account yet, get one (it is free to join).

Search for:  External Procedures

What follows are some cuts from technet.oracle.com about external procedures:

External Procedures Overview
External procedures are functions written in a third-generation language (3GL), such as C, and callable from within PL/SQL or SQL as if they were a PL/SQL procedure or function. External procedures let you take advantage of the strengths and capabilities of a 3GL programming language in a PL/SQL environment.


The main advantages of external procedures consist of the following:

Performance, because some tasks are performed more efficiently in a 3GL language than in PL/SQL, which is better suited for SQL transaction processing
 

 
Code re-usability, because dynamic link libraries (DLLs) can be called directly from PL/SQL programs on the server or in client tools such as SQL*Forms
 

 
You can use external procedures to perform specific processes, such as the following:
Solving scientific and engineering problems
 

 
Analyzing data
 

 
Controlling real-time devices and processes
Creating and using an external procedure would involve the following sequential tasks:

Installing and Configuring
Writing an External Procedure
Building a DLL
Registering an External Procedure
Executing an External Procedure
Enabling Multi-Threaded Callout Support

--------------------------------------------------------------------------------
Attention:
You can combine the instructions described in the fourth and fifth tasks into one SQL script that automates the process of registering and executing your external procedure. For an example of a SQL script that combines these steps, see ORACLE_BASE\ORACLE_HOME\RDBMS\EXTPROC\EXTERN.SQL.  

--------------------------------------------------------------------------------
 

 


Installing and Configuring
This section describes the installation and configuration of Oracle8i Enterprise Edition and Net8.


Installing Oracle8i Enterprise Edition
Follow the procedures in Oracle8i Enterprise Edition Installation for Windows NT to install these products on your Windows NT server:

Oracle8i Enterprise Edition. Contains PL/SQL, from which external procedures are called, and the PL/SQL external procedure program (EXTPROC), which executes external procedures.
 
Net8 Client, Net8 Server, and Oracle Protocol support

 
 
 
 

--------------------------------------------------------------------------------
Note:
You must also have a C compiler and linker installed on your system to build DLLs.  

--------------------------------------------------------------------------------
 

 


Configuring Net8
If you install Net8 Server from your Oracle8i Enterprise Edition CD-ROM, your server network files are automatically configured to use external procedures.


When PL/SQL calls an external procedure, the Net8 listener launches a session-specific process called EXTPROC. Through Net8, PL/SQL passes the following information to EXTPROC:

DLL name
 
External procedure name
 
Parameters (if necessary)
 
EXTPROC then loads the DLL and invokes the external procedure.
If you copy your Oracle7 server network files into your Oracle8i network files directory, you must manually configure the following files for the external procedure behavior described previously to occur:

ORACLE_BASE\ORACLE_HOME\NETWORK\ADMIN\LISTENER.ORA
 
ORACLE_BASE\ORACLE_HOME\NETWORK\ADMIN\TNSNAMES.ORA
See Chapter 6 of the Oracle Net8 Administrator's Guide for instructions.

 


--------------------------------------------------------------------------------
Note:
The SQLNET.ORA file requires no changes. By default, the values for the parameters NAMES.DEFAULT_DOMAIN and NAME.DEFAULT_ZONE are set to WORLD. These values match with the .WORLD extension on the end of EXTPROC_CONNECTION_DATA in the TNSNAMES.ORA file.  

--------------------------------------------------------------------------------
 

 


Writing an External Procedure
Using a 3GL programming language, such as C, you can write functions to be built into DLLs and invoked by EXTPROC. The following is a simple Microsoft Visual C++ example of an external procedure:


 


--------------------------------------------------------------------------------
Note:
Since external procedures are built into DLLs, they must be explicitly exported. In this example, the dllexport storage class modifier exports the function find_max from a dynamic link library.  

--------------------------------------------------------------------------------
 

 

#include <windows.h>
#define NullValue -1
/*
  This function simply returns the larger of x and y.
*/
long __declspec(dllexport) find_max(long        x,
                                short   x_indicator,
long    y,
short y_indicator,
                                short *ret_indicator)
{
   /* It can be tricky to debug DLL's that are being called by a process
      that is spawned only when needed, as in this case.  
      Therefore try using the DebugBreak(); command.  
      This will start your debugger.  Uncomment the line with DebugBreak();
  in it and you can step right into your code.
   */
   /* DebugBreak();  */

   /* first check to see if you have any nulls */
   /* Just return a null if either x or y is null */

   if ( x_indicator==NullValue || y_indicator==NullValue) {
      *ret_indicator = NullValue;  
      return(0);
   } else {
      *ret_indicator = 0;        /* Signify that return value is not null */
      if (x >= y) return x;
      else return y;
   }
}
Building a DLL
After writing your external procedure(s) in a 3GL programming language, use the appropriate compiler and linker to build a DLL, making sure to export the external procedures, as noted above. See your compiler and linker documentation for instructions on building a DLL and exporting its functions.


After building the DLL, you can move it to any directory on your system. For the example above, you can build the external procedure find_max into a DLL called EXTERN.DLL. To build the above example, go to ORACLE_BASE\ORACLE_HOME\RDBMS\EXTPROC and type MAKE.


Registering an External Procedure
Once you have built a DLL containing your external procedure(s), you must register your external procedure(s) with the Oracle database:

Create a PL/SQL library to map to the DLL.
 
Start Server Manager:
 
C:\> SVRMGRL
 

Connect to the database with the appropriate user name and password.
 
Create the PL/SQL library using the CREATE LIBRARY command:
 
SVRMGR> CREATE LIBRARY externProcedures AS 'C:\ORACLE\ORA81\RDBMS\EXTPROC\EXTERN.DLL';

   
 Where... Represents the...
externProcedures
 Alias library (essentially a schema object in the database)
 
C:\ORACLE\ORA81\RDBMS\EXTPROC\EXTERN.DLL
 Path to the Windows NT operating system DLL EXTERN.DLL. This example uses C:\ORACLE as your Oracle base and \ORA81 as your Oracle home.
 
 



--------------------------------------------------------------------------------
Note:
The DBA must grant EXECUTE privileges on the PL/SQL library to users who want to call the library's external procedures from PL/SQL or SQL.  

--------------------------------------------------------------------------------
 

 

Create a PL/SQL program unit specification.
 

 
Do this by writing a PL/SQL subprogram that uses the EXTERNAL clause instead of declarations and a BEGIN...END block. The EXTERNAL clause is the interface between PL/SQL and the external procedure. The EXTERNAL clause identifies the following information about the external procedure:
Name
DLL alias
Programming language in which it was written
Calling standard (defaults to C if omitted)
 
Example 13-1

 

Executing an External Procedure
To execute an external procedure, you must call the PL/SQL program unit (that is, the alias for the external function) that registered the external procedure. These calls can appear in any of the following:

Anonymous blocks
Stand-alone and packaged subprograms
Methods of an object type
Database triggers
SQL statements (calls to packaged functions only)
In "Registering an External Procedure", the PL/SQL function PLS_MAX registered the external procedure find_max. Follow the procedures below to execute find_max:

Call the PL/SQL function PLS_MAX from a PL/SQL procedure named UseIt:
   CREATE OR REPLACE PROCEDURE UseIt AS
                a integer;
                b integer;
                c integer;
   BEGIN
                a := 1;
                b := 2;
                c := PLS_MAX(a,b);
                dbms_output.put_line('The maximum of '||a||' and '||b||' is  '||c);
   END;
Run the procedure:
 
SVRMGR> EXECUTE UseIt;

 
Enabling Multi-Threaded Callout Support
You can increase the speed of external procedure invocations when making calls to external programs from PL/SQL-stored procedures or PL/SQL methods of object types in the database by taking advantage of multiple, lightweight threads instead of a single, dedicated process-per-user session.


 


--------------------------------------------------------------------------------
WARNING:
Do not enable multi-threaded callout support if your C code is not thread-enabled. For example, do not use global variables in DLLs. Ensure also that there is synchronized access to variables in DLLs. See your Microsoft programming documentation for information on thread-enabling your code.  

--------------------------------------------------------------------------------
 

 


To enable multi-threaded callouts:

Open the Windows NT Control Panel.
 
Double-click Services.

The Services window appears.
 

Select OracleHOME_NAMEExtprocAgent, where HOME_NAME is the home name of the Oracle home directory you want to use.
 
Click Start.
 
Exit from the Windows NT Control Panel.
 
This enables you to use multiple, lightweight threads when making calls to EXTPROC from PL/SQL programs.

Additional Documentation
See the following documents for more information on external procedures:

Oracle8i Administrator's Guide
 
PL/SQL User's Guide and Reference
 
The following files in ORACLE_BASE\ORACLE_HOME\RDBMS\EXTPROC:
EXTERN.C (code example shown in "Writing an External Procedure")
 
MAKE.BAT (batch file that builds the dynamic link library)
 
EXTERN.SQL (automates the instructions described in "Registering an External Procedure" and "Executing an External Procedure")
 
README.DOC (explains how to run the sample and provides debugging advice)

 

by: MoondancerPosted on 2002-05-24 at 11:43:22ID: 7033109

Please update and finalize this old, open question.  Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,
Moondancer - EE Moderator

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.

 

by: MindphaserPosted on 2002-05-26 at 20:40:30ID: 7036388

Force accepted

** Mindphaser - Community Support Moderator **

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...