PL/SQL User’s Guide and Reference phần 9 doc

76 317 0
PL/SQL User’s Guide and Reference phần 9 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

INSERT Statement 11-96 PL/SQL User’s Guide and Reference Usage Notes Character and date literals in the VALUES list must be enclosed by single quotes (’). Numeric literals are not enclosed by quotes. The implicit cursor SQL and the cursor attributes %NOTFOUND, %FOUND, %ROWCOUNT, and %ISOPEN let you access useful information about the execution of an INSERT statement. Examples The following examples show various forms of INSERT statement: INSERT INTO bonus SELECT ename, job, sal, comm FROM emp WHERE comm > sal * 0.25; INSERT INTO emp (empno, ename, job, sal, comm, deptno) VALUES (4160, ’STURDEVIN’, ’SECURITY GUARD’, 2045, NULL, 30); INSERT INTO dept VALUES (my_deptno, UPPER(my_dname), ’CHICAGO’); Related Topics SELECT Statement Literals Language Elements 11-97 Literals A literal is an explicit numeric, character, string, or Boolean value not represented by an identifier. The numeric literal 135 and the string literal ’hello world’ are examples. For more information, see "Literals" on page 2-7. Syntax + _ integer real_number numeric_literal digit integer integer . integer . . integer E e + _ integer real_number ’ character ’ ’ ’ character_literal ’ character ’ ’ ’ string_literal Literals 11-98 PL/SQL User’s Guide and Reference Keyword and Parameter Description character This is a member of the PL/SQL character set. For more information, see "Character Set" on page 2-2. digit This is one of the numerals 0 9. TRUE, FALSE, NULL This is a predefined Boolean value. Usage Notes Two kinds of numeric literals can be used in arithmetic expressions: integers and reals. Numeric literals must be separated by punctuation. Spaces can be used in addition to the punctuation. A character literal is an individual character enclosed by single quotes (apostrophes). Character literals include all the printable characters in the PL/SQL character set: letters, numerals, spaces, and special symbols. PL/SQL is case sensitive within character literals. So, for example, PL/SQL considers the literals ’Q’ and ’q’ to be different. A string literal is a sequence of zero or more characters enclosed by single quotes. The null string (’’) contains zero characters. To represent an apostrophe within a string, write two single quotes. PL/SQL is case sensitive within string literals. So, for example, PL/SQL considers the literals ’white’ and ’White’ to be different. Also, trailing blanks are significant within string literals, so ’abc’ and ’abc ’ are different. Trailing blanks in a literal are never trimmed. The Boolean values TRUE and FALSE cannot be inserted into a database column. TRUE FALSE NULL boolean_literal Literals Language Elements 11-99 Examples Several examples of numeric literals follow: 25 6.34 7E2 25e-03 .1 1. +17 -4.4 Several examples of character literals follow: ’H’ ’&’ ’ ’ ’9’ ’]’ ’g’ A few examples of string literals follow: ’$5,000’ ’02-AUG-87’ ’Don’’t leave without saving your work.’ Related Topics Constants and Variables, Expressions LOCK TABLE Statement 11-100 PL/SQL User’s Guide and Reference LOCK TABLE Statement The LOCK TABLE statement lets you lock entire database tables in a specified lock mode. That enables you to share or deny access to tables while maintaining their integrity. For more information, see "Using LOCK TABLE" on page 5-49. Syntax Keyword and Parameter Description lock_mode This parameter specifies the lock mode. It must be one of the following: ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE, SHARE, SHARE ROW EXCLUSIVE, or EXCLUSIVE. NOWAIT This optional keyword tells Oracle not to wait if the table has been locked by another user. Control is immediately returned to your program, so it can do other work before trying again to acquire the lock. table_reference This identifies a table or view that must be accessible when you execute the LOCK TABLE statement. For the syntax of table_reference, see "DELETE Statement" on page 11-52. Usage Notes If you omit the keyword NOWAIT, Oracle waits until the table is available; the wait has no set limit. Table locks are released when your transaction issues a commit or rollback. A table lock never keeps other users from querying a table, and a query never acquires a table lock. LOCK TABLE table_reference , IN lock_mode MODE NOWAIT ; lock_table_statement LOCK TABLE Statement Language Elements 11-101 If your program includes SQL locking statements, make sure the Oracle users requesting locks have the privileges needed to obtain the locks. Your DBA can lock any table. Other users can lock tables they own or tables for which they have a privilege, such as SELECT, INSERT, UPDATE, or DELETE. Example The following statement locks the accts table in shared mode: LOCK TABLE accts IN SHARE MODE; Related Topics COMMIT Statement, ROLLBACK Statement LOOP Statements 11-102 PL/SQL User’s Guide and Reference LOOP Statements LOOP statements execute a sequence of statements multiple times. The loop encloses the sequence of statements that is to be repeated. PL/SQL provides four kinds of loop statements: basic loop, WHILE loop, FOR loop, and cursor FOR loop. For more information, see "Iterative Control: LOOP and EXIT Statements" on page 3-6. Syntax << label_name >> LOOP statement END LOOP label_name ; basic_loop_statement << label_name >> WHILE boolean_expression while_loop_statement << label_name >> FOR index_name IN for_loop_statement REVERSE lower_bound upper_bound LOOP statement END LOOP label_name ; LOOP statement END LOOP label_name ; LOOP Statements Language Elements 11-103 Keyword and Parameter Description basic_loop_statement The simplest form of LOOP statement is the basic (or infinite) loop, which encloses a sequence of statements between the keywords LOOP and END LOOP. With each iteration of the loop, the sequence of statements is executed, then control resumes at the top of the loop. If further processing is undesirable or impossible, you can use the EXIT, GOTO, or RAISE statement to complete the loop. A raised exception will also complete the loop. boolean_expression This is an expression that yields the Boolean value TRUE, FALSE, or NULL. It is associated with a sequence of statements, which is executed only if the expression yields TRUE. For the syntax of boolean_expression, see "Expressions" on page 11-67. cursor_for_loop_statement A cursor FOR loop implicitly declares its loop index as a %ROWTYPE record, opens a cursor, repeatedly fetches rows of values from the result set into fields in the record, and closes the cursor when all rows have been processed. << label_name >> FOR record_name IN cursor_for_loop_statement cursor_name ( cursor_parameter_name , ) ( select_statement ) LOOP statement END LOOP label_name ; LOOP Statements 11-104 PL/SQL User’s Guide and Reference cursor_name This identifies an explicit cursor previously declared within the current scope. When the cursor FOR loop is entered, cursor_name cannot refer to a cursor already opened by an OPEN statement or an enclosing cursor FOR loop. cursor_parameter_name This identifies a cursor parameter; that is, a variable declared as the formal parameter of a cursor. (For the syntax of cursor_parameter_declaration, see "Cursors" on page 11-48.) A cursor parameter can appear in a query wherever a constant can appear. The formal parameters of a cursor must be IN parameters. for_loop_statement Whereas the number of iterations through a WHILE loop is unknown until the loop completes, the number of iterations through a FOR loop is known before the loop is entered. Numeric FOR loops iterate over a specified range of integers. The range is part of an iteration scheme, which is enclosed by the keywords FOR and LOOP. The range is evaluated when the FOR loop is first entered and is never re-evaluated. The sequence of statements in the loop is executed once for each integer in the range defined by lower_bound upper_bound. After each iteration, the loop index is incremented. index_name This is an undeclared identifier that names the loop index (sometimes called a loop counter). Its scope is the loop itself. Therefore, you cannot reference the index outside the loop. The implicit declaration of index_name overrides any other declaration outside the loop. So, another variable with the same name cannot be referenced inside the loop unless a label is used, as follows: <<main>> DECLARE num NUMBER; BEGIN FOR num IN 1 10 LOOP IF main.num > 5 THEN refers to the variable num, not to the loop index END IF; END LOOP; END main; LOOP Statements Language Elements 11-105 Inside a loop, its index is treated like a constant. The index can appear in expressions, but cannot be assigned a value. label_name This is an undeclared identifier that optionally labels a loop. If used, label_name must be enclosed by double angle brackets and must appear at the beginning of the loop. Optionally, label_name (not enclosed in angle brackets) can also appear at the end of the loop. You can use label_name in an EXIT statement to exit the loop labelled by label_ name. You can exit not only the current loop, but any enclosing loop. You cannot reference the index of a FOR loop from a nested FOR loop if both indexes have the same name unless the outer loop is labeled by label_name and you use dot notation, as follows: label_name.index_name In the following example, you compare two loop indexes that have the same name, one used by an enclosing loop, the other by a nested loop: <<outer>> FOR ctr IN 1 20 LOOP <<inner>> FOR ctr IN 1 10 LOOP IF outer.ctr > ctr THEN END LOOP inner; END LOOP outer; lower_bound upper_bound These are expressions that must yield numbers. Otherwise, PL/SQL raises the predefined exception VALUE_ERROR. The expressions are evaluated only when the loop is first entered. The lower bound need not be 1, as the example below shows. However, the loop counter increment (or decrement) must be 1. FOR i IN -5 10 LOOP END LOOP; [...]... methods, and so implements the spec All the information a client program needs to use the methods is in the spec Think of the spec as an operational interface and of the body as a black box You can debug, enhance, or replace the body without changing the spec 11-114 PL/SQL User’s Guide and Reference Object Types An object type encapsulates data and operations So, you can declare attributes and methods... statement host_cursor_variable_name This identifies a cursor variable declared in a PL/SQL host environment and passed to PL/SQL as a bind variable The datatype of the host cursor variable is compatible with the return type of any PL/SQL cursor variable Host variables must be prefixed with a colon 11-124 PL/SQL User’s Guide and Reference OPEN-FOR-USING Statement USING This optional clause specifies a list... spec Keyword and Parameter Description AUTHID This determines whether all the packaged subprograms execute with the privileges of their definer (the default) or invoker, and whether their unqualified references to schema objects are resolved in the schema of the definer or invoker For more information, see "Invoker Rights versus Definer Rights" on page 7- 29 11-128 PL/SQL User’s Guide and Reference Packages... sal FROM emp WHERE sal > :s’ USING my_sal; END; Related Topics EXECUTE IMMEDIATE Statement 11-126 PL/SQL User’s Guide and Reference Packages Packages A package is a schema object that groups logically related PL/SQL types, items, and subprograms Packages have two parts: a specification (spec for short) and a body For more information, see Chapter 8, "Packages" Syntax package_declaration | package_spec... OPEN Statement, %ROWTYPE Attribute 11-108 PL/SQL User’s Guide and Reference NULL Statement NULL Statement The NULL statement explicitly specifies inaction; it does nothing other than pass control to the next statement In a construct allowing alternative actions, the NULL statement serves as a placeholder For more information, see "NULL Statement" on page 3- 19 Syntax null_statement NULL ; Usage Notes... BEGIN RETURN (top = 0); END empty; 11-116 PL/SQL User’s Guide and Reference Object Types MEMBER PROCEDURE push (n IN INTEGER) IS push integer onto stack BEGIN IF NOT full THEN top := top + 1; position(top) := n; ELSE stack is full RAISE_APPLICATION_ERROR(-20101, ’stack overflow’); END IF; END push; MEMBER PROCEDURE pop (n OUT INTEGER) IS pop integer off stack and return its value BEGIN IF NOT empty... phone_number VARCHAR2(15), ss_number INTEGER, ); Related Topics Functions, Packages, Procedures 11-118 PL/SQL User’s Guide and Reference OPEN Statement OPEN Statement The OPEN statement executes the multi-row query associated with an explicit cursor It also allocates resources used by Oracle to process the query and identifies the result set, which consists of all rows that meet the query search criteria The... emp_cur(employee_name, 150); Related Topics CLOSE Statement, Cursors, FETCH Statement, LOOP Statements 11-120 PL/SQL User’s Guide and Reference OPEN-FOR Statement OPEN-FOR Statement The OPEN-FOR statement executes the multi-row query associated with a cursor variable It also allocates resources used by Oracle to process the query and identifies the result set, which consists of all rows that meet the query search criteria... many instances (usually called objects) as you need For more information, see Chapter 9, "Object Types" Syntax object_type_declaration | object_type_spec OR REPLACE CREATE schema_name TYPE type_name CURRENT_USER AUTHID DEFINER IS OBJECT AS member_list , attribute_name 11-110 attribute_type PL/SQL User’s Guide and Reference ( member_list ) ; Object Types MEMBER STATIC , subprogram_spec pragma_restrict_refs... call_spec ; MAP MEMBER function_body ; ORDER END ; Keyword and Parameter Description attribute_datatype This is any Oracle datatype except LONG, LONG RAW, NCHAR, NCLOB, NVARCHAR2, ROWID, UROWID, the PL/SQL- specific types BINARY_INTEGER (and its subtypes), BOOLEAN, PLS_INTEGER, RECORD, REF CURSOR, %TYPE, and %ROWTYPE, and types defined inside a PL/SQL package attribute_name This identifies an object attribute . ’ character_literal ’ character ’ ’ ’ string_literal Literals 11 -98 PL/SQL User’s Guide and Reference Keyword and Parameter Description character This is a member of the PL/SQL character set. For more information,. INSERT Statement 11 -96 PL/SQL User’s Guide and Reference Usage Notes Character and date literals in the VALUES list must be enclosed by single quotes. END LOOP; LOOP Statements 11-106 PL/SQL User’s Guide and Reference Internally, PL/SQL assigns the values of the bounds to temporary PLS_INTEGER variables, and, if necessary, rounds the values

Ngày đăng: 07/08/2014, 11:22

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan