Basic PL/SQL programming (1) [output, connection characters, server output, comments, etc.]

Source: Internet
Author: User

Frequently used:
Value assignment: [: =]
Connection character: [|]
Output: dbms_out.put_line ('some text ');
 
1. The example of the output of the application variable assignment is as follows:
Declare
X varchar2 (10); -- declare a variable
Begin
X: = 'this is '; -- Colon equal sign assignment: =
Dbms_output.put_line (the value of 'x is '| x); -- double vertical bars | different data types can be connected and Output
End; -- pay attention to the semicolon
/
 
2. Run the set HELP Command [? Set]
3. set serveroutput on size 10000 to set the cache. The maximum value is 1000000.
4. Line comment :--
5. Block comments /**/
 
6. Case 2: Exercise connection Variables
Declare
X varchar2 (10): = 'this is ';
Y string (10): = 'value of y ';
Z varchar2 (20 );
Begin
Z: = x | y; -- connect two variables
Dbms_output.put_line (z); -- output
End;
/
 
 
7. Case 3 [if endif], with if judgment added.
 
DECLARE
A number;
B varchar2 (10 );
Begin
A: = 2;
If a = 1 then
B: = 'a ';
Elsif a = 2 then -- Here elsif is not elseif
B: = 'B ';
Else
B: = 'C ';
End if; -- endif do not forget
Dbms_output.put_line ('B's value is' | B );
End; -- the semicolon after end is also crucial. Do not forget
/
 
8. CASE 4 [case endcase] usage
 
Declare
A varchar2 (10 );
B number;
Begin
A: = 'a ';
Case -- start with case
When a = 'A' then B: = 1; -- embedded with many when then statements
When a = 'B' then B: = 2;
When a = 'C' then B: = 3;
Else
B: = 'others ';
End case; -- end of case with a semicolon
Dbms_output.put_line ('B's value is' | B );
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.