In plsql programming, the variable Declaration creates the first program hello worldbegin dbms_output.put_line ('Hello World'); end;/set serveroutput on; (the command that outputs the statement to the dos window) begin dbms_output.put_line ('Hello World'); end;/You can see Hello world; (Declaration of simple variables) Declaration variable in the dos window: declare v_name varchar2 (20 ); (before the variable name and after the type) begin v_name: = 'myname'; (assign a value to the variable) dbms_output.put_line (v_name); end;/(Exception Handling) declare v_num number: = 0; begin v_num: = 2/v_num; dbms_output.put_line (v_num); exception when others then dbms_output.put_line ('error'); end; rules for variable declaration: 1 variable names cannot use reserved words: (from, select) 2. The first character must be a letter. 3. The variable name can contain a maximum of 30 characters. 4. Do not declare a variable with the same name as a database table or column. 5. Each row can only declare one common variable: binary_integer: integer, it is mainly used to count, not to represent the field type, (improve efficiency) number; number type char: Fixed Length string; date: date; long: long string, maximum 2G; boolean type, optional values: true, false, null; constant exercises; declare v_temp number (1); v_count binary_integer: = 0; v_sal number (4000.00): =; v_date date: = sysdate; v_pi constant number (3, 2): = 3.14; v_valid boolean: = false; v_name varchar2 (20) not null: = 'myname '; begin dbms_output.put_line ('v _ temp value' | v_temp); (| connector) end;/use '--' to comment out a section/**/dbms_output.put_line () boolean variables cannot be printed using the % type attribute: declare (variable declaration type varies according to the table type) v_empno number (4); v_empno2 emp. empno % type; v_empno3 v_empno2 % type; begin dbms_output.put_line ('test'); end; composite variable Declaration: First: Table variable type (equivalent to java array) declare type type_table_emp_empno is table of emp. empno % type index by binary_integer; v_empnos type_table_emp_empno; begin v_empnos (0): = 7369; v_empnos (2): = 7839; v_empnos (-1): = 9999; -- (subscript can be smaller than 0) (comment) dbms_output.put_line (v_empnos (-1); end; Record variable type: (equivalent to java class) declare type type_record_dept is record (deptno dept. deptno % type, dname dept. dname % type, loc dept. loc % type); v_temp type_record_dept; begin v_temp.deptno: = 50; (equivalent to referencing to access the member variable) v_temp.dname: = 'aaa'; v_temp.loc: = 'bj '; declare (v_temp.deptno | ''| v_temp.dname); end; Use % rowtype to declare the record variable; declare v_temp dept % rowtype; begin v_temp.deptno: = 50; v_temp.dname: = 'aaa '; v_temp.loc: = 'bj '; dbms_output.put_line (v_temp.deptno | ''| v_temp.dname); end; Application of SQL (select) Statements in PlSQL: declare v_ename emp. ename % type; v_sal emp. sal % type; begin -- the select statement in plsql statement must contain into, and the return record must be 'select ename, sal into v_ename, v_sal from emp where empno = 7369; values (v_ename | ''| v_sal); end; declare v_emp emp % rowtype; begin select * into v_emp from emp where empno = 7369; dbms_output.put_line (v_emp.empno); end; application of other SQL statements in plsql: declare v_deptno dept. deptno % type: = 50; v_dname dept. dname % type: = 'aaa'; v_loc dept. loc % type: = 'bj '; begin -- insert value; insert into dept2 values (v_deptno, v_dname, v_loc); commit; end; declare v_deptno emp2.deptno % type: = 10; v_count number; begin update emp2 set sal = sal/2 where deptno = v_deptno; -- select deptno into v_deptno from emp2 where empno = 7369; -- select count (*) into v_count from emp2; -- SQL indicates the statement that has just been executed (the number of records affected after this statement is executed) dbms_output.put_line (SQL % rowcount | 'records affected '); commit; end;