Login   Search
Skip Navigation Links
Home
Application Security Tips
Oracle , PL/SQL
IT Product Reviews
Project Management
Forum
Contact Us
Links & References
Avoid SQL Injection attack
Threats and Countermeasures: S.T.R.I.D.E
Input Validation
Session Management
Authentication Mechanism
Cross Site Scripting Vulnerabilities
Configuration Management
Scroll up
Scroll down
Oracle 9i - Programming basics PL/SQL
PL/SQL - Conditional Statements – IF
PL/SQL -Nested Block
LOOPS in PL/SQL
PL/SQL Records
Cursors in PL/SQL
PL/SQL Tables
PL/SQL Exceptions
PL/SQL Procedures
PL/SQL Functions
Oracle supplied packages
Packages
PL/SQL Ref Cursors
Types in Oracle PL/SQL
Varrays
Nested Table
Bfile and LOBs
Bulk Binding
Know Depandencies
PL/SQL Wrapper
Triggers
Scroll up
Scroll down
DBMS_SQL package
DBMS_DDL Package
DBMS_JOB Package
UTL_FILE Package
DBMS_METADATA Package
DBMS_PIPE Package
DBMS_SESSION Package
Scroll up
Scroll down

 

Blog

  • Imperativeness of agile methodology in software development
  • Get list of installed softwares on machines in your network
  • VMWare - Error - the vmware authorization service is not running
  • Add chart / graphs in ASP.net application / website
  • Microsoft Ramp Up

Blog

  • Review: uCertify.com: PrepKit for: 70-529 (C#)
  • Bird eye Review: uCertify.com: PrepKit for: 70-529 (C#)
Skip Navigation Links>Oracle , PL/SQL>Oracle supplied packages>DBMS_SESSION Package

DBMS_SESSION Package


The global variable’s value can be re initialized.

create or replace package p
 as
 g number := 0;
 end;
 /
 
create or replace procedure pr1
 is
 begin
  p.g := p.g 1;
  dbms_output.put_line('Value of g is ' || p.g);
end;
 /

exec pr1;
exec pr1;
exec pr1;
 

After executing the modify_package_state procedure the initial value of the global variable g gets initialized.

 The global cursors can be closed.

create table tx1 (name varchar2(30));

create or replace package p
is
cursor cf is select * from emp;
procedure pr1;
end p;

create or replace package body p
 is
   procedure pr1
   is
  c number := 0;
   begin
   for i in cf
   loop
       c :=  c + 1;
       if c <= 3 then
       --dbms_output.put_line(i.ename);
       insert into tx1 values(i.ename);
       else
       dbms_session.modify_package_state(dbms_session.reinitialize);
       end if;
   end loop;
  end pr1;
 end;

Effective for scheduling a job – After every 2 hours the open cursors should be initialized.

create or replace package P is
  cnt    number := 0;
  cursor c is select * from emp;
  procedure print_status;
end P;
/

create or replace package body P is
   procedure print_status is
   begin
     dbms_output.put_line('P.cnt = ' || cnt);
     if c%ISOPEN then
       dbms_output.put_line('P.c is OPEN');
     else
       dbms_output.put_line('P.c is CLOSED');
     end if;
   end;
 end P;
/

set serveroutput on;
begin
p.cnt := 111;
p.print_status;
end;
/

P.cnt = 111
P.c is CLOSED

begin
dbms_session.modify_package_state(dbms_session.reinitialize);
end;
/

set serveroutput on;

begin
  p.print_status;
end;
/

P.cnt = 0
P.c is CLOSED
UNIQUE_SESSION_ID Function
This function returns an identifier that is unique for all sessions currently connected to this database. Multiple calls to this function during the same session always return the same result.

Syntax
DBMS_SESSION.UNIQUE_SESSION_ID
  RETURN VARCHAR2;
Pragmas
pragma restrict_references(unique_session_id,WNDS,RNDS,WNPS);
select DBMS_SESSION.UNIQUE_SESSION_ID from dual;
SET_NLS Procedure
This procedure sets up your national language support (NLS). It is equivalent to the following SQL statement:
ALTER SESSION SET <nls_parameter> = <value>
Syntax
DBMS_SESSION.SET_NLS (
   param VARCHAR2,
   value VARCHAR2);
Parameters
Table 65-8 SET_NLS Procedure Parameters
Parameter
 Description

param
 NLS parameter. The parameter name must begin with 'NLS'.
value
 Parameter value. 

If the parameter is a text literal, then it needs embedded single-quotes. For example, "set_nls('nls_date_format','''DD-MON-YY''')"
declare
format varchar2(30);
begin
format := '&Date_Format';
if lower(format) = 'dd-mon-yy' then
  DBMS_SESSION.SET_NLS('nls_date_format','''DD-MON-YY''');
  dbms_output.put_line(' The date according to ' || format || ' is ' ||sysdate);
elsif lower(format) = 'dd-mm-yy' then
   DBMS_SESSION.SET_NLS('nls_date_format','''DD-MM-YY''');
  dbms_output.put_line(' The date according to ' || format || ' is ' ||sysdate);
elsif lower(format) = 'mm-dd-yy' then
   DBMS_SESSION.SET_NLS('nls_date_format','''MM-DD-YY''');
  dbms_output.put_line(' The date according to ' || format || ' is ' ||sysdate);
else
 dbms_output.put_line('Wrong format'); 
 end if;
end;

 

Discussion about this article

AuthorBody
Rahul
8/29/2009 3:53 PM
Please provide feedback about this article here.
To participate in this discussion Sign up for free membership of 24x7code.
To Signup click on Login , Use create user link & the follow the instructions.
Thank you



Designed & Developed by Rahul Bagal