2018-07-1216:41:19
1 Six, anonymous block2 1, define anonymous blocks:3 Declare 4Definition section;---optional Section5 begin6Executive section;---Required Section7 Exception8Exception handling Section;---optional Section9 End;Ten One ---Output Hello world to console A begin -Dbms_output.put_line ('Hello World'); - End; the ---turn on the console output switch F5 - SetServeroutput on; - - + ---Define variables, assign values to variables, output variable values - ---; + Declare Av_id Number(3); at begin -V_ID:=1; - Dbms_output.put_line (v_id); - End; - - ---query data output from database tables to the console in Declare -V_namevarchar2( -); toV_sal Number(7,2); + begin - SelectEname,sal intoV_name,v_sal fromEmpwhereEmpno=7788; theDbms_output.put_line (v_name||','||v_sal); * End; $ Panax Notoginseng &: Bring up input box to receive input data. - ---Query The salary of the specified employee the SelectSal fromEmpwhereEmpno=&No; + A ---Input String type the Select * fromEmpwhere Upper(ename)=UPPER('&name'); + - $ Declare $V_namevarchar2( -); -V_sal Number(7,2); - begin the SelectEname,sal intoV_name,v_sal fromEmpwhereEmpno=&No; -Dbms_output.put_line (v_name||','||v_sal);Wuyi Exception the whenNo_data_found Then -Dbms_output.put_line ('Sorry, the user you entered does not exist'); Wu End; - About ---%type: Use data type of a column in a database as the data type of a variable $syntax; table name. Column Name%type - - Declare -V_name Emp.ename%type; AV_sal Emp.sal%type; + begin the SelectEname,sal intoV_name,v_sal fromEmpwhereEmpno=&No; -Dbms_output.put_line (v_name||','||v_sal); $ Exception the whenNo_data_found Then theDbms_output.put_line ('Sorry, the user you entered does not exist'); the End; the - in ---%rowtype: Row data, using one of the behavior data types of a table in a database the Declare theV_emp EMP%RowType; About begin the Select * intoV_emp fromEmpwhereEmpno=&No; theDbms_output.put_line (v_emp.empno||','||v_emp.ename); the End; + - the Bayi
DAY16-dong Soft training. Oracle. Anonymous block