Oracle basics of PL/SQL programming

Source: Internet
Author: User
-- PL/SQL language -- string connector | select 'abc' | '000000' from dual; -- constants and variables declare -- <-- used to define variables, constants, cursors, and custom data types stu_name nvarchar2 (4); begin -- <-- execution statement start stu_name: = 'lu'; --: = value assignment symbol dbms_output.put_line (stu_name); end; -- <-- execution statement end declare PI constant number: = 3.1415926; -- constant is used to define constants -- Define the Data Type declare type student is record (-- <-- the allowed data types include record and table varray (Variable Length array) name nvarchar2 (20), sex char (2), age INT); stul student; -- <-- The stulbeginstul variable is defined here. name: = 'text'; dbms_output.put_line (stul. name); end; -- if... else statement declare I number; -- defines the number type variable ibegin I: = 1; if I <18 then dbms_output.put_line ('less than 18 '); else NULL; -- null statement, do not execute anything. It plays a placeholder role: end if; end; -- if... elsif... else statement declarei number; begin I: = 40; if I <18 then dbms_output.put_line ('less than 18 '); elsif I> 18 and I <30 then dbms_output.put_line ('less than 30'); else dbms_output.put_line ('outside the scope of Statistics '); end if; end; -- case statement declare C char (2); begin C: = 'C '; case C -- <-- it can be the expression when 'a 'then dbms_output.put_line ('You got A'); When 'B' then dbms_output.put_line ('You got B '); when 'C' then dbms_output.put_line ('You got C'); else dbms_output.put_line (' sorry, you didn't pass '); End case; end; -- loop declare I number; begin I: = 1; loop dbms_output.put_line (I); I: = I + 1; exit when I> 5; exit when I> 10; -- <-- exit can have multiple statements. If not written, it is an endless loop end loop; end; -- while loop declare I number; begin I: = 0; while I <10 loop dbms_output.put_line (I); I: = I + 1; end loop; end; -- For Loop declare I number; SUMI number; begin I: = 0; SUMI: = 100; for I in 1... 100 loop SUMI: = SUMI + I; dbms_output.put_line (SUMI); End loop; dbms_output.put_line (SUMI); end;

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.