Oracle Database Data Object Analysis (below)

xiaoxiao2021-03-06  65

Procedures and function processes and functions are stored in the database in the database, and the function can have multiple parameters and there is a return value without parameters. The process has zero or more parameters, no return value. Functions and processes can receive or return zero or more values ​​through the parameter list, and the main difference between functions, and processes is not to return values, but their call mode. The process is called: Pay_INVOLUME (INVOICE_NBR, 30, DUE_DATE); function is called in a legal expression: ORDER_VOLUMN: = Open_ORDERS (Sysdate, 30); The syntax of the creation process is as follows:

Create [or report] procedure_name [parameter_lister] {as | is} declaration_sectionBeginexecutable_section [exceptionException_section] End [Procedure_name]

The syntax of each parameter is as follows: paramter_name mode datatype [(: = | default) value] Mode has three forms: in, out, inout. In indicates that the value of the actual parameter is passed to the process when the calling process is passed, and the form parameter is considered to be read-only. When the process ends, the control will return to the control environment, and the value of the actual parameter will not change. The value of the actual parameter will be ignored when the process is called, and the internal form parameters can only be assigned, and the data cannot be read from the process, and the content of the formal parameters after the process will be given the actual parameters. This mode is a combination of IN and OUT; the value of the actual parameters within the process will pass to the form parameters, the value of the situation parameters can be written, and the value of the situation parameters will be given the actual parameters after the process is over. The syntax of the creation function is basically the same, the only difference is that the function has a Returen clause.

CREATE [OR REPLACE] FINCTION [schema.] Function_name [parameter_list] RETURN returning_datatype {AS | IS} declaration_sectionBEGINexecutable_section [EXCEPTION] exception_sectionEND [procedure_name]

There must be or more Return statements in the execution part of the function. You can call a single line function and group function in the creation function, for example:

CREATE OR REPLACE FUNCTION my_sin (DegreesIn IN NUMBER) RETURN NUMBERIS pi NUMBER = ACOS (-1); RadiansPerDegree NUMBER; BEGINRadiansPerDegree = pi / 180; RETURN (SIN (DegreesIn * RadiansPerDegree)); END

The bag is a container that is bundled with the process, function, and data structures; the package consists of two parts: external visual packing specification, including function head, process head, and external visual data structure; another part is the main body (Package Body), the cover body contains all the bundled processes and functions, execution, and exception handling parts. Packaged PL / SQL programs and a big difference without packaging, the package data has been existing during the entire session of the user, and when the user gets the execution authorization, it is equal to all programs and data structures in the package specification. Permission. But you can't just authorize only a function or process in the package. The package can be overloaded from the process and function, and multiple programs can be declared in the package, and the correct program is called according to the number of parameters and the data type of the data. Create package must first create the package specification, the package specification created syntax: CREATE [OR REPLACE] PACKAGE package_name {AS | IS} public_variable_declarations | public_type_declarations | public_exception_declarations | public_cursor_declarations | function_declarations | procedure_specificationsEND [package_name]

Create a package body Using the CREATE PACKAGE BODY statement:

CREATE [OR REPLACE] PACKAGE BODY package_name {AS | IS} private_variable_declarations | private_type_declarations | private_exception_declarations | private_cursor_declarations | function_declarations | procedure_specificationsEND [package_name]

Private data structures are those who are internally in the main body, which is invisible to the called program. The trigger is a program that automatically performs a response database. Can be set to trigger or execute before or after the trigger event. Events that can trigger trigger events include the following: DML event DDL event database event DML event trigger can be a statement or row-level trigger. The DML statement trigger triggers the DML row-level trigger before or after the speech statement is triggered before or after the row changes affecting the statement. Users can define multiple triggers to a single event and type, but there is no way to enhance the command of the multi-trigger trigger. The following table lists the trigger events that users can take advantage of:

Event Trigger Description INSERT Trigger Trigger DELETE Trigger Trigger DELETE Trigger Trigger CREATE When you remove a row from a table or view when you use a CREATE statement to use the CREATE statement to use the CREATE statement when you are inserting a row. Item Increases an object When the trigger ALTER triggers the trigger DROP when using the ALTER statement to change a database or item, trigger the trigger Start when the trigger Start is triggered when using the DROP statement to remove the trigger Start to turn on the trigger, in After the event triggers shutdown to turn off the database, triggering the logon before the event is triggered when a session is established, and the event triggers logoff when the session is turned off. Trigger the trigger when the server is triggered, and the event is triggered.

