What is package in oracle




















Step 3 Creating an anonymous block to insert and display the records by referring to the above created package. Since the package is the logical grouping of related things, it has some dependencies.

Following are the dependency that is to be taken care. Once the package information is created, the package information such as package source, subprogram details, and overload details are available in the Oracle data definition tables. Below table gives the data definition table and the package information that is available in the table.

UTL File is the separate utility package provided by Oracle to perform special tasks. It got the separate functions to put the information and to get the information from files.

The Programmer can use this to write operating system files of any type and the file will be written directly to the database server. The name and directory path will be mentioned at the time writing.

Skip to content. Report a Bug. Previous Prev. Next Continue. Home Testing Expand child menu Expand. SAP Expand child menu Expand.

A package specification declares public items. The scope of a public item is the schema of the package. A public item is visible everywhere in the schema. To reference a public item that is in scope but not visible, qualify it with the package name. For information about scope, visibility, and qualification, see " Scope and Visibility of Identifiers ".

Each public item declaration has all information needed to use the item. For example, suppose that a package specification declares the function factorial this way:.

Invokers need not know how factorial is implemented for example, whether it is iterative or recursive. Creating Package Specifications. You cannot declare an associative array type at schema level. Therefore, to pass an associative array variable as a parameter to a standalone subprogram, you must declare the type of that variable in a package specification. Doing so makes the type available to both the invoked subprogram which declares a formal parameter of that type and to the invoking subprogram or anonymous block which declares a variable of that type.

See Example Provide these subprograms to discourage package users from reading and writing public variables directly. You need not worry about compilation order for package subprograms, as you must for standalone subprograms that invoke each other. Overloaded subprograms are variations of the same subprogram.

That is, they have the same name but different formal parameters. For more information about them, see " Overloaded Subprograms ". You cannot reference remote package public variables, even indirectly. For example, if a subprogram refers to a package public variable, you cannot invoke the subprogram through a database link.

If a package specification declares cursors or subprograms, then a package body is required; otherwise, it is optional.

The package body and package specification must be in the same schema. Every cursor or subprogram declaration in the package specification must have a corresponding definition in the package body. The headings of corresponding subprogram declarations and definitions must match word for word, except for white space.

The cursors and subprograms declared in the package specification and defined in the package body are public items that can be referenced from outside the package. The package body can also declare and define private items that cannot be referenced from outside the package, but are necessary for the internal workings of the package.

Finally, the body can have an initialization part , whose statements initialize public variables and do other one-time setup steps. The initialization part runs only the first time the package is referenced. The initialization part can include an exception handler. You can change the package body without changing the specification or the references to the public items. When a session references a package item, Oracle Database instantiates the package for that session. Every session that references a package has its own instantiation of that package.

When Oracle Database instantiates a package, it initializes it. Initialization includes whichever of the following are applicable:. The values of the variables, constants, and cursors that a package declares in either its specification or body comprise its package state. Each session that references a package item has its own instantiation of that package. If the package is stateful, the instantiation includes its state.

Therefore, previous changes to the package state are lost. All of a session's package instantiations including package states can be lost if any of the session's instantiated packages are invalidated and revalidated. Oracle Database treats a package as stateless if its state is constant for the life of a session or longer. This is the case for a package whose items are all compile-time constants. A constant whose initial value is a literal is always a compile-time constant.

A constant whose initial value is not a literal, but which the optimizer reduces to a literal, is also a compile-time constant. Therefore, a package that is stateless when compiled at one optimization level might be stateful when compiled at a different optimization level. If creating the package results in compilation errors, then the database returns an error.

This specification applies to the corresponding package body as well. This clause creates an invoker-rights package.

External names in all other statements resolve in the schema in which the package resides. Specify DEFINER to indicate that the package executes with the privileges of the owner of the schema in which the package resides and that external names resolve in the schema where the package resides.



0コメント

  • 1000 / 1000