First, write anonymous blocks and execute
The previous article describes The type of several blocks of PL/SQL, where anonymous blocks are an instant execution block, using sql*plus to demonstrate how to create an anonymous block:
Sql> Show User
--Display the current user is "HR"
sql>
1 DECLARE 2 v_fname VARCHAR2 (20); --declare section, the following article will be detailed in the naming rules 3 BEGIN 4 SELECT first_name 5 into V_fname 6 from Employees 7 WHERE employee_id=100; 8 END; 9/--to end the writing of PL/SQL in Sql*plus, use the slash/PL/SQL procedure successfully completed. --Prompt Execution success
Second, display the execution results on the screen
Although the prompt execution succeeds, we cannot see the result of the execution, so you can use the Set command to set the output effect.
First Use the Help set command to see how the set is used:
Sql> Help Set
SET --- sets a system variable to alter the sql* plusenvironment settings for your currentsession. for example, to: - set the display width for data - customize HTML formatting - enable or disable printing of columnheadings - set the number of lines per page set system_ variablevalue where system_variableand value represent one of the following clauses: blo[ckterminator]{.| c| on| off} recsepchar {_|c} cmds[ep]{;|c| Off| on} serverout[put] {on| off} -- set whether the server side displays results COLSEP{_|text} [SIZE{n | UNLIMITED}] -- displays the size of the bufferLittle con[cat]{.| c| on| off} [for[mat] {wra[pped] |
Sql> set Serveroutput on
-- Turn on the screen Output
Sql> L
--Use the L command to extract the last executed statement from the SQL command history 1 DECLARE 2 V_fname VARCHAR2 (20); 3 BEGIN 4 SELECT first_name 5 into V_fname 6 from Employees 7 WHERE employee_id=100; 8* END;
Sql>/
PL/SQL procedure successfully completed.--still does not see the output, this is because the previous anonymous block does not define the output results, so you need to rewrite the---block.
Third, call dbms_output. Put_Line () Show output results
Sql>
1 DECLARE 2 v_fname VARCHAR2 (20); 3 BEGIN 4 SELECT first_name 5 into V_fname 6 from Employees 7 WHERE employee_id = 100; 8 Dbms_output. Put_Line (' The result is ' | | V_fname);--Use the method in package Dbms_output to put_line output (similar to printf () in c)--but use dbms_output. Before Put_Line (), you must make sure that Serveroutput is set to On-where | | 9 END for hyphen; 10/the result is steven--can see the output as Steven. PL/SQL procedure successfully completed.
The above is an anonymous block creation process.
This article is from the "Big sword without front of the great Qiao Not Work" blog, please make sure to keep this source http://wuyelan.blog.51cto.com/6118147/1538784