473,382 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,382 developers and data experts.

Using PRAGMA - II

debasisdas
8,127 Expert 4TB
This thread contains some useful tips/sample codes regarding some of advance concepts in Use of PRAGMA in oracle, that the forum members may find useful.

PRAGMA EXCEPTION_INIT
====================
This is used to bind a user defined exception to a particular error number.

For example: To display USER DEFINED MESSAGE FOR ORACLE DEFINED NUMBER
---------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. I EXCEPTION;
  3. PRAGMA EXCEPTION_INIT(I,-00001);
  4. BEGIN
  5. INSERT INTO DEPT VALUES(&DNO,'&DNAME','&LOC');
  6. DBMS_OUTPUT.PUT_LINE('ONE RECORD INSERTED');
  7. EXCEPTION
  8. WHEN I THEN
  9. DBMS_OUTPUT.PUT_LINE('DUPLICATE VALUE');
  10. END;
  11.  
Few more predefined number for predefined exception
========================================

dup_val_on_index, -0001
timeout_on_resource, -0051
invalid_cursor, -1001
not_logged_on, -1012
login_denied, -1017
too_many_rows, -1422
zero_divide, -1476
invalid_number, -1722
storage_error, -6500
program_error, -6501
value_error, -6502
rowtype_mismatch, -6504
cursor_already_open, -6511
access_into_null, -6530
collection_is_null , -6531
subscript_outside_limit, -6532
subscript_beyond_count , -6533
Jun 16 '07 #1
2 11468
debasisdas
8,127 Expert 4TB
RESTRICT_REFERENCES Pragma
===========================
This pragma was used to assert to the PL/SQL compiler the purity level of a packaged procedure or function. The RESTRICT_REFERENCES pragma had to be included in the package specification if you were to use that program inside a SQL statement (directly or indirectly).

This is not required starting with Oracle8i.

This pragma confirms to Oracle database that the function as the specified side-effects or ensures that it lacks any such side-effects.

Usage is as follows:

PRAGMA RESTRICT_REFERENCES(function_name, WNDS [, WNPS] [, RNDS], [, RNPS])

WNDS: Writes No Database State. States that the function will not perform any DMLs.

WNPS: Writes No Package State. States that the function will not modify any Package variables.

RNDS: Reads No Database State. Analogous to Write. This pragma affirms that the function will not read any database tables.

RNPS: Reads No Package State. Analogous to Write. This pragma affirms that the function will not read any package variables.

You can declare the pragma RESTRICT_REFERENCES only in a package spec or object type spec. You can specify up to four constraints (RNDS, RNPS, WNDS, WNPS) in any order. To call the function from parallel queries, you must specify all four constraints. No constraint implies another. For example, WNPS does not imply RNPS.

When you specify TRUST, the function body is not checked for violations of the constraints listed in the pragma. The function is trusted not to violate them.

If you specify DEFAULT instead of a function name, the pragma applies to all functions in the package spec or object type spec (including, in the latter case, the system-defined constructor). You can still declare the pragma for individual functions. Such pragmas override the default pragma.

A RESTRICT_REFERENCES pragma can apply to only one function declaration. So, a pragma that references the name of overloaded functions always applies to the nearest foregoing function declaration.

syntax
========
Expand|Select|Wrap|Line Numbers
  1. PRAGMA RESTRICT_REFERENCES ( 
  2.     function_name, WNDS [, WNPS] [, RNDS] [, RNPS] [, TRUST] );
  3.  
In the following example, the pragma applies to the second declaration of isok:
Expand|Select|Wrap|Line Numbers
  1. CREATE PACKAGE showrec AS
  2.    FUNCTION isok (amount NUMBER) RETURN BOOLEAN;
  3.    FUNCTION isok (net_time DATE) RETURN BOOLEAN;
  4.    PRAGMA RESTRICT_REFERENCES (isok, WNDS);
  5.    ...
  6. END showrec;
  7.  
