What are the specific languages for Oracle database programming?

Source: Internet
Author: User
Tags oracle database installation

PL/SQL are extensions of SQL by Oracle. They are specialized languages for programming in Oracle databases, it is a process-related programming language of the 3rd generation. From Oracle8, external C language calls are provided directly from PL/SQL.

Allows developers to use PL/SQL for program modules compiled in C language. Java programs have been introduced since Oracle8i.

This article describes the basic principles and conditions of external routines, describes how to reference external routines to operate COM objects in Windows, and provides an example of Excel objects.

All the Running Environments in this article are built on Oracle9i and Windows2000. The Oracle database installation directory ORACLE_HOME is D: oracleora92, SID is ORADB, and host name is CHANET.

Necessity

The extended PL/SQL language has integrated standard SQL, which is very suitable for designing Oracle database programs in terms of efficiency and security. However, for some functions of applications, other programming languages are more suitable than PL/SQL. For example, the C language is better than PL/SQL in computing and referencing system objects and devices, java has better network applications than PL/SQL.

If PL/SQL is not applicable to applications, you must compile it in other languages and use PL/SQL as an external routine.

In versions earlier than Oracle8, the only communication between PL/SQL and other languages is implemented by using the DBMS_PIPE and DBMS_ALERT packages. before using it, you must establish an OCI interface or pre-compiled monitoring program, it is complicated to use. When an external routine appears, you only need to create a function mapped to the external routine in PL/SQL, just like a common PL/SQL function, which simplifies the use process.

Basic Principles

When an external C language routine is referenced, The OracleOracle listener starts the extproc process, which dynamically loads the shared library. In Windows, the process is called a dynamic link library, that is, a DLL file ), the process acts as a buffer. When the PL/SQL process calls an external function, the process sends the command to the shared database and then returns the result to the PL/SQL process.

After a process is called, it exists with the use of session sessions in the shared library. If the call is completed or the user session in the database is closed, the extproc process is automatically disabled.

Use Configuration

Before calling an external routine, you must make the following settings:

· Configure listeners

· Configure the Net Component Service.

Configure the listener, open the D: oracleora92networkadminlistener. ora file, and modify the file parameters.

 
 
  1. LISTENER =   
  2. (DESCRIPTION_LIST =   
  3. (DESCRIPTION =   
  4. (ADDRESS_LIST =   
  5. (ADDRESS = (PROTOCOL = TCP)(HOST = CHANET)(PORT = 1521))   
  6. )   
  7. (ADDRESS_LIST =  
  8. (ADDRESS = (PROTOCOL = IPC)(KEY = extproc1))   
  9. )   
  10. )   
  11. )   
  12. SID_LIST_LISTENER =   
  13. (SID_LIST =   
  14. (SID_DESC =   
  15. (SID_NAME = PLSExtProc)  
  16. (ORACLE_HOME = D:oracleora92)   
  17. (PROGRAM = extproc)   
  18. )   
  19. (SID_DESC =   
  20. (GLOBAL_DBNAME = ORADB)   
  21. (ORACLE_HOME = D:oracleora92)   
  22. (SID_NAME = ORADB)   
  23. )   
  24. )  

Two parameters are important for using external routines.

 
 
  1. ·(ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = extproc1)) 

Set IPC-based external routines

 
 
  1. ·(SID_DESC =(SID_NAME = PLSExtProc) (ORACLE_HOME = D:oracleora92) (PROGRAM = extproc) ) 

Record the related attributes of the database. SID_NAME is PLSExtproc by default.

Configure the Net Component Service, open the D: oracleora92networkadmintnsnames. ora file, and save the following content in the file.

 
 
  1. EXTPROC_CONNECTION_DATA =   
  2. (DESCRIPTION =   
  3. (ADDRESS_LIST =   
  4. (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))   
  5. )   
  6. (CONNECT_DATA =   
  7. (SID = PLSExtProc)   
  8. (PRESENTATION = RO)   
  9. )   
  10. )  

Important parameter description:

 
 
  1. ·(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))    
  2. ·(CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) 

The two settings must be consistent with those in listener. ora.

Restart the listener and test whether the service is available.

Stop listener: lsnrctl stop

Start listener: lsnrctl start

Test whether the service is available:

 
 
  1. C:> tnsping EXTPROC_CONNECTION_DATA
  2. TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0-Production on month 4-2
  3. 005 16:57:00
  4. Copyright (c) 1997 Oracle Corporation. All rights reserved.

Used parameter file: D: oracleora92networkadminsqlnet. ora

Alias resolved using TNSNAMES Adapter

 
 
  1. Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)   
  2. (KEY = EXTPROC1))) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO)))  

OK30 ms)

Test whether the extproc process is normal:

 
 
  1. D: oracleora92bin> extproc
  2. Oracle Corporation-Thursday 2005 17:37:18. 968
  3. Heterogeneous Agent Release 9.2.0.1.0-Production

4. Instructions on using COM objects

The COM Object design provides three basic operations for developers to use: Get the attribute value, except for setting the attribute value read-only attribute) and call the method. Oracle Database provides interfaces for operating COM objects on the Windows platform, which belongs to the C language external routine mode.

Before using this function, you must understand the following:

1) create a COM Object operation function.

 
 
  1. SQL> CONNECT SYSTEM/chanet@oradb   
  2. SQL> CREATE USER chanet identified by chanet;   
  3. SQL> GRANT CREATE LIBRARY TO chanet;   
  4. SQL> CONNECT chanet/chanet@oradb;   
  5. SQL> @D:oracleora92comcomwrap.sql; 

2) configure the listener.

In the listener. ora file, add the following content and restart the listener.

 
 
  1. STARTUP_WAIT_TIME_LISTENER = 0   
  2. CONNECT_TIMEOUT_LISTENER = 10   
  3. TRACE_LEVEL_LISTENER = off   
  4. PASSWORDS_LINTENER = (oracle) 

3) PL/SQL data types and corresponding COM Object Types

Table 1-1 data type comparison

PL/SQL data type COM API data type

 
 
  1. VARCHAR2 BSTR   
  2. BOOLEAN BOOL   
  3. BINARY_INTEGER BYTE,INT,LONG   
  4. DOUBLE PRECISION DOUBLE,FLOAT,CURRENCY   
  5. DATE DATE 

4) function description.

Table 1-2 Functions

Name Function Description

CreateObject

DestroyObject

GetLastError

GetProperty

SetProperty

InitArg is the Invoke function initialization parameter.

InitOutArg is the GetArg initialization output parameter.

GetArg get output parameters

SetArg: set parameters for the Invoke Function

Invoke calls a function or process of a COM Object

5) Excel operation example

This section describes how to operate on a COM Object. Take an Excel object as an example. You can use PL/SQL statements to output table records in the database to an Excel file. You can use the Object Browser to view the properties and methods provided by the Excel object. For example, in the Excel menu, choose tools> macros> open the Visual Basic Editor. In the editor, choose View> Object Browser ).

Excel objects are generally used to operate on cells. For example, the Code for setting the Font Size of the first cell is Range ("A1"). Font. Size = 20 ). The operation steps of the corresponding COM external routine are as follows:

1. Obtain the program handle;

2. Obtain the workbook handle;

3. Obtain the worksheet handle;

4. Obtain the Range handle;

5. Obtain the Font class handle;

6. Set the Size attribute.

The above content is an introduction to the use of PL/SQL to operate COM objects in Oracle databases. I hope you will have some gains.

Article by: http://database.csdn.net/c_oracle/tag/2

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.