How to execute a function and return the result into a bind variable

Hi,
I am trying to calculate the sum of salaries of all persons with a particular JOB_ID using a function TOTAL_INCOME(v_job_id).
create or replace function total_income
+(v_job_id IN varchar2)+
RETURN number IS
v_total number(6);
cursor get_sal is
select salary from employees
where job_id = v_job_id;
BEGIN
v_total := 0;
for emp in get_sal
loop
v_total := v_total emp.salary;+
end loop;
dbms_output.put_line('Total salary of '||v_job_id||' is: '|| v_total);
return v_total;
END;
Now I woud like to execute this function and assign the returned value into a bind variable test_sal
variable test_sal number(6)
SELECT total_income('AD_VP') into :test_sal FROM DUAL;
dbms_output.put_line('Total Sal:'||:test_sal);
This is returning the below errors:
SELECT total_income('AD_VP') into :test_sal FROM DUAL
*+
Error at line 0
ORA-01036: illegal variable name/number
dbms_output.put_line('Total Sal:'||:test_sal);
Error at line 3
ORA-00900: invalid SQL statement
Could someone help me what could be the problem?? Thanks for your time...

Dear,
If everything you will do will be done inside PL/SQL (stored procedure or stored function) then you don't have to care about bind variable.
When using PL/SQL (static SQL) you will never encounter issues related to bind variables. PL/SQL itself takes care of your code and uses bind variables behind the scene.
The only situation where you have to look carefully to the use of bind variables within PL/SQL is when you use Dynamic sql into stored procedures or functions.
So, see in the light of the above comment, if you have to care about returning your function into a bind variable?
Best regards
Mohamed Houri