The syntax for creating a trigger is as follows:

Create [or report] Trigger_name {before | after | instead of} Eventon {Table_OR_VIEW_NAME | DATABASE} [for Each Row [hen condition]] TRIGGER_BODY

Only the DML trigger (INSERT, UPDATE, DELETE) statement can use the INSTEAD OF trip and only table DML triggers can be a Before or an AFTER trigger. Like constraints can be set to disable or enable to close or open their actuat (Execute), set the trigger to disable or enable using the ALTER TRIGGER statement: alter trigger_name enable; alter trigger trigger_name disable;

Use the ALTER TABLE statement to disable or enable the table

Alter Trigger Table_name Disable All Trigger; ALTER TRIGGER TABLE_NAME ENABLE All Trigger;

Delete trigger uses DROP TRIGGER

DROP TRIGGER TRIGGER_NAME;

Data Dictionary Oracle Data Dictionary contains metadata of the user database. With Underline Table Name, with Obj $, UET $, Source $, which is created by SQL.BSQ scripts during the execution of the CREATE DATABASE statement. Under normal circumstances, users rarely access these tables. Script Catalog.sql (usually at $ ORACLE_HOME / RDBMS / Admin) runs immediately after the CREATE DATABASE statement, create a data dictionary view. The data dictionary view can be roughly divided into three categories:. Prefix the data dictionary view of User_, contains information about the object owned by the user. The data dictionary view of the ALL_ contains information that the user is currently accessible. The prefix is ​​a DBA_ 's data dictionary view, which contains information about all objects and permissions owned by the database. There are view families like DBA_Tables, All_Tables, and User_Tables, all of the data dictionary views. There are more than 100 view families in Oracle, so we must fully introduce these views of these views that are monotonous and not much. The most important and most common view families are listed in the table below, and you need to pay attention to each view family has a DBA_, an all_ a USER_ view.

View Family Description Col_privs contains column permissions for tables, including grantors, granted people, and permissions EXTENTS data range information, such as data files, data segment names (segment_name), and size indexes index information, such as type, uniqueness And the table IND_COLUMNS index column information, such as the column of the index Objects object information, such as status, and DDL TIMEROLE_PRIVS role, such as the GRANT and Admin Options Segments table and index data segment information, such as TableSpace and Storagesequecnces sequence information For example, Cache, Cycle, and AST_NUMBERSOURCE, in addition to all built-in processes, functions, functions of the trigger, such as reference objects and database links DB_LINKSYS_PRIVS system permissions, such as Grantee, Privilege, Admin Option Tab_Columns Table, The column information of the view, the data type TAB_PRIVS table permissions, such as the grant, the grant, the author, and the permissions TABLES table information, such as tablespace, storage parameters, and data line quantity Triggers trigger information, For example, type, event, trigger, User information, such as temporary and default table space Views view information, including view definitions

There are also some unused data dictionary tables in Oracle, but these tables are not a real dictionary family, they are all important single views.

View Name Description User_col_privs_made User Grants Users' Rights User_col_privs_recd User Grant User_TAB_PRIVS_MADE User Grants Other Personal_Tab_Privs_Recd Users Get the list of table permissions Other dictionary views The main thing is V $ view, this is called because they are all Take V $ or GV $ start. V $ view is based on X $ virtual view. V $ view is owned by the SYS user. Under the default situation, only SYS users and users with DBA system privileges can see all views, users without DBA privileges can see User_ and all_ view, but not See the DBA_ view. In contrast to DBA_, ALL, and User_ view, these views are visually given information. In large system uptime, manually enter each statement manually enter the statement of the username variable, then enter each username, which takes a few hours to write a SQL statement, generate the needs of the ALTER USER statement, Then execute him, this takes only a few minutes, it is obvious that we will choose to generate SQL: Example:

Select 'alter user' || username || 'Temporary TableSpace Temp;' from dba_userswhere username <> 'sys' and temporary_tablespace <> 'Temp';

The result of this query will be processed from a file and then executed:

ALTER USER SYSTEM TEMPORARY TABLESPACE temp; ALTER USER OUTLN TEMPORARY TABLESPACE temp; ALTER USER DBSNMP TEMPORARY TABLESPACE temp; ALTER USER SCOTT TEMPORARY TABLESPACE temp; ALTER USER DEMO TEMPORARY TABLESPACE temp;

转载请注明原文地址:https://www.9cbs.com/read-109844.html

New Post(0)