Oracle PL/SQL Programming syntax

Source: Internet
Author: User

--PLSQL block structure, calculate a, B andDeclareaint:=Ten; bint:= -; cint; beginC:=A+b;   Dbms_output.put_line (c); End;--%type data type, output employee name and job title informationDeclarevar_ename Scott.emp.ename%type;var_job scott.emp.job%type;begin  SelectEname,job intoVar_ename,var_job fromscott.empwhereEmpno=7369; Dbms_output.put_line (Var_ename||''s duties are:'||var_job); End;--Record TypeDeclaretype Emp_type isRecord (Var_enamevarchar2( -), Var_jobvarchar2( -), Var_sal Number); Empinfo Emp_type;begin  SelectEname,job,sal intoEmpinfo fromscott.empwhereEmpno=7369;  Dbms_output.put_line (Empinfo.var_ename); End;--%rowtype Data TypesDeclarerowvar_emp scott.emp%RowType;begin  Select *    intorowvar_emp fromscott.empwhereEmpno=7369;    Dbms_output.put_line (Rowvar_emp.ename); End;----------------------------------------------------------------Process Control--------------------------------------------------- -----------If ... then compare string lengths, output long stringsDeclarevar_name1varchar2( -); Var_name2varchar2( -); beginvar_name1:='dog100'; Var_name2:='dog232332'; ifLength (var_name1)>Length (var_name2) ThenDbms_output.put_line (VAR_NAME1); ElseDbms_output.put_line (var_name2); End if; End; --Case output month of the season Declareseasonint:=2; infovarchar2( -); begin    Caseseason when 1  ThenInfo:=' the';  when 2  ThenInfo:='4,5,6';  when 3  ThenInfo:='7,8,9';  when 4  ThenInfo:='10,11,12'; ElseInfo:='Dog'; End  Case;  Dbms_output.put_line (info); End;-------------------------------------------------------------------Loop Statement------------------------------------------------ -----------Loop calculates the sum of 1 to 100 natural numbersDeclaresum_iint:=0; Iint:=0;beginLoop i:=I+1; Sum_i:=Sum_i+i; Exit  whenI= -; EndLoop;    Dbms_output.put_line (sum_i); End; -- whileDeclaresum_iint:=0; Iint:=0;begin   whileI<= -Loop sum_i:=Sum_i+i; I:=I+1; EndLoop;    Dbms_output.put_line (sum_i); End;-- forDeclaresum_iint:=0;begin   forIinch Reverse 1.. -Loop sum_i:=Sum_i+i; EndLoop;    Dbms_output.put_line (sum_i); End;--------------------------------------------------------------------Cursor------------------------------------------------- --explicit cursors, reading employee information Declare cursorCur_emp (var_jobinch varchar2:='salesman')  is SelectEmpno,ename,sal fromscott.empwhereJob=var_job; type record_emp isrecord (Var_empno scott.emp.empno%type, Var_ename scott.emp.ename%type, var_sal scott.emp.sal%type); Emp_row record_emp; begin   OpenCur_emp ('MANAGER'); FetchCur_emp intoEmp_row;  whileCur_emp%found Loop dbms_output.put_line (emp_row.var_ename); FetchCur_emp intoEmp_row; EndLoop; Closecur_emp; End;--implicit cursors, wage increases 20%beginUpdatescott.empSetSal=Sal*(1+0.2)whereJob='salesman';ifSql%NotFound ThenDbms_output.put_line ('No'); Elsedbms_output.put_line (SQL%RowCount); End if; End;--loop a cursor through a For loop statement, an implicit cursorbegin    forEmp_recordinch(Select *  fromScott.empwhereJob='salesman') Loop Dbms_output.put_line (Emp_record.ename); EndLoop; End;--loop a cursor through a For Loop statement, an explicit cursor Declare cursorCursor_emp is Select *  fromScott.empwhereJob='salesman'; begin    forEmp_recordinchcursor_emp Loop Dbms_output.put_line (emp_record.ename); EndLoop; End;---------------------------------------------------------------------------------------------                

Oracle PL/SQL Programming syntax

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: info-contact@alibabacloud.com 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.