DEFAULT
----------------
This specifies that the pragma applies to all functions in the package spec or object type spec. You can still declare the pragma for individual functions. Such pragmas override the default pragma.
Jun 16 '07 #2
debasisdas
8,127 Expert 4TB
SERIALLY_REUSABLE:
====================
This pragma lets the PL/SQL engine know that package-level data should not persist between reference to that data.

Package data (global variables in package specification etc.) by default persists for an entire session (or until a package is recompiled). Globally accessible data structures can cause some side effects. For instance, what if a cursor is left open in a package. In addition, a program can use up lots of real memory (UGA) and then not release it if the data is stored in a package-level structure.

In order to manage this, Oracle8i introduced the SERIALLY_REUSABLE pragma. This pragma is used in packages only and must be defined BOTH in specification and in the body. A bodiless package can be marked as serially reusable. If a package has a spec and body, you must mark both. You cannot mark only the body.

The global memory for serially reusable packages is pooled in the System Global Area (SGA), not allocated to individual users in the User Global Area (UGA). That way, the package work area can be reused. When the call to the server ends, the memory is returned to the pool. Each time the package is reused, its public variables are initialized to their default values or to NULL.

The advantage is that based on the pragma, a package state can be reduced to a single call of a program unit in the package as opposed to the package being available for the whole session.

Note :---Serially reusable packages cannot be accessed from database triggers.

SAMPLE CODE OF PRAGMA SERIALLY_REUSABLE;
===========================================
Expand|Select|Wrap|Line Numbers
  1. CREATE PACKAGE pkg1 IS
  2.    PRAGMA SERIALLY_REUSABLE;
  3.    num NUMBER := 0;
  4.    PROCEDURE init_pkg_state(n NUMBER);
  5.    PROCEDURE print_pkg_state;
  6. END pkg1;
  7.  
  8. CREATE PACKAGE BODY pkg1 IS
  9.    PRAGMA SERIALLY_REUSABLE;
  10.    PROCEDURE init_pkg_state (n NUMBER) IS
  11.    BEGIN
  12.       pkg1.num := n;
  13.    END;
  14.  
  15.    PROCEDURE print_pkg_state IS
  16.    BEGIN
  17.       dbms_output.put_line('Number: ' || pkg1.num);
  18.    END;
  19. END pkg1;
  20.  
Jun 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Shri | last post by:
Can anybody tell me where i can find a detailed document on #pragma .... --shri
1
by: Gustavo L. Fabro | last post by:
Greetings! Going directly to the point: myclass.h: //-------------------------------------- #pragma managed //Forward declaration
15
by: muttaa | last post by:
Hello all, I'm a beginner in C...May i like to know the difference between a #pragma and a #define.... Also,yet i'm unclear what a pragma is all about as i can find topics on it only in...
10
by: =?Utf-8?B?TmFuZCBLaXNob3JlIEd1cHRh?= | last post by:
I have a binary file created using C++ that contains an object of the structure: struct student { int roll_no; char name; char qualification; };
5
by: venkat | last post by:
Hi, I have come across the a pragma definition " #pragma switch direct ". I don't know any thing about pragma's. Even i when i search through google not getting exact information. what does...
26
by: Rick | last post by:
I'm told that "#pragma once" has made it into the ISO standard for either C or C++. I can't find any reference to that anywhere. If it's true, do any of you have a reference I can use? ...
2
by: aleemakhtar1 | last post by:
wat is use of pragma directive in embedded sys ??
0
debasisdas
by: debasisdas | last post by:
PRAGMA:-Signifies that the statement is a pragma (compiler directive). Pragmas are processed at compile time, not at run time. They pass information to the compiler. A pragma is an instruction to...
2
by: medrifter | last post by:
I have a program like this 1.Analyze.h as follows #if !defined(AFX_ANALYZE_H__550791A7_B441_4AD3_BCEB_4F391A71D410__INCLUDED_) #define...
4
by: dissectcode | last post by:
Hello - Is there a pragma directive that will make a function be ignored? I have a function that is not currently being used and it creates a warning. I would like to fix the warning by using pragma,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.