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]
- DeclareSRight varchar2 (60 );
- Icount number (4 );
- Begin
- ForCurTableIn(SelectColnameAsSvalueFromTable1WhereCol2 ='Test')
- Loop
- Select Count(Colname)IntoIcountFromMtdv2docWhere Right= CurTable. svalue;
- If icount> 2Then
- Dbms_output.put_line (curTable. svalie );
- EndIf;
- EndLoop;
- 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.