Similar Messages

  • How to convert Smart Form into PDF format and return the result in BAPI?

    I want to convert a Smart Form into PDF format and return the result in BAPI.
    can anyone tell me how it can be done with related example
    regards
    pranay

    hi,
    smart form to pdf--
    All you have to do is call your SF to get OTF and then concert it to PDF. Works like charm:
    DATA: p_output_options TYPE ssfcompop,
    p_control_parameters TYPE ssfctrlop.
    p_control_parameters-no_dialog = 'X'.
    p_control_parameters-getotf = 'X'.
    CALL FUNCTION v_func_name "call your smartform
    EXPORTING
    output_options = p_output_options
    control_parameters = p_control_parameters
    IMPORTING
    job_output_info = s_job_output_info.
    call function 'CONVERT_OTF_2_PDF'
    tables
    otf = s_job_output_info-otfdata
    lines = t_pdf
    and if u need more u can check below links also
    Check the below links..
    Re: Smartforms to PDF
    Re: smartform (otf) as pdf and sending as email-attachment
    VISIT THIS LINK
    Re: Smartforms to PDF
    PLZ REWARD POINTS IF IT HELPS YOU
    rgds
    anver

  • How do I create a 1d array that takes a single calculation and insert the result into the first row and then the next calculation the next time the loop passes that point and puts the results in thsecond row and so on until the loop is exited.

    The attached file is work inprogress, with some dummy data sp that I can test it out without having to connect to equipment.
    The second tab is the one that I am having the problem with. the output array from the replace element appears to be starting at the index position of 1 rather than 0 but that is ok it is still show that the new data is placed in incrementing element locations. However the main array that I am trying to build that is suppose to take each new calculation and place it in the next index(row) does not ap
    pear to be working or at least I am not getting any indication on the inidcator.
    Basically what I am attempting to do is is gather some pulses from adevice for a minute, place the results for a calculation, so that it displays then do the same again the next minute, but put these result in the next row and so on until the specifiied time has expired and the loop exits. I need to have all results displayed and keep building the array(display until, the end of the test)Eventually I will have to include a min max section that displays the min and max values calculated, but that should be easy with the min max function.Actually I thought this should have been easy but, I gues I can not see the forest through the trees. Can any one help to slear this up for me.
    Attachments:
    regulation_tester_7_loops.vi ‏244 KB

    I didn't really have time to dig in and understand your program in depth,
    but I have a few tips for you that might things a bit easier:
    - You use local variables excessively which really complicates things. Try
    not to use them and it will make your life easier.
    - If you flowchart the design (very similar to a dataflow diagram, keep in
    mind!) you want to gather data, calculate a value from that data, store the
    calculation in an array, and loop while the time is in a certain range. So
    theres really not much need for a sequence as long as you get rid of the
    local variables (sequences also complicate things)
    - You loop again if timepassed+1 is still less than some constant. Rather
    than messing with locals it seems so much easier to use a shiftregister (if
    absolutely necessary) or in this case base it upon the number of iterations
    of the loop. In this case it looks like "time passed" is the same thing as
    the number of loop iterations, but I didn't check closely. There's an i
    terminal in your whileloop to read for the number of iterations.
    - After having simplified your design by eliminating unnecessary sequence
    and local variables, you should be able to draw out the labview diagram.
    Don't try to use the "insert into array" vis since theres no need. Each
    iteration of your loop calculates a number which goes into the next position
    of the array right? Pass your result outside the loop, and enable indexing
    on the terminal so Labview automatically generates the array for you. If
    your calculation is a function of previous data, then use a shift register
    to keep previous values around.
    I wish you luck. Post again if you have any questions. Without a more
    detailed understanding of your task at hand it's kind of hard to post actual
    code suggestions for you.
    -joey
    "nelsons" wrote in message
    news:[email protected]...
    > how do I create a 1d array that takes a single calculation and insert
    > the result into the first row and then the next calculation the next
    > time the loop passes that point and puts the results in thsecond row
    > and so on until the loop is exited.
    >
    > The attached file is work inprogress, with some dummy data sp that I
    > can test it out without having to connect to equipment.
    > The second tab is the one that I am having the problem with. the
    > output array from the replace element appears to be starting at the
    > index position of 1 rather than 0 but that is ok it is still show that
    > the new data is placed in incrementing element locations. However the
    > main array that I am trying to build that is suppose to take each new
    > calculation and place it in the next index(row) does not appear to be
    > working or at least I am not getting any indication on the inidcator.
    >
    > Basically what I am attempting to do is is gather some pulses from
    > adevice for a minute, place the results for a calculation, so that it
    > displays then do the same again the next minute, but put these result
    > in the next row and so on until the specifiied time has expired and
    > the loop exits. I need to have all results displayed and keep building
    > the array(display until, the end of the test)Eventually I will have to
    > include a min max section that displays the min and max values
    > calculated, but that should be easy with the min max function.Actually
    > I thought this should have been easy but, I gues I can not see the
    > forest through the trees. Can any one help to slear this up for me.

  • Search in Nested Tables and Insert the result into new Nested Table!

    How can I search in Nested Tables ex: (pr_travel_date_range,pr_bo_arr) using the SQL below and insert the result into a new Nested Table: ex:g_splited_range_arr.
    Here are the DDL and DML SQLs;
    Don't worry about the NUMBER( 8 )
    CREATE OR REPLACE TYPE DATE_RANGE IS OBJECT ( start_date NUMBER( 8 ), end_date NUMBER( 8 ) );
    CREATE OR REPLACE TYPE DATE_RANGE_ARR IS TABLE OF DATE_RANGE;
    DECLARE
       g_splited_range_arr   DATE_RANGE_ARR := DATE_RANGE_ARR( );
       g_travel_range        DATE_RANGE := DATE_RANGE( '20110101', '99991231' );
       g_bo_arr              DATE_RANGE_ARR := DATE_RANGE_ARR( DATE_RANGE( '20110312', '20110317' ), DATE_RANGE( '20110315', '20110329' ) );
       FUNCTION split_date_sql( pr_travel_date_range    DATE_RANGE,
                                pr_bo_arr               DATE_RANGE_ARR )
          RETURN DATE_RANGE_ARR
       IS
          l_splited_range_arr   DATE_RANGE_ARR;
       BEGIN
          SELECT start_date, end_date
            INTO l_splited_range_arr(start_date, end_date)
            FROM (WITH all_dates
                          AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM TABLE( pr_travel_date_range )
                              UNION ALL
                              SELECT tr_end_date, 0 FROM TABLE( pr_travel_date_range )
                              UNION ALL
                              SELECT bo_start_date - 1, 1 FROM TABLE( pr_bo_arr )
                              UNION ALL
                              SELECT bo_end_date + 1, -1 FROM TABLE( pr_bo_arr )),
                       got_analytics
                          AS (SELECT a_date AS start_date,
                                     LEAD( a_date ) OVER (ORDER BY a_date, black_out_val) AS end_date,
                                     SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val) AS black_out_cnt
                                FROM all_dates)
                    SELECT start_date, end_date
                      FROM got_analytics
                     WHERE black_out_cnt = 0 AND start_date < end_date
                  ORDER BY start_date);
          RETURN l_splited_range_arr;
       END;
    BEGIN
        g_splited_range_arr := split_date_sql(g_travel_range,g_bo_arr);
        FOR index_g_splited_range_arr IN g_splited_range_arr .FIRST .. g_splited_range_arr .LAST LOOP       
            DBMS_OUTPUT.PUT_LINE('g_splited_range_arr[' || index_g_splited_range_arr || ']: ' || g_splited_range_arr(index_g_splited_range_arr).start_date || '-'  || g_splited_range_arr(index_g_splited_range_arr).end_date );
        END LOOP;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN OTHERS
       THEN
          NULL;
    END;Or can I create a VIEW with parameters of Nested Tables in it so I can simply call
    SELECT  *
      BULK COLLECT INTO g_splited_range_arr
      FROM view_split_date(g_travel_range,g_bo_arr);

    @riedelme
    For your questions:
    1) I don't want to store in the database as a nested table
    2) I don't want to retrieve data from the database. Data will come from function split_date() parameter and data will be processed in the function and function will return it in nested table format. For more detail please look at the raw function SQL.
    I have a SQL like:
    WITH all_dates
            AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM travel
                UNION ALL
                SELECT tr_end_date, 0 FROM travel
                UNION ALL
                SELECT bo_start_date - 1, 1 FROM black_out_dates
                UNION ALL
                SELECT bo_end_date + 1, -1 FROM black_out_dates),
         got_analytics
            AS (SELECT a_date AS start_date,
                       LEAD( a_date ) OVER (ORDER BY a_date, black_out_val)
                          AS end_date,
                       SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val)
                          AS black_out_cnt
                  FROM all_dates)
      SELECT start_date, end_date
        FROM got_analytics
       WHERE black_out_cnt = 0 AND start_date < end_date
    ORDER BY start_date;I want to change the tables black_out_dates and travel to Nested Array so I can use it in a function with Nested Array travel and Nested Array black_out_dates parameters and the function will return Nested Array of date ranges.
    Here is what I want in raw SQL:
        DECLARE
           g_splited_range_arr   DATE_RANGE_ARR := DATE_RANGE_ARR( );
           g_travel_range        DATE_RANGE := DATE_RANGE( '20110101', '99991231' );
           g_bo_arr              DATE_RANGE_ARR := DATE_RANGE_ARR( DATE_RANGE( '20110312', '20110317' ), DATE_RANGE( '20110315', '20110329' ) );
           FUNCTION split_date_sql( pr_travel_date_range    DATE_RANGE,
                                    pr_bo_arr               DATE_RANGE_ARR )
              RETURN DATE_RANGE_ARR
           IS
              l_splited_range_arr   DATE_RANGE_ARR;
           BEGIN
              SELECT start_date, end_date
                INTO l_splited_range_arr(start_date, end_date)
                FROM (WITH all_dates
                              AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM TABLE( pr_travel_date_range )
                                  UNION ALL
                                  SELECT tr_end_date, 0 FROM TABLE( pr_travel_date_range )
                                  UNION ALL
                                  SELECT bo_start_date - 1, 1 FROM TABLE( pr_bo_arr )
                                  UNION ALL
                                  SELECT bo_end_date + 1, -1 FROM TABLE( pr_bo_arr )),
                           got_analytics
                              AS (SELECT a_date AS start_date,
                                         LEAD( a_date ) OVER (ORDER BY a_date, black_out_val) AS end_date,
                                         SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val) AS black_out_cnt
                                    FROM all_dates)
                        SELECT start_date, end_date
                          FROM got_analytics
                         WHERE black_out_cnt = 0 AND start_date < end_date
                      ORDER BY start_date);
              RETURN l_splited_range_arr;
           END;
        BEGIN
            g_splited_range_arr := split_date_sql(g_travel_range,g_bo_arr);
            FOR index_g_splited_range_arr IN g_splited_range_arr .FIRST .. g_splited_range_arr .LAST LOOP       
                DBMS_OUTPUT.PUT_LINE('g_splited_range_arr[' || index_g_splited_range_arr || ']: ' || g_splited_range_arr(index_g_splited_range_arr).start_date || '-'  || g_splited_range_arr(index_g_splited_range_arr).end_date );
            END LOOP;
        EXCEPTION
           WHEN NO_DATA_FOUND
           THEN
              NULL;
           WHEN OTHERS
           THEN
              NULL;
        END;I must change the tables black_out_dates and travel in a way so it will be something like
    FROM TABLE( pr_travel_date_range )to get the result into l_splited_range_arr so it will be something like
              SELECT start_date, end_date
                INTO l_splited_range_arr(start_date, end_date)
                FROM (

  • Trying to fetch a value in a java function and returning the array.

    hello....I am trying to fetch a value in a java function and returning a array......I already write the pl/sql function which is working fine....but i think i m lost......when i run it through the jsp it shows me error........pls help
    java code:=
    public String [] viewx(String bid) throws SQLException, Exception {
    String [] values;
    try {
    CallableStatement cstmt = null;
    String SQL = "{?=call vi_dis.v_dis(?)}";
    cstmt = con.prepareCall(SQL);
    cstmt.registerOutParameter(1,Types.ARRAY);
    cstmt.setString(2, bid);
    cstmt.execute();
    Array simpleArray = cstmt.getArray(1);
    values = (String [])simpleArray.getArray();
    cstmt.close();
    } catch (SQLException sqle) {
    error = "SQLException: Could not execute the query.";
    throw new SQLException(error);
    } catch (Exception e) {
    error = "An exception occured while retrieving emp.";
    throw new Exception(error);
    return values;
    pl/sql function
    create or replace package vi_dis
    as
    function v_dis(vbid IN student.bid%type) return stuarray ;
    end;
    create or replace
    package body vi_dis
    as
    function v_dis(vbid IN student.bid%type) return stuarray
    is
    l_stu stUarray :=stuarray();
    cursor c_sel
    is
    SELECT CNAME
    FROM COURSE C,ENROLL E
    WHERE C.CID=E.CID
    AND E.BID=vbid;
    BEGIN
    OPEN c_sel;
    FETCH c_sel BULK COLLECT INTO l_stu;
    l_stu.extend;
    CLOSE c_sel;
    RETURN l_stu;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN DBMS_OUTPUT.PUT_LINE('NO RESULT AVAILABLE');
    CLOSE c_sel;
    END;
    END;
    /

    BalusC wrote:
    It is comparing the selected value against the List<SelectItem> returned by getSetoresOrigem() as it is during the apply request values phase of the form submit request.Ok. That's what I supposed JSF was doing.
    BalusC wrote:
    If the selected value isn't in there, then you will get this error.I can understand this, but is this right? As I said, the old value isn't really there because I changed the list values to new ones. But the new value (the value of fSetorOrigem ) corresponds to a value that exist in the new list items, so a valid value. So JSF is not considering that I also changed the list, not just the value. It is comparing the new value with the old list, not the new one. Acting like this JSF is making the page looks like a static HTML page, not a dynamic one. If I can't change the list and the value, what's the point of that? In my point of view I'm not doing anything wrong, I'm not violating any JSF rules.
    Marcos

  • How to execute a procedure depending on the result of a query?

    Hello, I'm new in ODI.
    I want to execute a procedure depending on the result of a query Oracle table.
    We have a Oracle Table whit a column that contains two possibles values.
    I want read the table, row by row, and depending on this value, execute a Procedure or execute another.
    How can i do?

    what you need to do is
    1. create a variable which "new_var2" which has the count of the number of rows you want to process. must be data type numeric.
    2. copy "new_var2" to the package screen.
    3. duplicate the "new_var2" on the package screen and evaluate the variable and test for "> 0" zero, call it "new_var2_E"
    3. create a new odi variable "new_var1" with a refresh of "select field1 fom (select field1,rownum as rownumber from tablex) where rownumber = #new_var2" in the relevant schema and technology.
    4. copy "new_var1" into your package (some where in the flow)
    5. right click the "new_var1" variable in you package screen and you should get the option duplicate step (click on that)
    6. select the the duplicate "new_var1" on the package screen and correct the the name to something meaning full to you "new_var1_E", also change the "type" to "evaluate variable" then you should see a "value" box. enter one of the values you want to test in the box (remember do not put in quotes ' )
    7. now back on the package screen join the "new_var1" to the "new_var1_E" with an OK line
    8 you now join "new_var2" to "new_var2_E" with OK
    9 you join "new_var2_E" to "new_var1"
    10. you then join the "new_var1_E" with an OK or a KO line to the relevant procedure.
    12. you need to duplicate "new_var2" in the package screen one more time this time and call it "new_var2_D" set the type to evaluate and then select the increment of -1
    13. the relevant procedure to "new_var2_D" with an OK
    14. join the "new_var2_D" to the "new_var2_E" with an OK
    15. this should close off the loop now the exit point is "new_var2_E" with a KO line to the next part of your process....
    Basically you should end up with a loop on new_var2 decementing, and it is used to get a specific next record row from your table.
    Hope this helps, sorry it is a little long winded..
    Edited by: DavidGD on Feb 8, 2009 3:29 PM

  • How to read a file and save the contents into array list

    i have textfile contains information like:
    Name: James Smith
    Customer no: 663,282
    Post code: BA1 74E
    Telephone no: 028-372632
    Last modified: Feb 10, 2008 6:50:00 PM GMT
    Name: Janet Smith
    Customer no: 663,283
    Post code: BA1 74E
    Telephone no: 028-372632
    Last modified: Jan 11, 2007 8:10:05 PM GMT
    etc...
    how can i read the contents of this textfile and put the data into an ArrayList called ArrayList<Customer> customerList.
    i knew that i need two classes, one for CustomerDetails and one for ReadFile.
    i have already done the customer class as:
    import java.util.Date;
    public class Customer
        String Name;
        int CustomerNo;
        String Postcode;
        String teleNo;
        Date lastModified;
        public Customer(String Name, int CustomerNo, String Postcode, String teleNo, Date lastModified)
         assign(Name, CustomerNo, Postcode, teleNo, lastModified);
        public void assign(String Name, int CustomerNo, String Postcode, String teleNo, Date lastModified)
         this.Name=Name;
         this.CustomerNo=CustomerNo;
         this.Postcode=Postcode;
         this.teleNo=teleNo;
         this.lastModified=lastModified;
        public String toString()
         String allDetails = "Name: "+Name+
             ", Customer No: "+CustomerNo+
             ", Postcode:"+Postcode+
             ", Telephone No: "+teleNo+
             ", Last Modified Date: "+lastModified;
         return allDetails;
    }i just wondering how can i code the ReadFile class?
    can anyone help me please. thank you in advance.

    thank you for your suggestion, but i have already started to code the readCustomer class using the Scanner.
    the code i got so far is:
    import java.util.Scanner;
    import java.io.*;
    public class readCustomer
        public static void main(String[] args)
         readCustomer("Customers.txt");
        public static void readCustomer(String filename)
         try {
             Scanner scanner = new Scanner(new File(filename));
             scanner.useDelimiter(System.getProperty("line.separator"));
             while (scanner.hasNext()) {
              processLine(scanner.next());
             scanner.close();
         } catch (FileNotFoundException e) {
             e.printStackTrace();
        public static void processLine(String line)
         Scanner scanner2 = new Scanner(line);
         scanner2.useDelimiter("\\s*:\\s*");
         String description = scanner2.next();
    *// here is where i am struggling. i don't know how to get the information after the : sign*   
    }i am currently struggling with the processLine method?
    also, i am not sure how to group a set of information and put them into the arraylist.
    Any hint, please. Thank you.
    Edited by: mujingyue on Feb 26, 2008 12:42 PM

  • [LV - TS] How to execute a SEQ file, get the result (PASS/FAIL) and the report file ?

    Hello,
    I'm looking for the most obvious and simple way to, from Labview :
    1- Start the Teststand engine : DONE
    2- Get a list of SEQ files to execute : DONE
    3- Loop through the list to execute each SEQ file : <- found some examples but I have some trouble with the UIMessage stuff
    http://zone.ni.com/reference/en-XX/help/370052N-01/tsexamples/infotopics/executing_sequences_using_api_labview/
    4- Get the result of the SEQ execution : <- unsure
    5- Get the XML path+name of the report file generated : <- obviously not easy
    http://digital.ni.com/public.nsf/allkb/3D3B2358DF9B786B8625789500549A3B
    http://forums.ni.com/t5/NI-TestStand/Getting-Report-File-Path-location-at-execution-in-TestStand-2012/td-p/3041789
    Here is my current implementation :
    David Koch
     

    Hello,
    I tried to work from this example :
    http://forums.ni.com/t5/NI-TestStand/Execution-of-TestStand-Sequence-in-LabVIEW-via-TS-API-Different/td-p/2939616/page/2#M46686
    However it remains unclear about how to get a simple
    answer from just running a sequence file out of any
    model so far (Simple Pass). Like I told you, all what
    I need, once the TS engine is started, is a VI with the
    following interface :
    INPUT
    1- TS engine reference
    2- SEQ file path (path or string)
    3- Sequence name to execute
    4- UUT string (optional, but yeah)
    5- error in
    OUTPUT
    1- Result boolean (PASS/FAIL)
    2- Path to XML report
    3- error out
    It would be so cool to just have this
    About the surrounding UI, I'm working on it. The LV
    code is not really important at this point, it's running
    a SEQ file that matters to me.
    David Koch
     

  • How to join two lists and display the results in datasheet view.?

    hello,
    i have two lists that i would like to join, i know a method that has been described  in the link below
    http://www.codeproject.com/Articles/194252/How-to-Link-Two-Lists-and-Create-a-Combined-Ciew-i
    however, here the data view is only limited to 30 rows and my resultant list is huge. I would like to know if there is a possibility to view the resultant list in a data sheet view ?

    I don't believe you can use the OOTB Datasheet view when joining lists. However, you should be able to increase your limit from 30 items to as many as you need (that doesn't trip the threshold set in Central Admin).
    Dimitri Ayrapetov (MCSE: SharePoint)

  • (Urgent help needed) how to read txt file and store the data into 2D-array?

    Hi, I have a GUI which allow to choose file from the file chooser, and when "Read file" button is pressed, I want to show the array data into the textarea.
    The sample data is like this followed:
    -0.0007     -0.0061     0.0006
    -0.0002     0.0203     0.0066
    0     0.2317     0.008
    0.0017     0.5957     0.0008
    0.0024     1.071     0.0029
    0.0439     1.4873     -0.0003
    I want my program to scan through and store these data into 2D array.
    However for some reason, my source code issues errors, and I don't know what's wrong with it, seems to have a problem in StringTokenizer though. Can anybody help me?
    Thanks in advance.
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.StringTokenizer;
    public class FileReduction1 extends JFrame implements ActionListener{
    // GUI features
    private BufferedReader fileInput;
    private JTextArea textArea;
    private JButton openButton, readButton,processButton,saveButton;
    private JTextField textfield;
    private JPanel pnlfile;
    private JPanel buttonpnl;
    private JPanel buttonbar;
    // Other fields
    private File fileName;
    private String[][] data;
    private int numLines;
    public FileReduction1(String s) {
    super(s);
    // Content pane
         Container cp = getContentPane();
         cp.setLayout(new BorderLayout());     
    // Open button Panel
    pnlfile=new JPanel(new BorderLayout());
         textfield=new JTextField();
         openButton = new JButton("Open File");
    openButton.addActionListener(this);
    pnlfile.add(openButton,BorderLayout.WEST);
         pnlfile.add(textfield,BorderLayout.CENTER);
         readButton = new JButton("Read File");
    readButton.addActionListener(this);
         readButton.setEnabled(false);
    pnlfile.add(readButton,BorderLayout.EAST);
         cp.add(pnlfile, BorderLayout.NORTH);
         // Text area     
         textArea = new JTextArea(10, 100);
    cp.add(new JScrollPane(textArea),BorderLayout.CENTER);
    processButton = new JButton("Process");
    //processButton.addActionListener(this);
    saveButton=new JButton("Save into");
    //saveButton.addActionListener(this);
    buttonbar=new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonpnl=new JPanel(new GridLayout(1,0));
    buttonpnl.add(processButton);
    buttonpnl.add(saveButton);
    buttonbar.add(buttonpnl);
    cp.add(buttonbar,BorderLayout.SOUTH);
    /* ACTION PERFORMED */
    public void actionPerformed(ActionEvent event) {
    if (event.getActionCommand().equals("Open File")) getFileName();
         if (event.getActionCommand().equals("Read File")) readFile();
    /* OPEN THE FILE */
    private void getFileName() {
    // Display file dialog so user can select file to open
         JFileChooser fileChooser = new JFileChooser();
         fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
         int result = fileChooser.showOpenDialog(this);
         // If cancel button selected return
         if (result == JFileChooser.CANCEL_OPTION) return;
    if (result == JFileChooser.APPROVE_OPTION)
         fileName = fileChooser.getSelectedFile();
    textfield.setText(fileName.getName());
         if (checkFileName()) {
         openButton.setEnabled(false);
         readButton.setEnabled(true);
         // Obtain selected file
    /* READ FILE */
    private void readFile() {
    // Disable read button
    readButton.setEnabled(false);
    // Dimension data structure
         getNumberOfLines();
         data = new String[numLines][];
         // Read file
         readTheFile();
         // Output to text area     
         textArea.setText(data[0][0] + "\n");
         for(int index=0;index < data.length;index++)
    for(int j=1;j<data[index].length;j++)
    textArea.append(data[index][j] + "\n");
         // Rnable open button
         openButton.setEnabled(true);
    /* GET NUMBER OF LINES */
    /* Get number of lines in file and prepare data structure. */
    private void getNumberOfLines() {
    int counter = 0;
         // Open the file
         openFile();
         // Loop through file incrementing counter
         try {
         String line = fileInput.readLine();
         while (line != null) {
         counter++;
              System.out.println("(" + counter + ") " + line);
    line = fileInput.readLine();
         numLines = counter;
    closeFile();
         catch(IOException ioException) {
         JOptionPane.showMessageDialog(this,"Error reading File",
                   "Error 5: ",JOptionPane.ERROR_MESSAGE);
         closeFile();
         System.exit(1);
    /* READ FILE */
    private void readTheFile() {
    // Open the file
    int row=0;
    int col=0;
         openFile();
    System.out.println("Read the file");     
         // Loop through file incrementing counter
         try {
    String line = fileInput.readLine();
         while (line != null)
    StringTokenizer st=new StringTokenizer(line);
    while(st.hasMoreTokens())
    data[row][col]=st.nextToken();
    System.out.println(data[row][col]);
    col++;
    row++;
    closeFile();
    catch(IOException ioException) {
         JOptionPane.showMessageDialog(this,"Error reading File",
                   "Error 5: ",JOptionPane.ERROR_MESSAGE);
         closeFile();
         System.exit(1);
    /* CHECK FILE NAME */
    /* Return flase if selected file is a directory, access is denied or is
    not a file name. */
    private boolean checkFileName() {
         if (fileName.exists()) {
         if (fileName.canRead()) {
              if (fileName.isFile()) return(true);
              else JOptionPane.showMessageDialog(null,
                        "ERROR 3: File is a directory");
         else JOptionPane.showMessageDialog(null,
                        "ERROR 2: Access denied");
         else JOptionPane.showMessageDialog(null,
                        "ERROR 1: No such file!");
         // Return
         return(false);
    /* FILE HANDLING UTILITIES */
    /* OPEN FILE */
    private void openFile() {
         try {
         // Open file
         FileReader file = new FileReader(fileName);
         fileInput = new BufferedReader(file);
         catch(IOException ioException) {
         JOptionPane.showMessageDialog(this,"Error Opening File",
                   "Error 4: ",JOptionPane.ERROR_MESSAGE);
    System.out.println("File opened");
    /* CLOSE FILE */
    private void closeFile() {
    if (fileInput != null) {
         try {
              fileInput.close();
         catch (IOException ioException) {
         JOptionPane.showMessageDialog(this,"Error Opening File",
                   "Error 4: ",JOptionPane.ERROR_MESSAGE);
    System.out.println("File closed");
    /* MAIN METHOD */
    /* MAIN METHOD */
    public static void main(String[] args) throws IOException {
         // Create instance of class FileChooser
         FileReduction1 newFile = new FileReduction1("File Reduction Program");
         // Make window vissible
         newFile.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         newFile.setSize(500,400);
    newFile.setVisible(true);
    Java.lang.NullpointException
    at FileReductoin1.readTheFile <FileReduction1.java :172>
    at FileReductoin1.readFile <FileReduction1.java :110>
    at FileReductoin1.actionPerformed <FileReduction1.java :71>
    .

    1) Next time use the CODE tags. this is way too much unreadable crap.
    2) The problem is your String[][] data.... the only place I see you do anything approching initializing it is
    data = new String[numLines][];I think you want to do this..
    data = new String[numLines][3];anyway that's why it's blowing up on the line
    data[row][col]=st.nextToken();

  • How to merge text files and put the result in a text file.

    Hi,
    I am trying to merge the files(text) using OWB and I would like to put the result in a file. Could any one please explain how to do this.
    Thanks and regards
    Gowtham Sen.

    using the unix commnad 'cat' along with the redirect '>>' will concat the files into one target
    #this will create the target file and over-write it if it existed already
    cat file1 > target
    ##Now add the rest of the files to the target, without over-writing
    cat file2 >>target
    cat file3 >>target
    cat file16 >> target
    You can then use an external table on the target file.
    A nicer way would be to user a 'for loop', but this will work fine.

  • How do I join two tables in the same database and load the result into a destination table in a SSIS package

    Hi,
    I have a query that joins two tables in the same database, the result needs to be loaded in a destination DB table.  How do I do this in SSIS package?
    thank you !
    Thank You Warmest Fanny Pied

    Please take a look at these links related to your query.
    http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers
    http://stackoverflow.com/questions/7037228/joining-two-tables-together-in-one-database

  • How to get the results for given Bind Variable

    Hi
    Can any one help me how to get the result rows from the View Object after executing the view object query by setting bind variable?
    snippet as follows
    viewObject.setNamedWherClauseParams("name","hei");
    viewObject.executeQuery();
    How to get the results from viewObject is my question..?
    Thanks in advance

    Should be something like
    while (vo.hasNext()){
    Row r = vo.next();
    r.getAttribute....
    You might want to read the "most commonly used methods" appendix in the ADF Developer Guide.

  • How to execute this Procedure and get the output?

    I have created a Procedure the source code of the same is furnished below.
    create or replace procedure vin_test( p_deptno IN number
    , p_cursor OUT SYS_REFCURSOR)
    as
    v_res Emp%rowtype;
    begin
    open p_cursor FOR
    select *
    from emp
    where deptno = p_deptno;
    end vin_test;
    Now, if i want to see the out put of this Proc
    i will first set the Serveroutput on and then..
    Exec vin_test(10);
    I am getting an error saying wrong number of arguments,so can anybody tell me what parameter value should i pass on so that i can get desired output.
    Thanks in Advance
    OraCrazy

    In sqlplus you can do like this.
    SQL> create or replace procedure vin_test( p_deptno IN number, p_cursor OUT SYS_REFCURSOR)
      2  as
      3     v_res Emp%rowtype;
      4  begin
      5     open p_cursor for
      6     select *
      7       from emp
      8      where deptno = p_deptno;
      9  end;
    10  /
    Procedure created.
    SQL> var lcur refcursor
    SQL> exec vin_test(30,:lcur)
    PL/SQL procedure successfully completed.
    SQL> print lcur
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO        DIV
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30         10
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30         10
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30         10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30         10
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30         10
    6 rows selected.Thanks,
    Karthick.

  • Function that return the results of a select

    Hi,
    I would like to create a function on the famous HR oracle Departments table to select * from it. I don't know how to do it.
    Does anybody can help me?.
    Thank you

    Oracle stored functions cannot directly return result sets but can return REF CURSOR. Please read [Optimize Result Set Retrieval Using ODP.NET and Ref Cursors |http://www.oracle.com/technology/pub/articles/mastering_dotnet_oracle/williams_refcursors.html] which gives full examples in PL/SQL for server side and in VB. Net for client side.

Maybe you are looking for

  • User Exit for sale order for adding a new partner

    Hi i am having the Scenario to add a new partner in  sales order in both VA01 / va02 transaction . i am using the exit named MV45AFZZ .   (USEREXIT_MOVE_FIELD_TO_VBAP) for this scenario. Its perfectly working for VA01 , but not VA02 .. why .. can any

  • Creating text filed template

    Hi, is it possible to change some attributes of Text Filed (HTML INPUT) for all text fields in application? To do something like CSS but for JS? I can't define something like Text Field Template in Theme edit option. I want to automatically trim valu

  • Adobe elements 5.0

    I tried to open elements 5.0 on my windows xp and it said that my company name and serial no's werent there. So i deleted the program and tried to install again but it came up with came up with error code 1304 it says verify that i have access to tha

  • My iTunes won't force quit and says it's still syncing my iPhone after hours of syncing.

    My iTunes won't force quit and says it's still syncing my iPhone after hours of syncing. I had plugged in my iPhone 4S in the morning before I left for school, it synced almost completely, and then it got stuck on "Finishing Sync". I pulled my iPhone

  • How to add shipping instructions while creating SO

    Hi All, I'm using the BAPI_SALESORDER_CREATEFROMDAT1 to create Sales Order. I want to add shipping instructions while creating each orders. How do I pass this information to the backend with this BAPI? Thanks Thruna