Q: | |||||||||||
27-20. | The following table summarizes the similarities and differences between native PL/SQL procedures and external procedures.
| ||||||||||
Q: | |||||||||||
27-21. | With the advent of external procedures comes the ability to call programs that can do things not currently supported by the PL/SQL language. Even with the large strides made in the Oracle8i release, there are operations that still require operating system-level programming (e.g., deleting an OS file). Programmers are no longer limited to performing tasks in PL/SQL that are directly supported. They can now write code in any Oracle-supported language and then call this code using the external procedure method. | ||||||||||
Q: | |||||||||||
27-22. | To use an external procedure, you must follow these steps:
| ||||||||||
Q: | |||||||||||
27-23. | The current implementation of external procedures has the following disadvantages:
| ||||||||||
Q: | |||||||||||
27-24. | This error occurs when Oracle is unable to find the external procedure listener. Without this listener, Oracle cannot communicate with the OS library or shared object that contains the code for the external procedure. This is quite common if the DBA forgets to restart the external procedure listener after a system reboot (only the database listener is restarted by default). | ||||||||||
Q: | |||||||||||
27-25. | The BY REFERENCE option in the PARAMETERS clause passes the parameter by reference (i.e., a pointer is passed to the module, and the result is changed directly by the external procedure). However, this option affects only numeric datatypes, since the other datatype (STRING) is always passed by reference. | ||||||||||
Q: | |||||||||||
27-26. | Since Oracle uses dynamic linking, once a particular module has been loaded into memory (when the first reference to it has been made), subsequent invocations of it do not cause any further overhead. In other words, all users share the same copy of the external library code in memory. This makes the memory requirements much lower in a busy system where many users quite often call the same code. By collecting commonly used modules into their own libraries, the system load is decreased and things become more manageable. | ||||||||||
Q: | |||||||||||
27-27. | The PL/SQL wrapper for an external procedure can be created as a stand-alone function, a standalone procedure, or a function/procedure within a package. While any of these methods works, there are several advantages to placing the wrapper inside a package:
| ||||||||||
Q: | |||||||||||
27-28. | Dropping a library can be a potentially dangerous operation if you are not sure whether any stored modules are utilizing it. The easiest way to check if the library is referenced anywhere is by querying the USER_DEPENDENCIES view as shown here: SELECT * FROM USER_DEPENDENCIES WHERE REFERENCED_NAME = 'MYLIB_NAME' | ||||||||||
Q: | |||||||||||
27-29. | Logging messages to a file is often desired because of the limitations with Oracle’s DBMS_OUTPUT package (e.g., output is unavailable until the program completes and is limited to 255 characters per line). The steps in the process are listed here:
All the pieces described must be in place before the file logging will work. If you’ve created all of the pieces and run without errors, but the logging still does not work, check to make sure that:
Other programmers can then place calls to this procedure in their code to generate messages into the OS file. For example: BEGIN ... log_pkg.write_debug_message('Attempting to add client information'), ... END; |
Q: | |
27-30. | One of the most common mistakes is forgetting to refresh the information available to the listener. If information in the LISTENER.ORA file is changed while the listener is up, it does not take effect until the listener is stopped and restarted. Alternatively, the reload command can be used to refresh the information while the listener is up. |
Q: | |
27-31. | One of the most common requests from developers or clients is to have an email message sent based on some triggering event in the database. The solution for the email-notification problem is to use an external procedure to call an operating system library to send the email. Here are the steps in the process:
All the pieces described must be in place before the email notifications will work. If all pieces exist and are without errors, and the email messages are still not being delivered, check to make sure that:
When the system is functioning, notifying a client of new products is as easy as inserting the client’s email address into the clients_to_notify table. The email message is sent automatically by the trigger. |
Q: | |
27-32. | A single-threaded process is one that guarantees only one copy of itself is running at any given time. Since only one extproc is created for each database session, you know that only one is ever running. If Oracle were to change the implementation, you’d need to be careful that the structures or system objects being accessed in the external procedure could handle concurrent access. For example, if the external procedure attempted to open and write to a file, you’d have to handle a situation in which two requests tried to open the same file at the same time. These issues are often referred to as serialization problems, because the requests must be “serialized” or sorted and processed in the order in which they were received. |
Q: | |
27-33. | Yes, in Oracle 8.1.5 using the DEBUG_EXTPROC package. Here is how it’s done:
Execute your external procedure, and the debugger should break at pextproc. Consult the Oracle documentation for a complete description of installing and using this package. |
3.16.70.101