Use Oracle SQL Developer to compile and run PL/SQL Blocks

Source: Internet
Author: User

First, popularize the basic concepts:

PL/SQL is a programming Language that combines Procedural Language and Structured Query Language (SQL.

The PL/SQL block corresponds to a small piece of code.

Applicable instructions:

1. Sometimes you may need to combine and view a lot of table data. If you cannot achieve the goal through multi-table queries and join, you can consider using it.

2. data needs to be updated and can be used to delete data.

3. You can use it to record query and update logs.

....


Let's look at the example.


[SQL]
  1. DeclareSRight varchar2 (60 );
  2. Icount number (4 );
  3. Begin
  4. ForCurTableIn(SelectColnameAsSvalueFromTable1WhereCol2 ='Test')
  5. Loop
  6. Select Count(Colname)IntoIcountFromMtdv2docWhere Right= CurTable. svalue;
  7. If icount> 2Then
  8. Dbms_output.put_line (curTable. svalie );
  9. EndIf;
  10. EndLoop;
  11. End;

Note:

1. Place the variable part after declare.

2. Start with begin and end with end

3. for/loop/end loop for loop

4. if/then/end if Condition Statement

5. dbms_output.put_line () print data to the console


The next step is how to execute this section in Oracle SQL Developer and see the results.

1. Enter the user name/password to log on to a database. Enter the code in worksheet.

2. Switch to "DBMS Output" in the Output tab below"

3. Click a message-like icon and the console outputs set serveroutput on.

4. Run the code block and the output will be below it.

5. Click a pen-like icon to clearly understand the content of the console.

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.