Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:00:26+00:00 2026-05-31T12:00:26+00:00

If I have a package variable in Oracle (8), and it is modified (incremented)

  • 0

If I have a package variable in Oracle (8), and it is modified (incremented) in a function that is called from multiple triggers, is it possible that the function is called multiple times at once?

Specifically, we have sequence numbers within a business transaction, so we have a function that returns the next number in a sequence for a particular session, and then a function that creates an increments a package variable representing the sequence number. Basically, the function is something like:

function get_seq_num return number is
  ret number;
begin
  if g_seq_num is not null then
    ret := g_seq_num;
    g_seq_num := g_seq_num + 1;
  else
    g_seq_num := 1;
  end if;
  return ret;
end get_seq_num;

It appears that 2 triggers attempt to log the same seq_num for a given transaction, and I can’t quite work out why (unless they run concurrently, which I thought they wouldn’t).

**NOTE1: For the record, this is legacy code I’ve inherited, and am probably not in a position to change it irrespective of how bad a practice it is….

** NOTE2: Because I don’t think it is possible for the function to be executing multiple times concurrently, I am looking into whether the record_seq_num can possibly be updated anywhere else….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:00:27+00:00Added an answer on May 31, 2026 at 12:00 pm

    I think the answer to your question is sort of, yes.

    Each database session gets its own copy of package variables. They are not shared between sessions. What you’ve described is NOT a safe way to create a sequence. If you have one session that hits that function a number of times, its copy of the package variable will be incremented, but another session will not. So it’s possible that session A will return 1, 2, 3 … and then session B will return 1.

    Furthermore, your package variable will be discarded when the session closes or the package gets recompiled.

    Here is an Ask Tom question on “Global variable across different sessions“

    You should be using an Oracle sequence.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found the function dhist() in the ggplot2 package that implements the variable
I have an ID in a package variable that I need to add as
I have a SSIS 2005 package that needs to read from an XML file,
I have a variable in a package ( rec in this case) that needs
I have an SSIS package that does the following: Selects the connection strings from
I have a msi package generated by wix that creates a system environment variable
I have ssis package in that I'm taking values from flat file and insert
I have an SSIS package, which depending on a boolean variable, should either go
I have a package that I just made and I have an old-mode that
Lucky me, I have to work with Oracle. And packages. I have a package

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.