Overview
The basic sturctures of PL/SQL is very smilar to that of Altibase Procedures.
The both tools support procedural operations with using SQL statement that can manipulate data.
When you can solve a problem with SQL, you can issue SQL statements from your Altibase Procedures, without learning new APIs.
Like other procedural programming languages, Altibase Procedures lets you declare constants and variables, control program flow, define subprograms, and trap run-time errors.
Error Handling
PL/SQL makes it easy to detect and handle errors. When an error occurs, PL/SQL raises an exception.
Normal execution stops and control transfers to the exception-handling part of the PL/SQL block.
You do not have to check every operation to ensure that it succeeded, as in a C program.
The Altibase Procedures have the same error-handling structures with Oracle PL/SQL, So it is very easy to convert error handling part of PL/SQL to Altibase procedures.
Blocks
The basic unit of a PL/SQL and Altibase Procedures source program is the block, which groups related declarations and statements.
A block is defined by the keywords DECLARE, BEGIN, EXCEPTION, and END.
Example 5-1 shows the basic struture of PL/SQL and Altibase Procedures.
PL/SQL DATATYPES
PL/SQL provides many predefined datatypes.
As described below, PL/SQL DATATYPES and Altibase datatypes are compatible each other.
Oracle |
Altibase |
Comments |
---|---|---|
BINARY_DOUBLE, BINARY_FLOAT, BINARY_INTEGER, DEC, DECIMAL, |
INTEGER, FLOAT, DECIMAL, DOUBLE, NUMBER, REAL |
PL/SQL Number Types |
CHAR, CHARACTER, LONG, LONG RAW, NCHAR, NVARCHAR2, RAW, ROWID, |
CHAR, VARCHAR, NCHAR, NVARCHAR |
PL/SQL Character and String Types and PL/SQL National Character Types |
BOOLEAN |
|
PL/SQL Boolean Types |
DATE, TIMESTAMP, TIMESTAMP WITH TIMEZONE, TIMESTAMP WITH LOCAL |
DATE |
PL/SQL Date, Time, and Interval Types |
Example 5-1 The block structure of PL/SQL and Altibase Procedures
Block Structure of PL/SQL and Altibase Procedures |
---|
<<label>> (optional) |
The both PL/SQL and Altibase Procedures have same block structures.
TCAhere is no differences between PL/SQL and Altibase Procedures.
Variables and Constants
PL/SQL lets you declare variables and constants, and then use them wherever you can use an expression.
The differences between variables and constant is that if the program runs, the values of variables can change, but the values of constants cannot.
In Altibase Procedures, you can reuse the variables and constants that used in PL/SQL source without any changes except a several SQL data types that can not support in Altibase.
The example 5-2 shows the source code including variables and constants can be used in both PL/SQL and Altibase procedures.
Example 5-2 This code can be used in both PL/SQL and Altibase procedures.
Subprograms
A PL/SQL subprogram is a named PL/SQL block that can be invoked repeatedly.
If the subprogram has parameters, their values can differ for each invocation.
PL/SQL has two types of subprograms, procedures and functions. A function returns a result.
Altibase Procedures also have two types of subprograms, procedures and functions as like oracle's PL/SQL.
PL/SQL lets you invoke external programs written in other languages.
if a C procedure or Java method is stored in the database, you can invoke it from PL/SQL.
In the Altibase, the external programs can't be stored in the database, so we couldn't invoke external programs from Altibase procedures.
Packages
The package in Oracle PL/SQL is a schema object that groups logically related PL/SQL types, variables, constants, subprograms, cursors, and exceptions.
A package is compiled and stored in the database, where many applications can share its contents.
Altibase does not provide the same functionality such like a Oracle PL/SQL's packages.
Although it is inconvenient for you, but you should find the other way for functionality of PL/SQL's packages.
Triggers
A trigger is a named PL/SQL unit that is stored in the database and run in response to an event that changes the data in a table.
The basic syntax of Altibase triggers is almost same with that of Oracle triggers.
The major differences between Oracle and Altibase in triggers is that Oracle can control multiple trigger event for one table,
but Altibase can't.
In Altibase, Only one of three trigger event ( DELETE, UPDATE, INSERT) can be handled in triggers.
Input and Output
Most PL/SQL input and output (I/O) to get some values or display results is done with SQL statements.
PL/SQL provide the functionality for input and out in the shape of packages,
In contrast, Altibase provides some of functionality for it with the built-in functions.
Table 5-1 Comparing with PL/SQL packages and Altibase functions can be replaced for input and output(I/O) processing.
Oracle Packages |
Usage description |
Altibase functions can be replaced |
---|---|---|
DBMS_OUTPUT |
This lets PL/SQL display output. Especially useful for displaying PL/SQL debugging information |
PRTINT and PRTINTLN function |
DBMS_PIPE |
This lets two or more session in the same instance communicate |
Not supported |
UTL_FILE |
This lets PL/SQL programs read and write operating system files |
FOPEN FCLOSE FCLOSE_ALL FCOPY ..... ..... NEW_LINE and so on. |