Equivalent of "C static local" variable?

Hi!
I am trying to write a sub-VI that has multiple call modes
(init, do1, do2) and needs to remember some variables set in the
'init' call. When I try the straightforward way of just placing
indicators as temporary variables on the front panel, these seem
to reset to the default values every time the VI is called.
Is there any equivalent of the static local variables used in C?
Or do I have to use GLOBAL variables?
Rudolf

There are several solutions:
1. Global variables.
You can create global variable for each of your temorary variables. This is easy to do but I think it's not very convivient way to pass data.
2. One Global variable.
If you have many temporary variables you can organize them into cluster and create only one global variable for this cluster. Then you have to read and write this cluster in your SubVI every time you change any of your temporary variables.
3. Pass data to/from your SubVI.
If you look at the most of LV VIs you will see that very often they have some practically identical input and output nodes. For example "AI Start.vi" has " task ID in' and "task ID out" nodes. You can make the same thing. Let your subVI reads and writes some cluster of your tempora
ry variables through its input and output nodes. So you will have the access to this variables in any place ofyour main VI. Also you can change and create your own clusters of temp variables in your main VI. And also you will get the ability to pass these data to your subVI using local variables or shift registers or sequence locals in your main VI
I think that the last way is the most useful.
Good luck.
Oleg Chutko.

