Fetching from a cursor and writing to a file in Pro*C

Hi guys,
I have a situation in hand here and I guess my "C" skills are putting me up to the test. My cursor is fetching 3 records and its all fine. I am also being able to sprintf those details and the fprintf also works perfectly -- except when I come back for Record 2, the details get overwritten and finally Record 3 is what remains on the file.
I know that UTL_FILE.PUT_LINE works just fine in Loops but here I seem to be doing somethign wrong. Has anyone seen this problem or situation before ?
void get_student_data(void)
   FILE   *student_file;
   char    student_file_name[100];
  exec sql begin declare section;
  exec sql end declare section;
      if ((student_file = fopen(student_file_name,"w")) == NULL)
          printf("Error opening data file!\n");
   exec sql declare student_cur cursor for
         select  s.student_id
                  to_char(s.start_date,'DD-Mon-YYYY'),
                  s.student_addr1,
                  s.student_addr2,
                  s.city,
                  s.state,
                  s.zip_code
         from   student s
         order by s.student_id;
   exec sql open student_cur;
   for (;;)
      exec sql fetch student_cur
          into  :cur_student_id,
                 :cur_start_date,
                 :cur_addr1,
                 :cur_addr2,
                 :cur_city,
                 :cur_state,
                 :cur_zip_code;
      if (sqlcode > 0)
         break;
   sprintf(out_line, "\"%d\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\","\n",
                     student_id,
                     (char *)start_date.arr,
                     (char *)addr1.arr,
                     (char *)addr2.arr,
                     (char *)city.arr,
                     (char *)state.arr,
                     (char *)zip_code.arr );
   fprintf(student_file, out_line);
   exec sql close student_cur;
   if (!student_file == NULL))
      fclose(student_file_file);
{code}
Thanks a bunch !
Edited by: RDonASunnyDay on Oct 20, 2009 11:07 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Hi riedelme,
The program is working fine. The procedure I am calling happens to be inside a FOR loop which I did not mention and that's my fault. You guys were on the right track.
If you notice, the fclose(filename) was at the very end of the procedure but everytime the procedure is called in the out for loop, the file gets opened and closed. So, that's why the file has always one record !
However, the logic of closing the cursor shoudl still be after closing the inner for loop.
Thanks

