1, the common Operational database technology has those
JDBC Technology for accessing databases using Java
Plsql (Procedure process SQL) technology for manipulating data within a database
Proc/c++ C and C + + access to database technology
ODBC Microsoft provides access to database technology
OCI Oracle Bottom-level connectivity interface
Composite data types in the 2,oracle
Composite data types in Oracle Record,table,cursor
2.1 Record Type 2.1.1 syntax
/* define a record type */ The type record types name is record ( property data Type, property data type ... ); /* define a record variable with the record type name */ record variable name record type name
You can also use the table's fields to define,
/* define a record type using the table's field type */ Type record the name of the is record property sheet name. property name %Type, property sheet name. property name %type ... ); /* define a record variable with the record type name */ record variable name record type name
2.1.2 Example
SetServeroutput on;Declaretype Emptype isRecord (ID Number, namevarchar2(5) ); Var_emp Emptype;beginvar_emp.id:=1; Var_emp.name:=' Jame '; Dbms_output.put_line (var_emp.id);End;/
2.2 Table Type 2.2.1 Syntax
/* define a table type */ type table name is tableof element type name Indexby Binary_integer; /* Define a table variable */ Variable name table type name;
How to access the data,
Table variable (subscript):= value;
2.2.2 Example
Declaretype Numstype is Table of Number Index byBinary_integer; Var_nums Numstype; beginVar_nums (0):=9; Var_nums (1):=5; Var_nums (2):=2; Var_nums (3):=7; Var_nums (4):=0; Dbms_output.put_line (Var_nums (3));/*Print the element labeled 3*/ End;
The data in table can also be manipulated using the idea of iteration
Variables that traverse table types when subscript is not contiguous
Iterative thinking:
The name of the variable. First () Gets the subscript (the smallest subscript corresponding to the element)
The variable name. Next (N) gets the subscript for the next element based on the subscript n of an element
The name of the variable. Last () gets the subscript corresponding to the final element
For example:
SetServeroutput on; Declaretype Numstype is Table of Number Index byBinary_integer; Var_nums Numstype; Var_index Binary_integer:=0; beginVar_nums (0):=9; Var_nums (1):=5; Var_nums (- A):=2; Var_nums (3):=7; Var_nums (4):=0; --Var_nums.count ();Var_index:=Var_nums.first (); Loop Dbms_output.put_line (Var_nums (Var_index)); Var_index:=Var_nums.Next(Var_index); ifVar_index=Var_nums.last () ThenDbms_output.put_line (Var_nums (Var_index)); Exit; End if; EndLoop; End; /
2.3 Cursor Type 2.3.1 syntax
/* declaring Cursors */ cursor The cursor name is a SELECT statement; /* Open Cursor */ Open cursor name; /* extracts data, stores the result in a variable, typically a record type */ Fetch Cursor name into variable; /* Close Cursors */ Close cursor name
2.3.2 Example
Declare /*Create a cursor variable using s_emp*/ cursorEmpcursor is SelectId,first_name name,salary froms_emp; /*Create a record type*/type Emptype isrecord (ID s_emp.id%type, name S_emp.first_name%type, salary s_emp.salary%type); /*Create a record variable*/var_emp Emptype; begin /*Open Cursor*/ OpenEmpcursor; /*stores the first value of a cursor in a var_emp*/ FetchEmpcursor intovar_emp; Dbms_output.put_line (Var_emp.id||':'||Var_emp.name||':'||var_emp.salary); /*stores the first value of a cursor in a var_emp*/ FetchEmpcursor intovar_emp; Dbms_output.put_line (Var_emp.id||':'||Var_emp.name||':'||var_emp.salary); /*Close Cursors*/ CloseEmpcursor; End; /
Compound data type in "Plsql" Plsql