- Sample Of Pl
- Sample Of Pl Sql Programs
Comments in PL/SQL. Commenting code simply instructs the compiler to ignore that particular code from executing. Comment can be used in the program to increase the readability of the program. In PL/SQL codes can be commented in two ways. Using '--' in the beginning of the line to comment that particular line. Sample PL/SQL Programs 1) WRITE A PROGRAM TO PRINT HELLO WORLD. Write a program to accept the grade and display emps belongs to that grade? Embedded PL/SQL Sample 6. Calling a Stored Procedure Running the Programs. All the sample programs in this appendix and several others throughout this guide are available online. So, they are preceded by the following comment:-- available online in file ' You can find the online files in the PL/SQL demo directory.
It is a sample PL/SQL Oracle example using procedure. When create a procedure IN and OUT keyword used during pass parameters. IN is used to pass values to. These programs will help you to learn pl/sql programming. Hello World Program in PL/SQL. PL/SQL Program To Add Two Numbers. PL/SQL Program for Prime Number. PL/SQL Program to Find Factorial of a Number. PL/SQL Program to Print Table of a Number. PL/SQL Program for Reverse of a Number. PL/SQL Program for Fibonacci Series. In PL/SQL procedure you can have a RETURN statement. However, unlike the RETURN statement in the function that returns a value to calling program, the RETURN statement in the procedure is used only to halt the execution of the procedure and return control to the caller.
In this chapter, we will discuss the Basic Syntax of PL/SQL which is a block-structured language; this means that the PL/SQL programs are divided and written in logical blocks of code. Each block consists of three sub-parts −
S.No | Sections & Description |
---|
1 | Declarations This section starts with the keyword DECLARE. It is an optional section and defines all variables, cursors, subprograms, and other elements to be used in the program. |
2 | Executable Commands This section is enclosed between the keywords BEGIN and END and it is a mandatory section. It consists of the executable PL/SQL statements of the program. It should have at least one executable line of code, which may be just a NULL command to indicate that nothing should be executed. |
3 | Exception Handling This section starts with the keyword EXCEPTION. This optional section contains exception(s) that handle errors in the program. |
Every PL/SQL statement ends with a semicolon (;). PL/SQL blocks can be nested within other PL/SQL blocks using BEGIN and END. Following is the basic structure of a PL/SQL block −
The 'Hello World' Example
The end; line signals the end of the PL/SQL block. To run the code from the SQL command line, you may need to type / at the beginning of the first blank line after the last line of the code. When the above code is executed at the SQL prompt, it produces the following result −
The PL/SQL Identifiers
PL/SQL identifiers are constants, variables, exceptions, procedures, cursors, and reserved words. The identifiers consist of a letter optionally followed by more letters, numerals, dollar signs, underscores, and number signs and should not exceed 30 characters.
By default, identifiers are not case-sensitive. So you can use integer or INTEGER to represent a numeric value. You cannot use a reserved keyword as an identifier.
The PL/SQL Delimiters
A delimiter is a symbol with a special meaning. Following is the list of delimiters in PL/SQL −
Delimiter | Description |
---|
+, -, *, / | Addition, subtraction/negation, multiplication, division |
% | Attribute indicator |
' | Character string delimiter |
. | Component selector |
(,) | Expression or list delimiter |
: | Host variable indicator |
, | Item separator |
' | Quoted identifier delimiter |
= | Relational operator |
@ | Remote access indicator |
; | Statement terminator |
:= | Assignment operator |
=> | Association operator |
| Concatenation operator |
** | Exponentiation operator |
<<, >> | Label delimiter (begin and end) |
/*, */ | Multi-line comment delimiter (begin and end) |
-- | Single-line comment indicator |
. | Range operator |
<, >, <=, >= | Relational operators |
<>, '=, ~=, ^= | Different versions of NOT EQUAL |
The PL/SQL Comments
Program comments are explanatory statements that can be included in the PL/SQL code that you write and helps anyone reading its source code. All programming languages allow some form of comments.
The PL/SQL supports single-line and multi-line comments. All characters available inside any comment are ignored by the PL/SQL compiler. The PL/SQL single-line comments start with the delimiter -- (double hyphen) and multi-line comments are enclosed by /* and */.
Starship troopers terran ascendancy game logic factory. Your missile troopers, grenadiers and the marvellous micro-nukers must be given specific fire orders, so as not to fire a ball of instant, firey disintegration into the middle of a crowded combat zone and this occasionally leads them to wander off in odd directions when the fire order is given in order to find a direct line of sight to their target. Sadly, nobody follows them to provide cover and if you're not careful they tend to die before firing their ordnance.
When the above code is executed at the SQL prompt, it produces the following result −
PL/SQL Program Units
A PL/SQL unit is any one of the following −
- PL/SQL block
- Function
- Package
- Package body
- Procedure
- Trigger
- Type
- Type body
Each of these units will be discussed in the following chapters.
Select Query /
alias column8 | ALL1 |
AND5 | ANY1 |
Arithmetic Operators Query4 | AS2 |
BETWEEN AND10 | Calculation in Query6 |
Case Query19 | Char Case1 |
Char Compare2 | Column alias4 |
Column Concatenation5 | Column Names9 |
Comparison Operators6 | Date Add1 |
Date Calculation Query9 | Derive values1 |
DISTINCT9 | EXISTS4 |
GROUP BY17 | HAVING14 |
Like19 | Logical Operators4 |
Nesting Functions2 | NOT10 |
Null Value Calculation2 | Null Value Compare10 |
Null Value Concatanation2 | Number Format1 |
OR9 | Order By26 |
Query Date Compare3 | Query IN13 |
Query Select Columns7 | Quote5 |
rowid2 | ROWNUM10 |
Select18 | UNIQUE1 |
Where12 | Wild Card4 |
With2 |
Insert Delete Update /
Delete Subquery1 | DELETE WHERE6 |
INSERT Column Name8 | INSERT with Functions4 |
Insert with subquery8 | Update All2 |
UPDATE Set Clause9 | Update subquery3 |
UPDATE WHERE5 |
Subquery /
Correlated Subquery9 | Exists Subquery5 |
Subquery ALL4 | Subquery ANY4 |
Subquery Basics36 | Subquery IN10 |
update3 | Virtual Table3 |
Hierarchical Query /
Indent2 | Level7 |
Nodes Branches2 | Root2 |
SIBLINGS4 | Start With Connect3 |
sys_connect_by_path6 |
Table /
Add Column13 | Alter Table16 |
Change Column Size2 | Change Column Type1 |
chartorowid1 | Cluster8 |
Column Default Value8 | Comment Table5 |
Copy Table13 | Create Table25 |
CSV Load14 | CSV Table5 |
Database3 | Describe4 |
Drop Columns3 | Drop Table4 |
DUAL Table3 | External Table1 |
Merge4 | Rename Column1 |
Rename Table1 | Row Count1 |
ROWID2 | ROWNUM5 |
SAVEPOINT2 | SYNONYM1 |
Table Reference2 | Table space12 |
Table Statistics1 | Temporary Table17 |
Transaction Rollback Commit11 | TRUNCATE TABLE2 |
Table Joins /
ANSI SQL 92 Joins5 | Cartesian product3 |
Cross joins1 | Equijoins5 |
Full Outer Join2 | Inner Joins8 |
Left Outer Join6 | Natural join3 |
Outer Joins7 | Right Outer Joins6 |
Self Joins2 | Table Join Basics15 |
Table Join Column10 |
View /
Alter View2 | Create View12 |
Inline View1 | MATERIALIZED_VIEW3 |
Query View2 | Updatable View1 |
Update View1 |
Aggregate Functions /
Aggregate Functions Basics8 | AVG15 |
COUNT22 | GROUP Function3 |
MAX10 | MIN8 |
SUM14 |
Char Functions /
ASCII3 | ASCIISTR2 |
Char Length1 | CHR2 |
COMPOSE2 | CONCAT2 |
CONTAINS4 | Convert1 |
decompose1 | Dump7 |
I18N2 | INITCAP7 |
INSTR12 | LENGTH4 |
LOWER4 | LPAD7 |
LTRIM7 | NVL14 |
NVL24 | REPLACE10 |
RPAD6 | RTRIM4 |
SOUNDEX4 | String Concatenate1 |
SUBSTR10 | Translate10 |
TRIM11 | UNISTR3 |
UPPER3 | VSIZE3 |
Numeric Math Functions /
ABS8 | ACOS3 |
ASIN3 | ATAN2 |
ATAN22 | BIN_TO_NUM4 |
BITAND5 | CEIL6 |
COS4 | COSH3 |
EXP4 | FLOOR4 |
greatest6 | hextoraw1 |
least4 | LN2 |
LOG4 | MOD8 |
POWER7 | ROUND19 |
SIGN8 | SIN3 |
SINH2 | SQRT5 |
TAN3 | TANH3 |
TRUNC13 |
Analytical Functions /
Aggregrate Analytical21 | Analytical Functions Basics12 |
Centered Average1 | Compute3 |
connect by3 | Corr1 |
COVAR_POP1 | COVAR_SAMP1 |
Cube10 | CUME_DIST3 |
Cumulative Sum8 | CURRENTV2 |
DENSE_RANK13 | First Last Value11 |
First Last1 | GROUPING SETS2 |
GROUPING7 | GROUPING_ID4 |
IGNORE NAV KEEP NAV1 | IS PRESENT1 |
LAG LEAD10 | Measure3 |
MEDIAN2 | Model2 |
Moving Average1 | NTILE8 |
NULLs First3 | NULLs Last5 |
Over11 | PARTITION14 |
percentile_cont1 | PERCENTILE_DISC1 |
PERCENT_RANK4 | PRESENTV1 |
Range3 | Rank Row1 |
Rank12 | Ratio Portion1 |
RATIO_TO_REPORT6 | REGR_AVGX2 |
REGR_AVGY1 | REGR_COUNT2 |
REGR_INTERCEPT2 | REGR_R22 |
REGR_SLOPE2 | REGR_SXX2 |
REGR_SXY2 | REGR_SYY3 |
Rollup12 | ROW_NUMBER11 |
RULES UPDATE1 | Start With3 |
STATS_MODE1 | STATS_WSR_TEST3 |
STDDEV2 | STDDEV_POP1 |
STDDEV_SAMP1 | Sum5 |
Top Values1 | UNBOUNDED FOLLOWING1 |
VARIANCE2 | VAR_POP1 |
VAR_SAMP1 |
PL SQL /
APPEND1 | Arithmetic Operators1 |
Begin End Block15 | Between and4 |
Boolean Expression4 | Break2 |
CARDINALITY3 | Case10 |
Char to Number1 | Char Varchar Compare5 |
Column Type Variable2 | Comments3 |
Compile Error10 | Concatenation Operator1 |
Conditional_compilation1 | Console Prompt Read4 |
Constant Number5 | Data Insert14 |
Data Type Convert10 | Data Type Define2 |
Date Calculation2 | DATE Compare2 |
Date Convert2 | DBMS_OUTPUT4 |
Decode6 | Default Value3 |
Define3 | Delete Data8 |
Dump1 | Errors Table1 |
Exception Handle24 | Exception Range5 |
Execute Immediate24 | EXIT9 |
For Loop27 | FORALL5 |
GOTO6 | Handle Exception5 |
IF20 | IN5 |
Index by Table5 | Insert Data4 |
IS6 | Label6 |
LIKE2 | Loop7 |
MEMBER OF3 | Multi line Command1 |
MULTISET7 | Not Null Variable2 |
NULL Statement3 | Null Value3 |
Number to Char4 | Object Type5 |
Operator1 | Output Print2 |
Package30 | Pause1 |
Predefined Exceptions6 | Print1 |
Program Block4 | Prompt1 |
Raise10 | Record Data Type14 |
Repeat Until2 | RETURNING Into2 |
rowtype13 | Select Into26 |
Server Output1 | Set2 |
SQL FOUND1 | SQL ISOPEN1 |
SQL ROWCOUNT1 | sqlcode3 |
SQLERRM8 | SUBMULTISET3 |
subtype2 | Table of Char5 |
Table of Column1 | Table of Date1 |
Table of number26 | Table of Object1 |
Table of rowtype5 | Table of Type18 |
Table of Varchar228 | Timing PL SQL2 |
Transaction9 | Type8 |
Update Data17 | Utility Package7 |
Varchar Table4 | Variable Declare6 |
Variable Default Value2 | Variable init4 |
Variable Scope9 | Variable4 |
varray41 | When3 |
While Loop17 | Your own Exception7 |
Data Type /
bfile2 | Binary Data Type5 |
blob5 | Boolean7 |
Cast1 | CHAR13 |
Clob23 | Date30 |
EXCEPTION2 | httpuritype3 |
Integer4 | INTERVAL6 |
IS INFINITE1 | IS NAN1 |
IS NULL Value2 | LOB1 |
Long7 | National Char2 |
nclob2 | NULL3 |
Number Type24 | Numeric Formatting19 |
PLS_INTEGER8 | TIMESTAMP22 |
TO_BINARY_DOUBLE1 | TO_BINARY_FLOAT1 |
TO_Char Date16 | TO_CHAR Number6 |
TO_CLOB2 | TO_Date6 |
TO_MULTI_BYTE1 | TO_NCHAR1 |
TO_NCLOB1 | TO_NUMBER4 |
TO_SINGLE_BYTE1 | VARCHAR220 |
Cursor /
Close Cursor7 | Cursor Fetch20 |
CURSOR FOR Loop11 | Cursor FOUND6 |
Cursor ISOPEN2 | Cursor Not Found11 |
Cursor Open6 | Cursor parameters8 |
Cursor ROWCOUNT7 | Cursor Update3 |
Cursor Value13 | Explicit Cursor12 |
Implicit Cursor14 | Nested Cursor2 |
ref cursor5 | Reference Cursor7 |
sys_refcursor4 |
Result Set /
Intersect6 | Loop Result set1 |
Minus8 | Union all5 |
UNION13 |
Regular Expressions /
alnum1 | Alpha3 |
Brackets4 | Case3 |
Control Letter1 | Digit4 |
Escape1 | Group5 |
NOT4 | OR2 |
Punct Print2 | Range1 |
REGEXP_INSTR16 | REGEXP_LIKE5 |
REGEXP_REPLACE3 | REGEXP_SUBSTR3 |
Repeat Operator4 | Space1 |
Wild Card15 | Word Start End4 |
Date Timezone /
ADD_MONTHS7 | CURRENT_DATE1 |
CURRENT_TIMESTAMP4 | Date Default Format7 |
Date Format19 | Date Time Interval2 |
Day Calculation1 | DBTIMEZONE2 |
EXTRACT10 | FROM_TZ1 |
INTERVAL6 | LAST_DAY8 |
LOCAL TIME ZONE2 | LOCALTIMESTAMP1 |
MONTHS_BETWEEN11 | NEW_TIME3 |
NEXT_DAY7 | NLS_DATE_FORMAT1 |
numtodsinterval8 | numtoyminterval5 |
ROUND Date7 | SESSIONTIMEZONE3 |
SYSDATE11 | SYSTIMESTAMP4 |
Time Zone7 | Timestamp12 |
TO_DATE5 | TO_DSINTERVAL3 |
TO_TIMESTAMP5 | TO_TIMESTAMP_TZ2 |
TO_YMINTERVAL5 | TRUNC Date10 |
TZ_OFFSET2 |
Sequence /
Alter Sequence1 | Create Sequence5 |
Drop Sequence1 | Sequence Increment2 |
Sequence Properties3 | Sequence Start1 |
Sequence Value9 |
Index /
Alter Index1 | Create Index19 |
Drop Index1 | Index STATISTICS4 |
Rename Index1 |
Constraints /
Add Check Constraint1 | Add Constraint4 |
Add Foreign Key6 | Add Primary Key11 |
Alter Constraints1 | Constraint Check21 |
Constraint Types2 | Contraint Name3 |
Create Foreign Key6 | Create Primary Key7 |
Defer Constraint2 | DELETE CASCADE1 |
DELETE SET NULL2 | Drop Cascade2 |
Drop Constraint3 | Drop Foreign Key3 |
Drop Primary Key1 | Enable Disable Primary Key2 |
Foreign Key2 | Name for Primary Key1 |
NOT NULL8 | Primary Key4 |
Unique9 |
Stored Procedure Function /
Autonomous_transaction4 | Call6 |
Default Parameter Value4 | exec3 |
Function Call8 | Function Definition16 |
Function Parameters12 | Function Return15 |
Insert7 | NOCOPY2 |
Overload2 | Parameter IN5 |
Parameter OUT11 | PIPELINED3 |
Procedure Call13 | Procedure Definition21 |
Procedure Function Body2 | Procedure Parameters21 |
Reference Your Function1 | Show Error2 |
Utility Function8 | Utility Procedure9 |
Trigger /
After Delete Trigger2 | After Insert Trigger4 |
After Update Trigger2 | Audit Log Table8 |
Before Delete Trigger1 | Before Insert Trigger4 |
Before Trigger3 | Before Update Trigger3 |
Business Logic Trigger6 | Create Trigger16 |
Database Trigger11 | Disable Trigger5 |
Drop Trigger1 | Enable Trigger3 |
Log Trigger2 | Old New Value8 |
Schema Trigger4 | Trigger Error2 |
Trigger Firing2 | Trigger on View2 |
Triggerable Actions2 |
Object Oriented Database /
Alter Type3 | Attribute2 |
Cast2 | Comparable5 |
Constructor7 | Cursor2 |
Delete1 | DEREF1 |
final1 | Insert11 |
NOT INSTANTIABLE1 | Object Column11 |
Object Method11 | Object Table Insert3 |
Object Table19 | Object View2 |
Object18 | Ref6 |
Reference Object3 | Select12 |
Self2 | table function2 |
Table4 | treat2 |
Type Body8 | Type Combination3 |
Type Hierarchy5 | Update7 |
Value Function1 | value1 |
Varray2 | Where1 |
Large Objects /
bfile7 | blob1 |
Directory2 | EMPTY_BLOB1 |
empty_clob1 | HEXTORAW2 |
Insert2 | Update1 |
Conversion Functions /
CAST5 | chartorowid1 |
COALESCE3 | CONVERT1 |
DECODE18 | NULLIF3 |
ROWIDTOCHAR2 | TO_CHAR10 |
TO_Number5 |
User Previliege /
Alter User3 | AUDIT2 |
Column Privileges1 | Create User4 |
Current_User4 | Drop User3 |
Grant Permission11 | Lock Unlock Account2 |
outline4 | PROFILE1 |
Revok Roles1 | Revoke Permission3 |
REVOKE REFERENCES1 | Role10 |
schema1 | Sequence privileges1 |
SESSION privileges3 | Synonym8 |
System Privileges3 | Table privileges5 |
UID1 | User Password8 |
View privileges1 |
System Tables Views /
all_arguments1 | ALL_CATALOG1 |
all_col_privs1 | all_indexes1 |
all_ind_columns1 | all_objects2 |
ALL_SEQUENCES1 | ALL_SYNONYMS1 |
ALL_TABLES2 | all_tab_columns2 |
all_tab_privs1 | ALL_TRIGGERS1 |
all_users2 | CAT2 |
DBA_AUDIT_OBJECT6 | DBA_AUDIT_SESSION5 |
dba_coll_types1 | dba_col_privs1 |
DBA_DATA_FILES2 | dba_ddl_locks1 |
dba_dependencies2 | DBA_EXTENTS4 |
dba_external_tables1 | DBA_INDEXES2 |
dba_job1 | DBA_JOBS_RUNNING1 |
dba_lobs1 | dba_locks2 |
dba_method_result1 | dba_objects6 |
DBA_OBJECT_SIZE1 | dba_object_tables1 |
dba_outlines1 | dba_procedure1 |
dba_profiles1 | dba_resumable1 |
dba_roles1 | dba_role_privs4 |
dba_rsrc_consumer_groups1 | dba_rsrc_plan_directives1 |
dba_source1 | DBA_SYNONYMS1 |
dba_sys_privs3 | DBA_Tables5 |
dba_tablespaces1 | DBA_TAB_COLUMNS2 |
dba_tab_comments1 | dba_tab_privs3 |
DBA_TAB_SUBPARTITIONS1 | dba_triggers1 |
dba_types1 | dba_type_attributes1 |
dba_type_method1 | dba_updatable_columns1 |
dba_users7 | dba_views1 |
db_object_cache1 | dict1 |
dictionary1 | global_name2 |
obj1 | open_cursor1 |
option1 | parameter5 |
pgastat1 | process3 |
ROLE_SYS_PRIVS1 | ROLE_TAB_PRIVS2 |
RSRC_CONSUMER_GROUP1 | session3 |
session_event1 | session_role1 |
sgastat1 | sql2 |
sqltext1 | sys.aux_stats1 |
sys.col4 | SYS_EXTRACT_UTC1 |
sys_nc_rowinfo1 | tab1 |
timezone_names1 | USER_CATALOG2 |
user_col_comments1 | USER_COL_PRIVS_MADE1 |
USER_COL_PRIVS_RECD1 | USER_CONSTRAINTS4 |
user_cons_columns2 | user_dependencies5 |
USER_ERRORS3 | user_indexes2 |
user_ind_columns4 | USER_JOBS3 |
USER_OBJECTS23 | user_object_size1 |
user_outlines1 | user_outline_hints2 |
USER_ROLE_PRIVS2 | user_segments3 |
USER_SEQUENCES2 | user_source3 |
USER_SYNONYMS1 | USER_SYS_PRIVS1 |
USER_TABLES9 | USER_TAB_COLUMNS1 |
USER_TAB_COMMENTS1 | user_tab_privs1 |
USER_TAB_PRIVS_MADE2 | USER_TAB_PRIVS_RECD1 |
user_triggers5 | user_types1 |
user_unused_col_tabs1 | USER_UPDATABLE_COLUMNS1 |
user_users1 | USER_VIEWS5 |
version1 | v_buffer_pool1 |
V_Controlfile1 | V_DATAFILE1 |
V_dbfile1 | V_db_cache_advice1 |
V_FIXED_TABLE1 | V_instance4 |
V_lock1 | V_logfile1 |
V_log_history1 | V_nls_parameters1 |
V_Object_Usage1 | V_Parameter5 |
V_pga_target_Advice1 | V_Rollname2 |
V_SESSION3 | V_SGA1 |
v_sgastat2 | V_sql2 |
V_sqlarea1 | V_statistics_level1 |
V_statname3 | v_Sysstat1 |
V_Waitstat1 |
System Packages /
DBMS_ALERT6 | dbms_application_info4 |
DBMS_AQADM3 | dbms_crypto8 |
DBMS_DB1 | dbms_ddl1 |
DBMS_DEBUG1 | DBMS_FGA1 |
DBMS_FILE_TRANSFER1 | dbms_flashback3 |
dbms_job8 | dbms_lob17 |
dbms_lock1 | DBMS_METADATA2 |
DBMS_OBFUSCATION_TOOLKIT6 | dbms_output16 |
DBMS_PIPE13 | DBMS_RANDOM12 |
DBMS_REDEFINITION1 | DBMS_REPAIR4 |
dbms_rowid7 | dbms_scheduler1 |
DBMS_SESSION1 | dbms_space1 |
dbms_sql27 | dbms_stats12 |
DBMS_TRACE2 | dbms_utility15 |
DBMS_WARNING2 | dbms_xmlquery1 |
dbms_xmlschema2 | htp1 |
ORA Error13 | ORA18 |
outln_pkg1 | TEXT_IO1 |
UTL_COMPRESS1 | UTL_FILE9 |
UTL_HTTP1 | utl_i18n1 |
UTL_INADDR1 | UTL_MAIL1 |
utl_raw27 | UTL_SMTP1 |
UTL_TCP1 |
Report Column Page /
COLSEP1 | Column Format Clear1 |
Column Heading Name1 | Column Heading Size1 |
Column Length1 | Column Number Format7 |
Column Word Wrap1 | Heading1 |
Line size2 | Line Width1 |
Page Size2 |
Sample Of Pl
SQL Plus /
Accept7 | all_policies1 |
Analyze24 | autotrace23 |
break2 | Column25 |
compute1 | define3 |
Edit1 | editor2 |
Environment Variables2 | explain plan4 |
Feedback2 | flashback1 |
Get1 | linesize1 |
Login2 | long2 |
markup html4 | numformat1 |
pagesize4 | pause5 |
Prompt4 | Query Rewrite1 |
Quit1 | recyclebin2 |
Run1 | Save3 |
SERVEROUTPUT6 | Session variable43 |
SGA1 | show3 |
Skip1 | space1 |
SPOOL5 | Start2 |
sys_context3 | Timing11 |
Title3 | USERENV2 |
variable9 |
XML /
Sample Of Pl Sql Programs
ExistsNode4 | UPDATEXML5 |
xdburitype1 | XML Save1 |
xmlattributes2 | XMLElement2 |
xmlforest1 | XMLType18 |
xpath8 |