Similar Messages

  • Optimal number of records to fetch from Forte Cursor

    Hello everybody:
    I 'd like to ask a very important question.
    I opened Forte cursor with approx 1.2 million records, and now I am trying
    to figure out the number of records per fetch to obtain
    the acceptable performance.
    To my surprise, fetching 100 records at once gave me approx 15 percent
    performance gain only in comparsion
    with fetching records each by each.
    I haven't found significant difference in performance fetching 100, 500 or
    10.000 records at once.In the same time, fetching 20.000
    records at once make a performance approx 20% worse( this fact I cannot
    explain).
    Does anybody have any experience in how to improve performance fetching from
    Forte cursor with big number of rows ?
    Thank you in advance
    Genady Yoffe
    Software Engineer
    Descartes Systems Group Inc
    Waterloo On
    Canada

    You can do it by writing code in start routine of your transformations.
    1.If you have any specific criteria for filtering go with that and delete unwanted records.
    2. If you want to load specific number of records based on count, then in start routine of the transformations loop through source package records by keeping a counter till you reach your desired count and copy those records into an internal table.
    Delete records in the source package then assign the records stored in internal table to source package.

  • My mother got an iPad air after she thought her old iPad was locked up with voice over anyway it says to hook to itunes i told it to fetch from the iCloud and it wont hook up to iTunes can someone help?

    my mother got an iPad air after she thought her old iPad was locked up with voice over anyway it says to hook to itunes i told it to fetch from the iCloud and it wont hook up to iTunes can someone help?

    Punctuation would make your post a little easier to read and understand.
    What do you mean it won't hook up to iTunes? you mean iTunes does not recognize the device? If that's what you mean, one of these might be helpful.
    iOS: Device not recognized in iTunes for Windows
    iOS: Device not recognized in iTunes for Mac OS X

  • How can I extract certain pages from my document and save as another file?

    How can I extract certain pages from my document and save as another file?

    You would need Adobe Acrobat to do that, not Adobe Reader.

  • I want to initialize my MBpro end reinstall lino, but I purchased it from apple store and cancelled the installation file. If i try to download again it from appstore I couldn't...How I can do ? Please help me

    I want to initialize my MBpro end reinstall lino, but I purchased it from apple store and cancelled the installation file. If i try to download again it from appstore I couldn't...How I can do ? Please help me

    Thanks for the feedback. Now, before installing in, put a copy some place safe and you won't have to download it again, wasting bandwidth, time, and electricity. Why? Because the installer blows itself away during the installation—IMO, a braindead delivery system, copied from their iOS world, but totally unsuitable for computers.

  • HT1725 Hi, a few hours ago I purchased an "audio book" from i-tunes and i samw the files were downloading on my iPad, but  I cannot find the audio book! What happened? Please, guide me

    Hi, a few hours ago I purchased an "audio book" from i-tunes and i samw the files were downloading on my iPad, but  I cannot find the audio book! What happened?

    HI CEGS,
    Welcome to the Support Communities!
    Audiobooks can be found in your Music app on the iPad.
    I've referenced the section of the iPad User Guide (page 78):
    manuals.info.apple.com/en_US/ipad_user_guide.pdf
    See additional browse buttons: Tap More.
    I hope this information helps ....
    Have a great day!
    - Judy

  • Iterative query to fetch from one column and insert/update in another colum

    i have a table with 5 columns as shown below
    Devicedetails
    userid ip deviceid makeby makedate
    123 100.00.20.11 | 00002011 xyz 10/11/2009
    456 102.03.21.12 | 02032112 def 11/12/2009
    678 null 02032112 def 11/12/2009
    896 111.22.33.44 02032112 def 11/12/2009
    in the above example i need to pick the value from deviceid - 022032112 and brake it in ot 02.03.21.12 (. after every tow digits) and prefix 1 (number one) at the end
    i am trying to write using cursor below not getting any idea
    1) I need to get the deviceid and subsctring it and update if the ip is there else insert

    SELECT REGEXP_REPLACE
              ('022032112',
               '([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{1})',
               '\1.\2.\3.\4.1\5'
              ) TEST
      FROM DUAL
    WHERE LENGTH ('022032112') = 9;o/p
    TEST
    02.20.32.11.12
    SELECT REGEXP_REPLACE
              ('02032112',
               '([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2})',
               '\1.\2.\3.1\4'
              ) TEST
      FROM DUAL
    WHERE LENGTH ('02032112') = 8;Edited by: DeepakDevarapalli on Nov 11, 2009 10:57 AM

  • How to retrieve characters like '£' from the database and write to xml file

    Hi ,
    I have a requirement to retrieve the data from database and write to files in XML format.
    I am able to do so successfuly by using XMLElement tag and writing to file through UTL_File package.
    All characters like <&@^ get converted properly, but when it comes to multibyte chars like '£', they are not able to get converted as it is.
    Can somebody please advise me how to go ahead.
    Regards

    Thanks odie.
    The nls_charset for my database is WE8ISO8859P1 and database version is Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi.
    The data (with pound sign) is sitting in one of the columns of the table and when i query it directly, I am able to view it properly.
    However when I use the below code to retrieve in XML format and print it to file, it gets changed. This file is also passed to one of the application GUI where this XML gets processsed and it is not visible properly.
    below id the sample abstract of code I am using.
    Declare
    l_file UTL_FILE.FILE_TYPE;
    l_clob CLOB;
    l_buffer VARCHAR2(32767);
    l_amount BINARY_INTEGER := 32767;
    l_pos INTEGER := 1;
    Begin
    SELECT XMLElement("case",
    XMLElement("comments",
    XMLElement("comment",
    XMLElement("comments",a.COMMENTS)
    ).getClobVal() val1 into l_clob
    FROM TO_COMMENTS a
    l_file :=
    UTL_FILE.fopen (XMLDIR,
    test.xml,
    'w',
    32767);
    LOOP
    DBMS_LOB.read (l_clob,
    l_amount,
    l_pos,
    l_buffer);
    UTL_FILE.put_line (l_file, l_buffer);
    l_pos := l_pos + l_amount;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.NEW_LINE('Reached end of file');
    END;
    The comments column given contains the character like pound.
    And once the file is generated and i see using the vi editor, the char is not viewable properly like £
    And when the same is passed to GUI application to be processed, its not viewable propely in GUI from IE as well like �.

  • How can i control NI-6115 to collect data from 2 channels and save as 2 files?

    I want to program NI-6115 card to collect data from 2 channels and save the two data into two different filenames that i specified?
    How do i write in labview codes?

    Calibur,
    LabVIEW includes a number of examples that demonstrate how to acquire analog input data and write it to disk. Dependent upon the type of file you would like to use, I would suggest that you examine one of the following examples:
    Cont Acq to File (binary).vi
    Cont Acq to File (scaled).vi
    Cont Acq to Spreadsheet File.vi
    With regards to writing each channel's data to a separate file, you will need to use the Index Array function to generate two 1-D arrays, each containing data for one channel. These arrays can then be written to separate files using two Write File functions.
    Good luck with your application.
    Spencer S.

  • Reading and Writing large Excel file using JExcel API

    hi,
    I am using JExcelAPI for reading and writing excel file. My problem is when I read file with 10000 records and 95 columns (file size about 14MB), I got out of memory error and application is crashed. Can anyone tell me is there any way that I can read large file using JExcelAPI throug streams or in any other way. Jakarta POI is also showing this behaviour.
    Thanks and advance

    Sorry when out of memory error is occurred no stack trace is printed as application is crashed. But I will quote some lines taken from JProfiler where this problem is occurred:
              reader = new FileInputStream(new File(filePath));
              workbook = Workbook.getWorkbook(reader);
              *sheeet = workbook.getSheet(0);* // here out of memory error is occured
               JProfiler tree:
    jxl.Workbook.getWorkBook
          jxl.read.biff.File 
                 jxl.read.biff.CompoundFile.getStream
                       jxl.read.biff.CompoundFile.getBigBlockStream Thanks

  • Very slow painting while reading and writing doubles into file

    for 15MB length file i = 7662080
    for 50MB length file i = 12414368
    Part of Code for writing into file follows like this:
    try{
    fos = new FileOutputStream("Angel.txt");
    File f = new File("Angel.txt");
         if(f.length() >=4)
         f.delete();
    fos = new FileOutputStream("Angel.txt");     
    dos = new DataOutputStream(new BufferedOutputStream(fos,1000000));
    int x=0;
    double y_last, y_new;
    for(int j=0 ;j<i ;j++)
    if(some condition)
    y_new = ....;
    try{
    //previously in vectors
    y_last = y_new;
    vect.add(new Line2D.Double(x, y_last, x, y_new)_;
    dos.writeDouble(y_new);
         }catch(Exception e){System.out.println(e);}
    dos.close();
    fos.close();
    x++;
    }catch(Exception excp){System.out.println(excp);}
    part of code for reading from file follows like this:
    public void paint(Graphics g)
    try{
         double y1, y2 =0;               
         Line2D.Double doub;
         raf = new RandomAccessFile("Angel.txt","r");
         dis = new DataInputStream(new BufferedInputStream(new FileInputStream(raf.getFD(),1000000)));
         raf.seek((rect.x*8));
         for (int i = 0/any value; (i < value as per choice); i++)
              g2.setStroke(new BasicStroke(0)); //2
              y1 = y2;
         y2 =dis.readDouble();
              doub=new Line2D.Double(i,y1,i,y2);
              g2.draw(doub);
    dis.close();
         raf.close();
    }catch(Exception excp){System.out.println(excp);}
    I tried using Object Streams but NotSerializable Exception is thrown as Line2D.Double objects
    are not serialized.
    Any idea to make reading and writing into file specially from MB files faster is appreciated.

    Why are you reading in the file in the paint method ?
    Create your data once before painting.
    I think you should explain what is your goal and what behavior you want.
    Denis

  • Need help Take out the null values from the ResultSet and Create a XML file

    hi,
    I wrote something which connects to Database and gets the ResultSet. From that ResultSet I am creating
    a XML file. IN my program these are the main two classes Frame1 and ResultSetToXML. ResultSetToXML which
    takes ResultSet & Boolean value in its constructor. I am passing the ResultSet and Boolean value
    from Frame1 class. I am passing the boolean value to get the null values from the ResultSet and then add those
    null values to XML File. When i run the program it works alright and adds the null and not null values to
    the file. But when i pass the boolean value to take out the null values it would not take it out and adds
    the null and not null values.
    Please look at the code i am posing. I am showing step by step where its not adding the null values.
    Any help is always appreciated.
    Thanks in advance.
    ============================================================================
    Frame1 Class
    ============
    public class Frame1 extends JFrame{
    private JPanel contentPane;
    private XQuery xQuery1 = new XQuery();
    private XYLayout xYLayout1 = new XYLayout();
    public Document doc;
    private JButton jButton2 = new JButton();
    private Connection con;
    private Statement stmt;
    private ResultSetToXML rstx;
    //Construct the frame
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    xQuery1.setSql("");
    xQuery1.setUrl("jdbc:odbc:SCANODBC");
    xQuery1.setUserName("SYSDBA");
    xQuery1.setPassword("masterkey");
    xQuery1.setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    xQuery1.setSql("Select * from Pinfo where pid=2 or pid=4");
    jButton2.setText("Get XML from DB");
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException ex) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(ex.getMessage());
    try {
    con = DriverManager.getConnection("jdbc:odbc:SCANODBC","SYSDBA", "masterkey");
    stmt = con.createStatement();
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton2_actionPerformed(e);
    contentPane.add(jButton2, new XYConstraints(126, 113, -1, -1));
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    void jButton2_actionPerformed(ActionEvent e) {
    try{
    OutputStream out;
    XMLOutputter outputter;
    Element root;
    org.jdom.Document doc;
    root = new Element("PINFO");
    String query = "SELECT * FROM PINFO WHERE PID=2 OR PID=4";
    ResultSet rs = stmt.executeQuery(query);
    /*===========This is where i am passing the ResultSet and boolean=======
    ===========value to either add the null or not null values in the file======*/
    rstx = new ResultSetToXML(rs,true);
    } //end of try
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    ======================================================================================
    ResultSetToXML class
    ====================
    public class ResultSetToXML {
    private OutputStream out;
    private Element root;
    private XMLOutputter outputter;
    private Document doc;
    // Constructor
    public ResultSetToXML(ResultSet rs, boolean checkifnull){
    try{
    String tagname="";
    String tagvalue="";
    root = new Element("pinfo");
    while (rs.next()){
    Element users = new Element("Record");
    for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
    tagname= rs.getMetaData().getColumnName(i);
    tagvalue=rs.getString(i);
    System.out.println(tagname);
    System.out.println(tagvalue);
    /*============if the boolean value is false it adds the null and not
    null value to the file =====================*/
    /*============else it checks if the value is null or the length is
    less than 0 and does the else clause in the if(checkifnull)===*/
    if(checkifnull){ 
    if((tagvalue == null) || tagvalue.length() < 0 ){
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    root.addContent(users);
    out=new FileOutputStream("c:/XMLFile.xml");
    doc = new Document(root);
    outputter = new XMLOutputter();
    outputter.output(doc,out);
    catch(IOException ioe){
    System.out.println(ioe);
    catch(SQLException sqle){

    Can someone please help me with this problem
    Thanks.

  • How do I transfer Notes from my iPhone4s and iPad to my new MacBook Pro?

    How do I transfer Notes from my iPhone4s and iPad to my new 13" MacBook Pro with retina display?

    Finally figured it out...
    1) Open mail/compose notes on your macbook...
    2) copy and paste every note from Outlook to a new note in Mail.
    3) Open iTunes. In Info/Advanced tick Notes. This will replace / copy all Notes from Mail to your iPhone...
    4) Voila! Notes are on iPhone...
    I must say in spite of all the fabulous advantages of a Macbook and an iPhone, syncing really does suck...
    Transferring data from another smartphone to a Mac or an iPhone is tough...
    Features like "one way / two way" sync for Phone / computer or allowing us to select which whose, phone or computer, will be considered more important so that you can choose whose data will overwrite the other, are not there in iTunes... This is something which really needs to be there...
    Anyways... problem solved for now...
    ciao...
    Jesal

  • HOW TO RETRIEVE A LONG RAW COLUMN FROM A TABLE AND WRITE TO OS FILE

    Good evening.
    Please how can I read a long raw datatype from a table and insert into an operating system file using PL/SQL.
    Thank you.

    What does this have to do with LONG RAW? It is about UTL_FILE and not especially great code.
    The question is how to retrieve and write LONG RAW and that is quite a different matter.
    First you must convert it to BLOB.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:13213885403654
    Then you can write it out to the file system
    http://www.morganslibrary.org/reference/utl_file.html
    Look at the "Extract Blob" demo

  • Record Sound From a Microphone and convert it text file using jave applicat

    Hi, I want source code for recording sound from a microphone which is connected to a sound card fixed in my machine,and convert that sound file to a text file , so that i can compare that text later with the command which i have stored already in my computer.How to do this in Java ? If any one could help me in solving this problem, it would be very helpful for me !

    Have you looked into the JSAPI?
    http://www.esus.com/docs/GetQuestionPage.jsp?uid=1471

Maybe you are looking for

  • Jco exception thrown while executing function "BICS_PROV_OPEN" against syst

    Hi,      Am implementing SAP EP, BI Integration. The BI Querys are running fine, but when i try to run a BEx Application Query am thrown with this exception in portal. Exception caught: com.sap.ip.bi.base.exception.BIBaseRuntimeException: Jco excepti

  • Objects move when adding pages

    When I add/remove pages, or just move pages around in my document using the Pages panel, random objects on some pages move. They normally move just a slight amount, and stay with the page, but it is very annoying. I never know which objects will move

  • I need take take pictures with a 60D using may notebook as the monitor. How can I do that?

    I need take take pictures with a 60D using may notebook as the monitor. How can I do that?

  • Changing to a new Active Directory

    We are synchronising Shared Services to Microsoft Active Directory to create our main user directory. We add the AD accounts to native groups, which are provisioned with Essbase and Planning roles. We apply security filters for our Planning cubes dir

  • Old Time Rock and Roll with AE and Element 3D

    Heres some Old Time Rock and Roll with Element 3D. View at 1080P and full frame to really rock out Element is a truly remarkable plugin that takes some playing with to get comfortable with. http://www.youtube.com/watch?v=q_QMcgpB21Y - (Please stop de