Scope of globle and locale variable of a Package
I have query about scope of variable declared in spec and body of a package. like
create or replace package pk_test as
v_var varchar2(50);
procedure pk_p_test;
end ;
create or replace package body pk_test as
v_var varchar2(50) := 'aaa';
procedure pk_p_test
is
--v_var varchar2(50) := 'bbbb' ;
begin
null;
--dbms_output.put_line(pk_p_test.v_var);
dbms_output.put_line(pk_test.v_var);
dbms_output.put_line(*v_var*);
end;
end;
declare
begin
pk_test.v_var := 'qqqqq';
--dbms_output.put_line(pk_test.v_var);
pk_test.pk_p_test() ;
end ;
package is allowing to declare variable having same name in spec and body.
But its not allowing to access. is it bug or .. can we access that variable using some methods
Ah, I think I can see what you are saying.
Yes, it can be declared in either place, or even declared in both places, but it shouldn't be declared in both.
One is a "public" state variable and the other is a "private" state variable, so when it creates the package state, they are both marked differently within the state and therefore unique, hence it compiles.
The public one can be accessed from outside the package, because it's clear to Oracle which is being referred to...
SQL> create or replace package pk_test as
2 v_var varchar2(50);
3 procedure pk_p_test;
4 end ;
5 /
Package created.
SQL> ed
Wrote file afiedt.buf
1 create or replace package body pk_test as
2 v_var varchar2(50) := 'aaa';
3 procedure pk_p_test is
4 begin
5 null;
6 end;
7* end;
SQL> /
Package body created.
SQL> exec pk_test.v_var := 'aaa';
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> exec dbms_output.put_line(pk_test.v_var);
aaa
PL/SQL procedure successfully completed.However if you try and access the variable from inside the package, the body is able to reference both the public and private variables, so it doesn't know which one to use. Hence the compilation error previously seen.
It's not a bug, because the packages are being flexible to allow for public and private variables, but what you are experiencing just indicates poor package design and lack of understanding of package state variables.
Similar Messages
-
How to change value of instance variable and local variable at run time?
As we can change value at run time using debug mode of Eclipse. I want to do this by using a standalone prgram from where I can change the value of a variable at runtime.
Suppose I have a class, say employee like -
class employee {
public String name;
employee(String name){
this.name = name;
public int showSalary(){
int salary = 10000;
return salary;
public String showName()
return name;
i want to change the value of instance variable "name" and local variable "salary" from a stand alone program?
My standalone program will not use employee class; i mean not creating any instance or extending it. This is being used by any other calss in project.
Can someone tell me how to change these value?
Please help
Regards,
Sujeet SharmaThis is the tutorial You should interest in. According to 'name' field of the class, it's value can be change with reflection. I'm not sure if local variable ('salary') can be changed - rather not.
-
Hi Gurus, I was unable to see where I can define local and global variables? I see that help.sap.com documentation but where do I create. All variables that I create, are global because, they are visible to all and they all can use it? Any help would be greatly appreciated.
As far as I know, Variables are re-usable objects that are not dependent upon InfoProvider. When I look at this link
http://help.sap.com/saphelp_nw04/helpdata/en/5c/8db07d555411d189660000e829fbbd/frameset.htm
it talks about Global and Local variable? Is this different than what we use in Query Designer? -
Default initialisation of member variables and local variables
I don't understand why member variables are initialized with default values by Java.
Objects are initialized with "null" and primitives with "0", except boolean, which is initialized with "false".
If these variables are used locally they are not initialized. The compiler requires them to be initialized by the programer, for example "String s = null".
Why? What is the use of that difference?
And why are arrays always initialized with default values, no matter if they are member variables or local variables? For example String[] s = new String[10]; s[0] to s[9] are initialized with "null", no matter if "s" is a local or member variable.
Can someone please explain that strange difference, why it is used? To me it has no sense.Most of the time I have to initialize a local variable
with "String s = null" in order to use it because
otherwise the compile would complain. This is a cheap
little trick, but I think everyone uses it.
I wouldn't agree with "most of the time". The only cases where it is almost necessary to do that is when the variable should be initialized in a loop or a try-catch statement, and that doesn't happen too often.
If local variables were initiliazed automatically without a warning it would be a Bad Thing: the compiler could tell when there is a possibility that a variable hasn't been assigned to and prevent manymanymany NullPointerExceptions on run time.
And you didn't answer me why this principle is not
used with arrays if it is so useful as you think.
Possibly it is much more difficult to analyse the situation in the case of arrays; what if values are assigned to the elements in an order that depends on run time properties such as values returned from a random number generator.
The more special rules one has to remember, the more
likely one makes errors.I agree, but what is the rule to remember in this case? -
Final attributes and local variables - performance ??
Hi all,
I and a colleague have done some performance testing regarding the use of final attributes and final local variables, e.g.
with final:
public class MyClass {
private final int i;
public final void myMethod() {
final int j = 5;
// do something with i and j
}vs. non-final:
public class MyClass {
private int i;
public final void myMethod() {
int j = 5;
// do something with i and j
}I couldn't find any speed differences in a small test program, but my colleague did so in his application. Who is right ??
Still, I will have do some formal testing next week and I will post the results.
I'd prefer the version using final anyway because I find it better readable, but the issue I am having is whether I'll spend 2-3 days going through the program making everything final or not.I made some tests with final arguments to a method: I could not find any difference between final and non-final arguments. code is posted below
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import junit.framework.*;
import junit.extensions.*;
public final class FinalVariablesTest extends TestCase /* from junit */ {
* Constructors
public FinalVariablesTest(String name) {
super(name);
* helper methods/classes
protected void setUp() throws Exception {
super.setUp();
protected void tearDown() throws Exception {
super.tearDown();
* Test Suite
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
public static Test suite() {
return new TestSuite(FinalVariablesTest.class);
* Test Cases
/** tests the effect of passing an (final or non-final) int parameter
to a method which uses the variable in a for loop.
<p>
Linux System:
cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 8
model name : Pentium III (Coppermine)
stepping : 1
cpu MHz : 501.146
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
sep_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr xmm
bogomips : 999.42
</pre>
<p>
Results:
<pre>
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
final non-final
498 500
491 494
491 493
491 494
534 494
492 494
491 494
492 493
491 494
495 494
4966 4944 (Totals)
</pre>
public final void testIntParametersToForLoop() {
final int RUNS = 10;
final int INNER = 1000000;
final int OUTER = 10;
System.out.println("-----------------------");
System.out.println("testIntParametersToForLoop");
for(int i=0; i<RUNS; i++) {
outerFinalIntParametersToForLoop(INNER, OUTER);
outerNonFinalIntParametersToForLoop(INNER, OUTER);
private final void outerFinalIntParametersToForLoop(final int INNER,
final int OUTER) {
// with final var in for loop
long start0 = System.currentTimeMillis();
for(int i=0; i<OUTER; i++) {
innerFinalIntParametersToForLoop(INNER * i);
long end0 = System.currentTimeMillis();
System.out.println(" final: " +
( end0 - start0 ) + " milliseconds");
private final void outerNonFinalIntParametersToForLoop(final int INNER,
final int OUTER) {
// with non-final var in for loop
long start1 = System.currentTimeMillis();
for(int i=0; i<OUTER; i++) {
innerNonFinalIntParametersToForLoop(INNER * i);
long end1 = System.currentTimeMillis();
System.out.println(" non final: " +
( end1 - start1 ) + " milliseconds");
private final void innerFinalIntParametersToForLoop(final int INNER) {
for(int i=0; i<INNER; i++) {
int testVar = i * INNER;
private final void innerNonFinalIntParametersToForLoop(int loops) {
for(int i=0; i<loops; i++) {
int testVar = i * loops; -
Hi All
In MS visual studio i can select a local variable (Promise I will go and wash my mouth out now) and add it to a watch therefore i can see what the value of the variable as I go through the code line for line
how can I view local variable in xcode ?
Regards
TonyTo do something similar in Xcode, select the variable and either choose Run > Variables View > View Variables as Expression or choose Run > Variables View > View Variable in Window. Both options place the local variable in a separate window for you to view.
There's not much difference between the two options if you're viewing one variable, but there is a difference if you're viewing multiple variables. If you view the variable as an expression, Xcode places all the variables you want to view in one Expressions window. If you view the variable in a window, Xcode creates a new window when you choose Run > Variables View > View Variable in Window. -
Reading digital line and local variable
I am using digital lines in my program to start and stop "Flat Sequence Structures"
like time measurement ( 4 sequence, start and stop time with "Tick Count" )
Is it good behaviour if i use once "Read from Digital Line.vi" and other starts and stops etc. with Local variables?
Or can i just use "Read from Digital Line.vi" many times in my VI? (same line)Most experienced LV programmers try to avoid both sequence structures and local (and global) variables. The state machine architecture is often preferred. Look at the examples with LV and search for "State machine" on this site.
I would probably use one read line or read port VI in a loop and pass the data to other, independent loops for processing (the timing) via queues.
Lynn -
Hi:
I know there are global inventory and local inventory. the global inventory is pointed by oraInst.loc. Where is local inventory? THXPlease see these MOS docs, it should answer your question.
Global and Local Inventory explained [ID 360079.1]
How to find the location of GLOBAL Inventory and LOCAL inventory on R12.x ? Need Clarifications Oracle Inventory [ID 878717.1]
How to create, update or rebuild the Central Inventory for Applications R12 [ID 742477.1]
Thanks,
Hussein -
Local variable's VariableElement not accessible through treepath
Hi,
I'm extending TreePathScanner visitor to localize and handle certain annotations associated with variables of any kind (field, parameters and local variables).
To do so I overrode the visitVariable method that, as far I understand, should be able to obtain the corresponding javax.lang.model's VariableElement for any variable (whatever its kind) based on the current three path, see code bellow.
It does work well with fields and parameter, however with local variables Trees.getElement simply returns a null. All the information is in fact in the code tree VariableTree node and I could retrieve what I needed from it but rather refrain from using com.sun. ... API if not really necessary and of course implement the processing twice.
Perhaps the javax.lang.model.... object tree is not built for elements within a method body? or is this a bug? com.sun.source.util.Trees#getElement javadoc only says that a null is returned if the element is not "available".
Thanks in advance.
import javax.lang.model.element.VariableElement;
import com.sun.source.util.TreePathScanner;
import com.sun.source.util.Trees;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
public class MyVisitor extends TreePathScanner<Object,Trees> {
@Override
public Object visitVariable(VariableTree node, Trees trees) {
TreePath path = getCurrentPath();
VariableElement ve = (VariableElement) trees.getElement(path);
if (ve != null) {
// The case for parameters and fields.
process(ve);
else { // Funnily getElement return null for local variables
process(node);
return super.visitVariable(node, trees);
}I had a similar problem where trees.getElement(TreePath) was returning null. In my case it had to do with the fact that symbol resolution wasn't done yet. I was trying to invoke my TreePathScanner after calling javacTask.parse() but I had to switch to after calling javacTask.analyze() otherwise trees.getElement(TreePath) always returned null. My issues was with a TreePath for a method though.
-
What's the difference between global variables and instance variables?
hi im just a biginner,
but what is the difference between these two?
both i declare them above the constructor right.
and both can access by any method in the class but my teacher said
global variables are not permitted in java....
but i don't know what that means....and i got started to confuse these two types,,
im confusing.......
and why my teacher said declaring global variables is not permitted,,,,,,
why.....instance variables are kindof like Global variables. I'm not surprised you are confused.
The difference is not in how they are declared, but rather in how they are used.
There are two different "styles" of programming
- procedural programming.
- object oriented programming.
Global variables are a term from Procedural programming.
In this style of programming, you have only one class, and one "main" procedure. You only create one instance of the class, and then "run" it.
There is one thread of control, which goes through various methods/procedures to accomplish your task.
In this style of programming instance variables ARE "global" variables. They are accessible to all methods. There is only one instance of the class, and thus only one instance of the variables.
Global variables are "bad" BECAUSE you can change them in any method you like. Even from places that shouldn't have to. Also if you use the same name as a global variable and a local variable, you can cause great trouble. This can lead to very subtle bugs, as the procedures interact in ways you don't expect.
The preferred method in procedural programming is to pass the values as parameters to the methods, and only refer to the parameters, and local variables. This means that you can track exactly what your method is doing, and what it affects. It makes it simpler to understand. If you use global variables in your methods, it becomes harder to understand.
So when are instance variables not global variables?
When you are actually using the class as an Object, rather than just a program to run. If you are creating multiple instances of an object, all with different values for their instance variables, then they are not global variables. For instance you declare a Person object with an attribute "firstname". Your "main" program then creates many instances of the Person object, each with their own "firstname"
I guess at the end of all this, it comes down to definitions.
Certainly you can write procedural code in java. You can treat your instance variables, for all intents and purposes like global variables.
I can only think to show a sort of example
public class Test1
User[] users;
public void printUsers(){
// loop through and print all the users
// uses a global variable
for(int i=0; i<users.length; i++){
users.printUser();
public void printUsers(User[] users){
// preferred method - pass it the info it needs to do the job
for(int i=0; i<users.length; i++){
users[i].printUser();
public Test1(){
User u1 = new User("Tom", 20);
User u2 = new User("Dick", 42);
User u3 = new User("Harry", 69);
users = new User[3];
users[0] = u1;
users[1] = u2;
users[2] = u3;
printUsers();
printUsers(users);
public static void main(String[] args)
new Test1();
class User{
String firstName;
int age;
public User(String name, int age){
this.firstName = name;
this.age = age;
public void printUser(){
// here they are used as instance variables and not global variables
System.out.println(firstName + " Age: " + age);
Shit thats a lot of typing, and I'm not even sure I've explained it any good.
Hope you can make some sense out of this drivel.
Cheers,
evnafets -
Performance with globle variable and local var.
hi anyone
i just have one performance question about the globle var and local. is having a globle var that is initialized with 'new' at one place better than having local var that is initialzed with 'new' in several places? for example, i have a access var that is initialzed with DB connection. should i have it as a globle var? or put it in the functions where it is needed, and initialize it with DB connection? in both cases, i need to use new operator.
thanks in advance.First , don't use the term "global variable". It is misleading and not an official part of the Java nomenclature. I think the term used should be ( and correct me if I'm wrong ) instance variable. In C and C++ globale variables really are global - they can be accessed by any and all classes which include the header file.
OK, having got that out of my system, back to the question. The value is gotten from a database, right? Whether you make it an instance variable or not depends on you design and whether the value in the database is likely to change during the lifetime of the instance.
For example, if this class is a superclass of another, and the cild needs to know the value of the variable, it is often convenient to make it an instance variable so the subclass can access it directly.
But if the value is likely to change, then you may want to have a getter method which returns the current value in the database.
The latter will clearly have more overhead associated with it since you would need to get the value each time, but it is probably safer than having an instance variable. -
Cannot find scope's local variable
I am doing the soa tutorial. In the step of 5.11.5 Task 5: Reference the RequriesApprovalRule Dictionary in the BPEL Designer, I cannot find the variable of IorderApproved when I add "assign output facts" in the business rule activity.
A local variable named "lOrderApproved" was defined in the scope Scope_CheckApprovalLimit. According to the tutorial, I create the business rule and refered it in BPEL.
However, in the step of Assign Input Facts, I cannot see the lOrderApproved under the Scope_CheckApprovalLimit.There are lot of sequence of steps in this tutorial. If you miss something you cannot proceed further. I would redo from first step.
post here in the BPEL forum
BPEL -
What is difference between local variable and property node ?
What is difference between local variable and property node ?
" 一天到晚游泳的鱼"
[email protected]
我的个人网站:LabVIEW——北方客栈 http://www.labview365.com
欢迎加入《LabVIEW编程思想》组——http://decibel.ni.com/content/groups/thinking-in-labviewTo make things clear, here are two small examples that show how nasty locals and value properties can be to the naive programmer.
- Open the diagram of the race condition.vi before running it and try to predict what will be the values of the two counters after the third run.
- Use the Compare Locals Properties and Wires.vi to find out how slow locals and value properties can be (times 1000+).
This being demonstrated, I must add that I use globals and value properties quite often, because they are often very convenient
Chilly Charly (aka CC)
E-List Master - Kudos glutton - Press the yellow button on the left...
Attachments:
Race condition.vi 9 KB
Compare Locals Properties and Wires.vi 18 KB -
How many ways to read and write a local variable in a called VI?
Ciao!
I'm producing my first TestStand sequence. It is called "FirstAttempt" and it is made by a single step which calls a VI. One of the first dilemmas i encountered realizing this sequence is how to read and write a local variable (created going in Variables -> Locals ('FirstAttempt') -> <right click to insert local>) in the called VI.
The first way (the only one i tried) is to create a control and an indicator on the VI front panel, connect them to their respective terminals in the connector pane and then specify (going in Step Settings -> Module) that these connectors (shown in the Parameter Name column) are linked to the local variable (selected in the Value column).
The second way (not tried) consists in using TestStand API: create a Sequence Context reference on the VI front panel, link it to a property node in the block diagram, select the property "Locals" and extract from this the local variable name and value which, i think, can be readable and writable.
So...
Are the shown ways correct?
Are there other ways?
Knowing that a "local" variable can be considered "global" within the whole sequence, is there the possibility to simply create a reference to the local variable and use the reference in the called VI block diagram in order to save space in the connector pane (if using method 1) or in the block diagram (if using method 2)?
Thanks!
Message Edited by aRCo on 09-17-2009 05:09 AMHi,
Before TestStand 3 you would use the second way you quoted as its the only way.
But now you would use the first way you quoted. You may still what to pass the SequenceContext if you were going to use the TestStand API. For TestStand 3.x and above you would use this way as the first chose. (Personnelly, I would not pass the SequenceContext into a VI if I know it was never going to be used in that VI.)
Not sure I understand your final comment, maybe you are liking it to passing the reference of a control to a subVI so that the control can be updated from within the subVI.
If this is the case and you had a situation where you had a step that was running in parallel with the rest of the steps in the sequence either as a separate thread or execution and were dependent on the contents of the local variable changing from that parallel running step, then you would have to use the API SetVal method to change the local.
Hope this is clear.
Regards
Ray Farmer
Regards
Ray Farmer -
Sampling local variable and synchroniz​e with DAQmx
Hello,
I made a small change in the set-up I used with labview and now when I wanted to change the code I'm having a rather complicated problem.
In my old set-up I was measuring three variables: x and y with a QPD and the power of a laser with a power detector. I was using the DAQmx and I was getting a matrix with three columns with n (sample rate) values. Now, for various reasons I had to take out the second detector. So now I want to build the same matrix as constructed before, but instead of putting the measured values of the laser power I want to put the theoretical values (they are in a local variable) as I cannot measure them. The problem is that this local variable, in general, changes during the DAQmx acquisition time and I would need to sample it at the same rate as I acquire the data from DAQ and then combine all them. How I could sample this variable and attach it to my DAQ results? DAQmx doesn't accept local variables.
ThanksA local variable is not something standalone. It is always associated with a control or indicator. Hows is it updated?
From your description, it is not clear what you are doing. Can you show us some code instead?
(Also be more clear when using acronyms. QPD cound mean many things)
LabVIEW Champion . Do more with less code and in less time .
Maybe you are looking for
-
My IPOD Classic 160GB is now not recognized by iTunes and will not sync
I have a 160GB IPOD Classic that now will not sync with iTunes. Both the iPod and iTunes have up to date software versions and I am connecting thru a MAcBook Pro running OS X 10.10.2. I have synced this iPod i the past with no problems and now it doe
-
How to instal iMovie6 in my new iMAC
What is the best way to install iMovie6 to my new iMac that is on it's way...I read so much about how no one likes the new iMovie8. So should I use firewire and transfer it or should I use the disc? The reason I ask is because I have so many plugins
-
I have an existing Flash 8/AS2 game that uses Stage.width and Stage.height quite a bit, problem is that when I package as an AIR app the Stage.width and Stage.height properties are undefined, although Stage itself still shows up as an Object with 8-1
-
What is the use of setup tables in LO extraction
Hi Friends, What is the use of setup tables in LO extraction, what is the functionality of setup tables Thanks in advance
-
I delete websites I visit in "History" line by line, and I save the ones I find valuable for viewing in the future. Last week I visited a new website and checked out a few articles. A few days later I was deleting that day's line items I did not want