PL/SQL script language value assignment statement syntax table and record comply with the type usage, select the statement if else usage anonymous Block

Source: Internet
Author: User

PL/SQL script language value assignment statement syntax table and record comply with the type usage, select the statement if else usage anonymous block (1), assign value statement syntax PL/SQL values use: = "=" some rules need to be observed in the comparison operator value assignment statement: the character type must use single quotes, and the group by operator or the string connection operator (2) cannot be used), PL/SQL script language variable declaration (a), variables must be declared in the declare statement block syntax rule Identifier [constant] datatype [not null] [: = | default expr]; some basic rules or specifications must be observed when declaring variables: variable names cannot use reserved words, for example, the first character such as from and select must be a letter (v _). The variable name can contain a maximum of 30 characters. Do not declare only one variable (B) for each row with the same name as the database table or column) variable type number: Numeric char: Fixed Length string varchar2: Variable Length string date: date boolean: boolean type, can be set to true, false, or null value note: if the declared variable type is the same as a table field or another variable and the field type can be dynamically tracked, use the % type attribute of the field or variable (c) note: In PL/SQL, only one record can be returned for a select statement. Otherwise, the program will encounter an error when adding the into clause in the select statement, put the queried data into the variable. If the DML statement in PL/SQL takes effect or is rolled back directly using the DML statement, you need to explicitly call the commit or rollback SQL % rowcount attribute to record the number of records affected by the last SQL statement. The execute immediate statement must enclose the DDL statement in single quotes (3) anonymous block: The anonymous block of PL/SQL consists of four parts: declare-optional declaration of various Where the variable or cursor is located. Begin-it is necessary to start executing the statement. -- The single-line comment statement is represented by two '-' that are connected together. /* Multi-line comment statement, line feed */exception-optional processing after error. End;-necessary (note the semicolon after end. (3) The declaration of table record conforming to type (a) and table similar to the array able variable contains two parts. The first part declares a specific type of table, then use this specific type to declare a variable type type_name is table of data_type index by binary_integer; identifier type_name; (B) the declared syntax rule type type_name is record (field_name1 data_type [not null {:=| default} expr], field_name2 data_type [not null {: = | default} expr],…); Identifier type_name; if the declared variable type is the same as a table structure and can dynamically track table structure changes, % rowtype is replaced by % rowtype (c), example declare -- record table Variable Composite type emp_record is record (ename emp. ename % type, job emp. job % type, sal emp. sal % type); emp_info emp_record; type str_tab is table of varchar2 (10) index by binary_integer; v_str str_tab; begin select e. ename, e. job, e. sal into emp_info.ename, emp_info.job, emp_info.sal from emp e where e. empno = 7369; dbms_output.put_line (emp_info.ename); v_str (0): = 'afdfa '; v_str (1): = 'afwea'; v_str (3): = 'fej '; dbms_output.put_line (v_str (3) | ''| v_str (0); end; (4), if else SELECT statement declare v_num1 number (8, 4 ); v_num2 number (8, 4); v_num3 number (8, 4); v_sum number (8); begin v_num1: = floor (dbms_random.value * 6) + 1; v_num2: = floor (dbms_random.value * 6) + 1; v_num3: = floor (dbms_random.value * 6) + 1; v_sum: = v_num1 + v_num2 + v_num3; if v_sum> 12 then -- if then can be written between conditions, and or () dbms_output.put_line ('Good luck '); elsif v_sum> 8 then dbms_output.put_line ('General luck '); else dbms_output.put_line ('bad luck '); end if; end;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.