The Code:
Declare |
The Output:
| Stmt# 1 Stmt# 2 Test Text |
Declare |
| Stmt# 1 Stmt# 2 Test Text |
| pPrint.SQL |
|---|
| Create Or Replace Procedure pPrint (Print_String In Varchar2) Is Begin Dbms_Output.Put_Line(Print_String); End; / |
| Begin pPrint ('apple'); End; / |
/*---------------------------------------------------*/
/* Example 1: Create an anonymous block */
/*---------------------------------------------------*/
Declare
vShopList Varchar2(25) := 'Apples';
Begin
Dbms_Output.Put_Line ('Buy more '||vShopList);
End;
/
Buy more Apples
/*---------------------------------------------------*/
/* Example 2: Change to a procedure and execute */
/*---------------------------------------------------*/
Create or Replace Procedure pShopList
is
vShopList Varchar2(25) := 'Apples';
Begin
Dbms_Output.Put_Line ('Buy more '||vShopList);
End;
/
Procedure created.
/*-----------------------------------------------*/
/* Run procedure */
/*-----------------------------------------------*/
Begin
pShopList;
End;
/
Buy more Apples
/*---------------------------------------------------*/
/* 3. Change procedure to accept parameter */
/*---------------------------------------------------*/
Create or Replace Procedure pShopList
(vShopList Varchar2)
is
Begin
Dbms_Output.Put_Line ('Buy more '||vShopList);
End;
/
Procedure created.
/*-----------------------------------------------*/
/* Run procedure with input parameter */
/*-----------------------------------------------*/
Begin
pShopList ('Bananas');
End;
/
Buy more Bananas
Create Table Accounts
( Acct Number(5)
, Amt Number(8,2)
);
Create Or Replace
Procedure Cr_Acct /* Spec */
( Acct In Integer,
Amt In Real)
As
Begin /* Body */
Insert Into Accounts
Values (Acct, Amt);
End Cr_Acct;
/
Select *
From User_Source
Where Name = 'CR_ACCT';Declare
Acct_Id Number := &Id;
Amt Number := &Deposit;
Begin
Cr_Acct(Acct_Id, Amt);
End;
/
Select * From Accounts;