Similar Messages

  • Static local variable?

    Hi,
    Why a local variable can not be declared as static? What is the logic behind this static keyword?
    thks.

    Hi,
    Why a local variable can not be declared as static?
    What is the logic behind this static keyword?
    thks.In C, a static local variable is used to maintain state between function calls. In Java, the way to maintain state is with a member variable. We have no need of static local variables.
    The meaning of the static keyword is "associated with the class as a whole, rather than with any one instance."

  • 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;

  • Local variable problem

    I am making an application that takes an apartment number and number of occupants in that apartment and then displays a number of statistics. So far I haven't had much problem
    except on a what is probably a very simple problem.
    I have two buttons, and when "store" is clicked the info in the textboxes is input to an array.
    My problem is with the next button, "quit", this is where all the info is supposed to be displayed.
    All my variables that I need from "store" are local and are recognized in " the if statement in quit. Ive tried declaring them outside of the if statement, but it hasn't been working.
    {code}
    public void actionPerformed(ActionEvent event)
                   Object source = event.getSource();
                   Apartment input;
                   if (source == store)
                        Integer aptNo = Integer.parseInt(input1.getText());
                        Integer occup = Integer.parseInt(input2.getText());
                        input = new Apartment(aptNo, occup);
                        if(aptNo > BUILDING_SIZE)
                             JOptionPane.showMessageDialog(null, "That apartment number doesn't exist.");
                        else if(occup > MAX_OCCUPANTS)
                             JOptionPane.showMessageDialog(null, "Too many occupants, only 20 are permitted per apartment.");
                        else
                             occupants[aptNo] = occup;
                             input1.setText("");
                             input2.setText("");
                             JOptionPane.showMessageDialog(null, input.getNumber(occupants));
                   if (source == quit)
                   // I need the variables aptNo and occup in here to put into my methods for output, but I don't know how to get them.     
    {code}

    EmmCeeVee wrote:
    Thank you for all of the responses, it really helps me out.
    Obviously my knowledge of local variables is hurting as I switched it around as your said and declared the aptNo and occup outside of the if's.
    All I need is for the quit button to look at the array ( which has just been modified by the sotre button) and output a bunch of results.
    Heres where im at:Your problem is of scope of the variables.
    Here whatever variable you defined in actionPerformed they are local for that method (they are out of scope when the method is finished/called again), Upon this, the actionPerformed is called twice one for store and another time for quit. So you cant expect the value stored at store should be there still when you all quit
    If you want those values available on both the actions then make them a class level variables.
    Below is a sample program, might help you.
    class Employee
         String empName = null;
         int empNo;
         Employee(String eName,int eNmbr)
              this.empName = eName;
              this.empNo = eNmbr;
    class CheckVariableScope
            Employee empOb; // Here
         int eNo;
         String eName = null;
         public void checkScope(String action)
                    //Instead of defining Employee reference variable, eNo and eName  in checkScope method, define it @ class level.
                    // in your case they are Apartment input, Integer aptNo and Integer occup
                     // like above i did.
                     // If i comment the class level variable and uncomment method variable, this program also give the same error.
              //Employee empOb;
              //int eNo;             
              //String eName = null;
              if (action.equals("Store") )
                        eNo = 10;
                        eName = "Bob";
                        empOb = new Employee(eName, eNo);
                        System.out.println("The eName is : "+empOb.empName+" , empNo is : "+empOb.empNo);
                   if (action.equals("quit"))
                        System.out.println(" eNO from Object is : "+empOb.empNo);
                        System.out.println(eNo); //Error: may not have been intitialized
         public static void main (String st[])
              CheckVariableScope ob = new CheckVariableScope();
              ob.checkScope("Store");
              ob.checkScope("quit");
    }

  • Local variable needs to be declared final

    This is the error code I am getting:
    C:\javacode\Notepad>javac FinalProgram.java
    FinalProgram.java:60: local variable textfield1 is accessed from within inner class; needs to be declared final
    System.out.println("It is detected " + pressed +
    textfield1);
    ^
    1 error
    Here is my code:
    comments relevant to this topic are //ALL IN CAPS
    import java.awt.*; //declare packages needed
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.JMenuBar;
    public class FinalProgram extends JFrame
        implements ActionListener {
    static JFrame frame;
      public void actionPerformed (ActionEvent e) {
          String answer = (e.getActionCommand());
             if (answer == "Get Data") {
              JInternalFrame iFrame = new JInternalFrame("Get Data . ", false, true, false, false);
              iFrame.setLayout(new GridLayout(8,2));
              JLabel label1 = new JLabel("First Name");
              JLabel label2 = new JLabel("Last Name");
              JLabel label3 = new JLabel("Street");
              JLabel label4 = new JLabel("City");
              JLabel label5 = new JLabel("State");
              JLabel label6 = new JLabel("Zip");
              JLabel label7 = new JLabel("Phone");
              JLabel label8 = new JLabel("Click Button to Submit Form -->");
              JTextField textfield1 = new JTextField(10);
              JTextField textfield2 = new JTextField(10);
              JTextField textfield3 = new JTextField(10);
              JTextField textfield4 = new JTextField(10);
              JTextField textfield5 = new JTextField(10);
              JTextField textfield6 = new JTextField(10);
              JTextField textfield7 = new JTextField(10);
              JButton button1 = new JButton("Submit Data");
              //textfield1.addActionListener(this);
              textfield1.addActionListener(this);
              textfield2.addActionListener(this);
              textfield3.addActionListener(this);
              textfield4.addActionListener(this);
              textfield5.addActionListener(this);
              textfield6.addActionListener(this);
              textfield7.addActionListener(this);
              button1.addActionListener(new ActionListener() { //start button1.addActionListener
              public void actionPerformed(ActionEvent a) { //start button1 actionPerformed
                        String pressed = ((JButton) a.getSource()).getText();
                        System.out.println("button press is detected " + pressed + textfield1);  //THIS SYSTEM OUT PRINT IS A TEST, IT WORKS WHEN I DON'T HAVE THE "+ textfield1" PART, IT GIVES ME THE ERROR MESSAGE POSTED ABOVE ABOUT DECLARING IT FINAL.
    I'M A BEGINNER, MY GOAL HERE, IN EASY ENGLISH, IS TO GRAB THE DATA FROM EACH TEXTFIELD AND STORE THEM IN VARIABLES, OR MORE IDEALLY IN AN ARRAY SO THAT THE REST OF MY CODE BELOW CAN WRITE THEM TO FILE, I'VE BEEN TRYING THE PAST FEW DAYS ON THIS EXPERIMENTING AND ANY SUGGESTIONS WOULD BE APPRECIATED
              try {
                   String directoryName = "c:\\javacode\\Notepad";
                   String fileName = "program.txt";
                   File output = new File(directoryName,fileName);
                   output.createNewFile();
              if (! output.isFile()) {
                   System.out.println("File creation of" + output.getPath() + "failed");
            return;
              BufferedWriter out = new BufferedWriter(new FileWriter(output.getPath(), true));
              String[] text = {"This is the text that will be written. \r", //we pass an array, which holds the text to append to the file
                    "The text will be written to the file \r",
                    "in append mode. If the file does not \r",
                    "exist it will be created.\r"};  //WHAT YOU SEE HERE IS JUST A TEST, IN PLACE, I WOULD LIKE TO HAVE THE INFORMATION FOR MY TEXTFIELDS SO THAT I CAN PASS THEM THROUGH A FOR LOOP AS BELOW AND WRITE DATA FOR EACH OF THE TEXTFIELDS TO MY EXTERNAL TEXT FILE
                    for(int i = 0; i < text.length; i++) { //using the length of the text message we use out.Write() to write out the data.  Notice that all of the code is placed into a try-catch block so we can check for any IOExceptions that occur
           out.write(text[i] + "\n");
              //Here I create the code to grab the actions(grab the text) from the textFields and store them into variables OR into an array
              //after I have created my container to hold the information for my various textFields, then I want to create a for loop to go through each textField and write that information to a text file, separating each textField on its own line
         out.close();
         catch(IOException d) {
         System.out.println("Error writing to file " + d);
                   }  //end button1.addActionListener
              }  //end button1 actionPerformed
              );     //end actionListener statement     
              //textfield1.setSize(10, 10);
              iFrame.add(label1);
              iFrame.add(textfield1);
              iFrame.add(label2);
              iFrame.add(textfield2);
              iFrame.add(label3);
              iFrame.add(textfield3);
              iFrame.add(label4);
              iFrame.add(textfield4);
              iFrame.add(label5);
              iFrame.add(textfield5);
              iFrame.add(label6);
              iFrame.add(textfield6);
              iFrame.add(label7);
              iFrame.add(textfield7);
              iFrame.add(label8);
              iFrame.add(button1);
              iFrame.setSize(200, 500);
              iFrame.setVisible(true);
              add(iFrame);
              if (answer == "Display Data") {
              JInternalFrame iFrame = new JInternalFrame("Display Data . ", false, true, false, false);
              JTextArea text = new JTextArea();
              JScrollPane scroller = new JScrollPane();
              scroller.getViewport().add(text);
              iFrame.getContentPane().add(scroller);
              iFrame.setSize(200, 150);
              iFrame.setVisible(true);
              add(iFrame);
      public FinalProgram() {
        super ("Menu Example");
        JMenuBar jmb = new JMenuBar();
        JMenu file = new JMenu("Functions");
        JMenuItem item;
        file.add(item = new JMenuItem("Get Data"));
        item.addActionListener (this);
        file.add(item = new JMenuItem("Display Data"));
        item.addActionListener (this);
        jmb.add(file);
        addWindowListener(new ExitListener());    
         setJMenuBar (jmb);
        public static void main(String[] args) {
            FinalProgram window = new FinalProgram();
            window.setTitle("Final Program");
            window.setSize(600, 600);
            window.setVisible(true);
    }

    hi,
    Updated Code,
    import java.awt.*; //declare packages needed
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.JMenuBar;
    public class FinalProgram extends JFrame
        implements ActionListener {
    static JFrame frame;
              JLabel label1 = new JLabel("First Name");
              JLabel label2 = new JLabel("Last Name");
              JLabel label3 = new JLabel("Street");
              JLabel label4 = new JLabel("City");
              JLabel label5 = new JLabel("State");
              JLabel label6 = new JLabel("Zip");
              JLabel label7 = new JLabel("Phone");
              JLabel label8 = new JLabel("Click Button to Submit Form -->");
              JTextField textfield1 = new JTextField(10);
              JTextField textfield2 = new JTextField(10);
              JTextField textfield3 = new JTextField(10);
              JTextField textfield4 = new JTextField(10);
              JTextField textfield5 = new JTextField(10);
              JTextField textfield6 = new JTextField(10);
              JTextField textfield7 = new JTextField(10);
              JButton button1 = new JButton("Submit Data");
      public void actionPerformed (ActionEvent e) {
          String answer = (e.getActionCommand());
             if (answer == "Get Data") {
              JInternalFrame iFrame = new JInternalFrame("Get Data . ", false, true, false, false);
              iFrame.setLayout(new GridLayout(8,2));
              //textfield1.addActionListener(this);
              textfield1.addActionListener(this);
              textfield2.addActionListener(this);
              textfield3.addActionListener(this);
              textfield4.addActionListener(this);
              textfield5.addActionListener(this);
              textfield6.addActionListener(this);
              textfield7.addActionListener(this);
              button1.addActionListener(new ActionListener() { //start button1.addActionListener
              public void actionPerformed(ActionEvent a) { //start button1 actionPerformed
                        String pressed = ((JButton) a.getSource()).getText();
                        System.out.println("button press is detected " + pressed + textfield1.getText()); 
              try {
                   String directoryName = "c:\\javacode\\Notepad";
                   String fileName = "program.txt";
                   File output = new File(directoryName,fileName);
                   output.createNewFile();
              if (! output.isFile()) {
                   System.out.println("File creation of" + output.getPath() + "failed");
            return;
              BufferedWriter out = new BufferedWriter(new FileWriter(output.getPath(), true));
              String[] text = {"This is the text that will be written. \r", //we pass an array, which holds the text to append to the file
                    "The text will be written to the file \r",
                    "in append mode. If the file does not \r",
                    "exist it will be created.\r"};  //WHAT YOU SEE HERE IS JUST A TEST, IN PLACE, I WOULD LIKE TO HAVE THE INFORMATION FOR MY TEXTFIELDS SO THAT I CAN PASS THEM THROUGH A FOR LOOP AS BELOW AND WRITE DATA FOR EACH OF THE TEXTFIELDS TO MY EXTERNAL TEXT FILE
                    for(int i = 0; i < text.length; i++) { //using the length of the text message we use out.Write() to write out the data.  Notice that all of the code is placed into a try-catch block so we can check for any IOExceptions that occur
           out.write(text[i] + "\n");
              //Here I create the code to grab the actions(grab the text) from the textFields and store them into variables OR into an array
              //after I have created my container to hold the information for my various textFields, then I want to create a for loop to go through each textField and write that information to a text file, separating each textField on its own line
         out.close();
         catch(IOException d) {
         System.out.println("Error writing to file " + d);
                   }  //end button1.addActionListener
              }  //end button1 actionPerformed
              );     //end actionListener statement     
              //textfield1.setSize(10, 10);
              iFrame.add(label1);
              iFrame.add(textfield1);
              iFrame.add(label2);
              iFrame.add(textfield2);
              iFrame.add(label3);
              iFrame.add(textfield3);
              iFrame.add(label4);
              iFrame.add(textfield4);
              iFrame.add(label5);
              iFrame.add(textfield5);
              iFrame.add(label6);
              iFrame.add(textfield6);
              iFrame.add(label7);
              iFrame.add(textfield7);
              iFrame.add(label8);
              iFrame.add(button1);
              iFrame.setSize(200, 500);
              iFrame.setVisible(true);
              add(iFrame);
              if (answer == "Display Data") {
              JInternalFrame iFrame = new JInternalFrame("Display Data . ", false, true, false, false);
              JTextArea text = new JTextArea();
              JScrollPane scroller = new JScrollPane();
              scroller.getViewport().add(text);
              iFrame.getContentPane().add(scroller);
              iFrame.setSize(200, 150);
              iFrame.setVisible(true);
              add(iFrame);
      public FinalProgram() {
        super ("Menu Example");
        JMenuBar jmb = new JMenuBar();
        JMenu file = new JMenu("Functions");
        JMenuItem item;
        file.add(item = new JMenuItem("Get Data"));
        item.addActionListener (this);
        file.add(item = new JMenuItem("Display Data"));
        item.addActionListener (this);
        jmb.add(file);
        addWindowListener(new ExitListener());    
         setJMenuBar (jmb);
        public static void main(String[] args) {
            FinalProgram window = new FinalProgram();
            window.setTitle("Final Program");
            window.setSize(600, 600);
            window.setVisible(true);
    class ExitListener extends WindowAdapter {
      public void windowClosing(WindowEvent event) {
        System.exit(0);
    }

  • Catch-22: need to assign a local variable within an anonymous class

    static boolean showMessage(Window parent, String button0, String button1)
        throws HeadlessException {
              final Window w = new Window(parent);
              Panel p = new Panel(new GridBagLayout());
              final Button b[] = new Button[]{new Button(button0), (button1 != null) ? new Button(button1) : (Button)null};
              boolean rval[]; //tristate: null, true, false
              w.setSize(100, 50);
              w.setVisible(true);
              //add b[0
              gbc.fill = GridBagConstraints.HORIZONTAL;
              gbc.gridx = 0;
              gbc.gridy = 3;
              p.add(b[0], gbc);
              //add b[1]
              if (button1 != null) {
                   gbc.fill = GridBagConstraints.HORIZONTAL;
                   gbc.gridx = 1;
                   gbc.gridy = 3;
                   p.add(b[1], gbc);
              w.add(p);
              w.pack();
            w.setVisible(true);
            //actionListener for button 0
              b[0].addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             if (e.getSource() == b[0]) {
                                  w.setVisible(false);
                                  rval = new boolean[1];
                                  rval[0] = true;
              //actionListener for button 1
              if (button1 != null) {
                   b[1].addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent e) {
                                  if (e.getSource() == b[1]) {
                                       w.setVisible(false);
                                       rval = new boolean[1];
                                       rval[0] = false;
            while (true) {
                 try {
                      if (rval[0] == true || rval[0] == false) //should trigger NullPointerException
                           return rval[0];
                 } catch (NullPointerException e) { }
         }catch-22 is at
    rval = new boolean[1];
    rval = false;javac whines: "local variable rval is accessed from within inner class; needs to be declared final"
    How do I assign to rval if it's declared final?
    Or at the very least, how do I get rid of this error (by all means, hack fixes are okay; this is not C/C++, I don't have to use sanity checks)?
    I'm trying to make a messagebox in java without using JOptionPane and I'm trying to encapsulate it in one method.
    And I'm far too lazy to make a JNI wrapper for GTK.

    dcminter wrote:
    How do I assign to rval if it's declared final?You don't and you can't. You're not allowed to assign to the local variable of the outer class for extremely good reasons, so forget about trying.
    Or at the very least, how do I get rid of this errorIf you don't want the side effect, then just use an inner class variable or a local variable.
    If you want the side effect then use a named class and provide it with a getter and setter.
    Finally, in this specific case because you're using an array object reference, you could probably just initialise the array object in the outer class. I.e.
    // Outer class
    final boolean[] rval = new boolean[1];
    // Anonymous Inner class
    rval[0] = true; // No need to intialize the array.
    I declared it as an array so that it would be a tristate boolean (null, true, false) such that accessing it before initialization from the actionPerformed would trigger a NullPointerException.
    Flowchart:
    is button pressed? <-> no
    |
    V
    Yes->set and return
    Is there a way to accomplish this without creating a tribool class?

  • Oracle equivalent to SQL Server Table Variables ?

    Does Oracle have anything equivalent to SQL Server table variables, that can be used in the JOIN clause of a select statement ?
    What I want to do is execute a query to retrieve a two-column result, into some form of temporary storage (a collection ?), and then re-use that common data in many other queries inside a PL/SQL block. I could use temporary tables, but I'd like to avoid having to create new tables in the database, if possible. If I was doing this in SQL Server, I could use a table variable to do this, but is there anything similar in Oracle ? SQL Server example:
    use Northwind
    DECLARE @myVar TABLE(CustomerID nchar(5), CompanyName nvarchar(40))
    INSERT INTO @myVar(CustomerID, CompanyName)
    select CustomerID, CompanyName
    from Customers
    --Join the variable onto a table in the database
    SELECT *
    FROM @myVar mv join Customers
    on mv.CompanyName = Customers.CompanyName
    The closest I've found in Oracle is to use CREATE TYPE to create new types in the database, and use TABLE and CAST to convert the collection to a table, as shown below. I can't see anyway without creating new types in the database.
    CREATE TYPE IDMap_obj AS Object(OldID number(15), NewID number(15));
    CREATE TYPE IDMap_TAB IS TABLE OF IDMap_obj;
    DECLARE
    v_Count Number(10) := 0;
    --Initialize empty collection
    SourceIDMap IDMap_TAB := IDMap_TAB();
    BEGIN
    --Populate our SourceIDMap variable (dummy select statement for now).
    FOR cur_row IN (select ID As OldID, ID + 10000000 As NewID From SomeTable) LOOP
    SourceIDMap.extend;
    SourceIDMap(SourceIDMap.Last) := IDMap_obj(cur_row.OldId, cur_row.NewId);
    END LOOP;
    --Print out contents of collection
    FOR cur_row IN 1 .. SourceIDMap.Count LOOP
    DBMS_OUTPUT.put_line(SourceIDMap(cur_row).OldId || ' ' || SourceIDMap(cur_row).NewId);
    END LOOP;
    --OK, can we now use our collection in a JOIN statement ?
    SELECT COUNT(SM.NewID)
    INTO v_Count
    FROM SomeTable ST JOIN
    TABLE(CAST(SourceIDMap As IDMap_TAB)) SM
    ON ST.ID = SM.OldID;
    DBMS_OUTPUT.put_line(' ' );
    DBMS_OUTPUT.put_line('v_Count is ' || v_Count);
    END;

    Hi, got this from our plsql guys:
    The term "table function" is a bit confusing here. In Oracle-speak, it means a function that can be used in the from list of a select statement thus:
    select * from Table(My_Table_Function()),..
    where...
    The function's return type must be a collection that SQL understands. So for the interesting case -- mimicking a function with more than one column -- this would be a nested table of ADTs where both the ADT and the nested table are defined at schema level. PL/SQL -- by virtue of some clever footwork -- allows you to declare the type as a nested table of records where both these types are declared in a package spec. This alternative is generally preferred, especially because the nested table can be of Some_Table%rowtype (or Some_Cursor%rowtype if you prefer).
    As I understand it from our man on the ANSI committee, our use terminology follows the standard.
    The construct below seems to be a bit different (though there are similarities) because it appears from your code sample that it's usable only within procedural code. And the object from which you select is a variable rather than a function.
    So, after that preamble... the answer would be:
    No, we don't have any constructs to let you "declare" something that looks like a regular schema-level table as a PL/SQL variable -- and then use (static) SQL on it just as if it were a schema-level table.
    But yes, you can use PL/SQL's pipelined table function to achieve much of the same effect.
    Look at the attached Table_Function.sql.
    It shows that you can populate a collection of records using ordinary PL/SQL code. You can't use SQL for insert, update, or delete on such a collection. I see that SQL Server lets you do
    insert into Program_Variable_Table select... from Schema_Level_Table
    The PL/SQL equivalent would be
    select...
    bulk collect into Program_Variable_Collection
    from Schema_Level_Table
    The attached shows that once you have populated your collection, then you can then query it with regular SQL -- both from inside PL/SQL code and from naked SQL.
    and the code is here
    CONNECT System/p
    -- Drop and re-create "ordinary" user Usr
    EXECUTE d.u
    CONNECT Usr/p
    create table Schema_Things(ID number, Description Varchar2(80))
    create package Pkg is
    subtype Thing_t is Schema_Things%rowtype;
    type Things_t is table of Thing_t; -- index by pls_integer
    Things Things_t;
    -- PLS-00630: pipelined functions must have
    -- a supported collection return type
    -- for "type Things_t is table of Thing_t index by pls_integer".
    function Computed_Things return Things_t pipelined;
    procedure Insert_Schema_Things(No_Of_Rows in pls_integer);
    end Pkg;
    create package body Pkg is
    function Computed_Things return Things_t pipelined is
    Idx pls_integer;
    Thing Thing_t;
    begin
    Idx := Things.First();
    while Idx is not null loop
    pipe row (Things(Idx));
    Idx := Things.Next(Idx);
    end loop;
    end Computed_Things;
    procedure Insert_Schema_Things(No_Of_Rows in pls_integer) is
    begin
    Things := Things_t();
    Things.Extend(No_Of_Rows);
    for j in 1..No_Of_Rows loop
    Things(j).ID := j;
    Things(j).Description := To_Char(j, '00009');
    end loop;
    insert into Schema_Things
    select * from Table(Pkg.Computed_Things());
    end Insert_Schema_Things;
    end Pkg;
    -- Test 1.
    begin Pkg.Insert_Schema_Things(100); end;
    select * from Schema_Things
    -- Test 2.
    begin
    Pkg.Things := Pkg.Things_t();
    Pkg.Things.Extend(20);
    for j in 1..20 loop
    Pkg.Things(j).ID := j;
    Pkg.Things(j).Description := To_Char(j, '00009');
    end loop;
    for j in 1..5 loop
    Pkg.Things.Delete(5 +2*j);
    end loop;
    end;
    select * from Table(Pkg.Computed_Things())
    /

  • Thread local variable causes JVM crash through JNI

    Hi All,
    My team developed a JDBC driver which uses some native C codes. (Compiler: cl.exe, O/S: Windows XP)
    I found that JVM crashes at specific point. So I used debugger(Visual Studio 2005) to find the position.
    ==================File1.c=====================
    JNIEXPORT jbyteArray JNICALL
    Java_com_lone_wolf_MyClass_myFunc(
    JNIEnv *env, jclass cls,
    jint msgtype, jbyteArray recvarr)
    jbyteArray outarr;
    int x = 3;
    outarr = my_initializer (int &x);
    return outarr;
    ==================File2.c=====================
    __declspec(thread) int thread_id;
    static jbyteArray my_initializer (int *a)
    thread_id = *a; // HERE JVM CRASHES
    When my_initializer() tries to put *a into thread_id, JVM crashed with the following error message.
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x4931c6bf, pid=3560, tid=848
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode)
    # Problematic frame:
    # C [hello.dll+0xc6bf]
    --------------- T H R E A D ---------------
    Current thread (0x00037168): JavaThread "main" [_thread_in_native, id=848]
    Stack: [0x00040000,0x00080000), sp=0x0007f494, free space=253k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C [hello.dll+0xc6bf]
    C [hello.dll+0xbebb]
    C [hello.dll+0x3c30]
    C [hello.dll+0x18e6]
    C [hello.dll+0x11b8]
    j com.lone.wolf.MyClass.myFunc(I[B)[B+0
    v ~StubRoutines::call_stub
    V [jvm.dll+0x8176e]
    V [jvm.dll+0xd481d]
    V [jvm.dll+0x8163f]
    V [jvm.dll+0x885cd]
    C [java.exe+0x14c0]
    C [java.exe+0x64cd]
    C [kernel32.dll+0x16ff7]
    VM Arguments:
    jvm_args: -Xms128m -Xmx1024m
    java_command: sampler.Sampler
    --------------- S Y S T E M ---------------
    OS: Windows XP Build 2600 Service Pack 2
    CPU:total 4 family 6, cmov, cx8, fxsr, mmx, sse, sse2, ht
    Memory: 4k page, physical 2062180k(1378880k free), swap 4003992k(3252828k free)
    vm_info: Java HotSpot(TM) Client VM (1.5.0_01-b08) for windows-x86, built on Dec 6 2004 19:51:00 by "java_re" with MS VC++ 6.0
    Any idea how to solve this issue will be greatly appreciated.
    Thank you.

    This deffinition ( __declspec(thread) ) of the thread local veriable does not works in some cases (see articles in MSDN how to define thread local variables in C++ code). JVM loads your native module (DLL) with LoadLibrary function. This is one of the cases when __declspec(thread) is wrong in C++ code.

  • Local variable initialization

    How local variables initialized in CVI?
    Are there any default values for local variables?

    Following function is generated by IVI Scope driver generator.
    If the vertical coupling is GND, variable simOffset is used in an equation without being initialised.
    Is this a bug and it must be initialized?
    * Function: TTTTT_FetchWaveformSafe
    * Purpose: This function returns the data from the instrument. You must
    * range-check all parameters and lock the session before calling
    * this function.
    static ViStatus TTTTT_FetchWaveformSafe (ViSession vi, ViConstString channelName,
    ViInt32 waveformSize, ViReal64 waveform[],
    ViInt32 *actualPoints, ViReal64 *initialX,
    ViReal64 *xIncrement)
    ViStatus error = VI_SUCCESS;
    if (!Ivi_Simulating (vi)) /* call only when locked */
    ViSession io = Ivi_IOSession (vi); /* call only when locked */
    ViChar rdBuf[5000];
    checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));
    /*=CHANGE: ==============================================================*
    Do actual instrument I/O only if not simulating. Example:
    viCheckErr( viPrintf (io, ":WAV %sATA?", channelName));
    viCheckErr( viRead (io, rdBuf, 5000, VI_NULL));
    Change the number of elements in the rdBuf array as appropriate for your
    instrument's maximum record size.
    Convert the rdBuf raw data here to a double precision floating point
    numbers and store the data in the waveform array.
    Read the waveform preamble from the instrument to get the initial X
    and X increment values.
    If the oscilloscope did not resolve all points in the waveform record,
    replace such points with the IVI_VAL_NAN value. The function should
    return the TTTTT__WARN_INVALID_WFM_ELEMENT
    warning in this case.
    *============================================================END=CHANGE=*/
    else
    ViInt32 x;
    ViReal64 yRange, simOffset;
    ViInt32 triggerSlope, vCoup;
    ViReal64 k, level, theta, offset;
    checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL,
    TTTTT_ATTR_HORZ_RECORD_LENGTH,
    0, actualPoints));
    checkErr( Ivi_GetAttributeViReal64 (vi, channelName,
    TTTTT_ATTR_VERTICAL_RANGE,
    0, &yRange));
    checkErr( Ivi_GetAttributeViInt32 (vi, channelName,
    TTTTT_ATTR_VERTICAL_COUPLING,
    0, &vCoup));
    checkErr( Ivi_GetAttributeViReal64 (vi, channelName,
    TTTTT_ATTR_VERTICAL_OFFSET,
    0, &offset));
    checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL,
    TTTTT_ATTR_TRIGGER_SLOPE,
    0, &triggerSlope));
    checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
    TTTTT_ATTR_TRIGGER_LEVEL,
    0, &level));
    checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
    TTTTT_ATTR_HORZ_TIME_PER_RECORD,
    0, xIncrement));
    checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
    TTTTT_ATTR_ACQUISITION_START_TIME,
    0, initialX));
    theta = asin (2*level/yRange);
    if (triggerSlope == TTTTT_VAL_POSITIVE)
    k = 1.0;
    else
    k = -1.0;
    if( *actualPoints>waveformSize )
    *actualPoints = waveformSize; /* Checking number of points to write */
    *xIncrement /= *actualPoints;
    if (vCoup == TTTTT_VAL_DC)
    simOffset = 0.5;
    if (vCoup == TTTTT_VAL_GND)
    k = 0.0;
    for (x = 0; x < *actualPoints; x++)
    ViReal64 y = simOffset + k * 2.5 * sin (*xIncrement * 12560 * x + k * theta) + // ~2 periods of 1kHz sinewave
    (!(x%20)) * (16384 - rand())/150000.0;
    waveform[x] = (offset + yRange/2) > y ? ((offset - yRange/2) < y ? y : (offset - yRange/2)) : (offset + yRange/2);
    Error:
    return error;

  • While local variable initialized inside try block compiler throws error???

    Check out this code where two local variables(one String and the other int type) is declared at the beginning of the method and initialized inside try block. now when i compile this app, it gives an error sayin' that Variables not been initialized. Can anyone tell me why compiler is throwin' an error message?
    Many thanks.
    import java.io.*;
    public class Test{
    public static void main(String[] args){
    String aa;
    int c;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("EnterAnything:");
    try{
    aa = in.readLine();
    c = 1;
    catch(IOException e){
    System.out.println(e.getMessage());
    System.out.println(aa);
    System.out.println(c);
    }

    jfbriere,
    Thanks to u all.
    that every reference to the variable is necessarily preceded
    by execution of an assignment
    to the variable.But I've initialized the variable c and aa inside try block before referencing it as a parameter of println()?
    Can u clarify this?
    --DM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • APEX equivalent of Java Static Initialization Block

    Is there a APEX equivalent of Java static init block (i.e. execute once at class load time)? My use case is that I need to load some configuration values to an environment (i.e. APEX Workspace) specific variables and don't want to do per user session since the values remain the same for all user sessions. I believe SYS_CONTEXT is tied to user session and would not be useful for my usecase. Any advise would be appreciated.

    Hello,
    You should check the concept of User Preferences and see if it can help you:
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21678/aadm_mg_sessions.htm#BABHFEFD
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • Local Variable annotation

    hi
    I've written some lines of code:
    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.LOCAL_VARIABLE)
    public @interface Testable {
         String test() default "haha";
    public class TestAnnotation {
         public static void main(String[] args) {
              @Testable
              String str = new String();
              printAnnotation(str);
         static void printAnnotation(Object str) {
    in printAnnotation i want to see if the passed variable is annotated with @Testable or not.
    But now I dont know how to complete printAnnotation()
    could anyone help me ?
    tanx

    There was no straightforward way to represent local variables and their
    annotations, so no such representation was defined.To me, that's a completely bogus argument. Sun easily could have defined another attribute, similar to the LocalVariableTable, that contains information about a local variable and its annotation.
    I was really excited about all the possibilities of Java annotations... until I noticed this grave oversight.

  • "abstract" modifier for local variable

    Again, I am studying the SCJP 6 and have a question on avaiable access modifier in local variable (within the method).
    The book said the ONLY access modifier allowed for variable within the method is "final", and for method-local inner class is "abstract" or "final". But for fun I tried to write this code:
    public class NewClass1 {
        public static void method1(){
            abstract String a = "hello";
            System.out.println(a);
        public static void main(String[] args){
            method1();
    }can it compiles and runs fine. Also when I change to this below, I can even "change" the value of a refer to, the behaviour seems ignoring the final access modifier:
    public class NewClass1 {
        public static void method1(){
            abstract final String a = "hello";
            a = "free to change the value";
            System.out.println(a);
        public static void main(String[] args){
            method1();
    }So my question are:
    1. Can local variable use the access modifier "abstract"?
    2. If yes, what is the meaning of it?
    Edited by: roamer on 2009?11?16? ??9:55

    it compiles and runs fine
    As I said in the post they were compiled and ran without any error or exception.
    Yes, when "compiling", I got the compilation error which is same to your message^^
    let's see if I got the same error again in my home.I've seen your future, and it's got a compiler error in it.

  • Unable to see local variable values when debugging java

    Hi,
    I am using JDev 10.1.2 with java version 1.4.2_04.
    I have been using JDev to debug my java programs. But suddenly from this morning I am unable to see local variable values. I am able to see class and instance variables. This has happened to me before and I had restarted my machine couple of time, to get this sorted. But this time, nothing helps. Going thru the forum I found out that Include Debug information (Project Properties -> Compiler Option) need to be turned ON. It is already turned ON for me.
    I would greatly appreciate if you could let me know how to crack this problem.
    Thanks in advance.

    No. The local variables 'used' to show up during debugging. But erratically it doesn't show up local variable values. I had to restart my machine couple of times whenever this happens, inorder to see the local variable values. But this time even restarting doesn't help.
    Is there any preference setup that need to be turned on/off to see local variables?
    Also I can't step into a static method now. Any idea why this happens?

  • Local Variable Probelm

    public class Q275d {
        static int a;
        int b;
        public Q275d() {
            int c;
            c = a;
            a++;
            b += c;
        public static void main(String[] args) {
            new Q275d();
    }Since int c is not initialized . It shud give a compiilation error. But it does not. What is the reason behind this. I thought it was a local variable
    Regards,
    http://www.beginner-java-tutorial.com
    Hemanth

    Since int c is not initialized . It shud give a
    compiilation error. But it does not. What is the
    reason behind this. I thought it was a local
    variableYou're initializing it when you say c = a;Perhaps you thought you had to initialize it on the line where you declare it? As in int c = a;You don't need to do that. You just have to initialize it before you try to read its value. Of course, if you know what value you're going to give it at the point of declaration, it's generally considered good practice to do so.

Maybe you are looking for

  • Print, pdf, mail from form

    Hello, I want to print, create pdf file on desktop and send external mail of invoice from SAP form (all in one program). I have following question: 1) can we do all from one program? 2) Will it download pdf file on presentation server (c:\filename.pd

  • White box around png images in Final Cut Express 4.0

    I was putting in some muzzle flashes into my video with final cut express 4.0, they were png images and there was a white box around the muzzle flash after i used the composite mode screen effect, if anybody knows what the problem is i could use the

  • Message bar keeps telling me that Firefox would not allow a page to reload. What does this mean?

    For a few days now when I go to certain sites I get this message at the top of the page "firefox will not allow this page to reload." Then there is a button that says "allow" or an X. Regardless of which I do, it keeps coming back.

  • Ask Apple to add Business themes to iWeb

    On the iWeb Feedback page I noticed there were two questions where Apple includes business as a survey question. They could be thinking about some sort of business support for future releases. If your interested in Apple supporting business on an iWe

  • Can't read pdf-files from the web

    Some pdf-files from the web (using Safari 6) is not readable on my iMac, OSX 10.7.4. I get a lot of instaed of text. Why? /Karin