SELECT YEAR FROM DATE FROM VARCHAR2

Dear all,
i have a question aboute date and TO_DATE. The thing is i have a VARCHAR2 colum with data like:
12/09/1979
02/05/1978 etc etc etc
Now we like to know how old the person is at the beginning of the year. So we have to take the current year -1 -year of burth.
The first part is not so hard. We can take the current year from DUAL. Now here is the hard part how do we convert the varchar data to a date and extract only the years from it and not the rest of the date?
All bright and smart things are welcome :-)
Thanks already.

Anupama and Christian,
thanks for the input buth i still have a question. I tried the option of Christian and moddified the query a little:
select months_between(trunc(sysdate, 'YEAR'),
to_date(
'27/08/1979',
'DD/MM/YYYY'
) / 12
from vak_werknemer where geboorte like '__/__/____'
This works fine buth. it is only working with 1 date, so i gives me a list +/1 1000 rows with the same conclusion i am correct aboute my age :-)
Now i like to do this with all the other people in the database. SO i have placed a subquery in the query instead of a date.
select months_between(trunc(sysdate, 'YEAR'),
to_date(
(select geboorte from vak_werknemer where geboorte like '__/__/____'),
'DD/MM/YYYY'
) / 12
from vak_werknemer where geboorte like '__/__/____'
This is giving me the error that a single-row subquery returns more than one row. That is correct there are 1000 returnd rows. How do i make the query so that it will give me a list of all the people and not the age of 1?
Thanks already. :-)

Similar Messages

  • ADF 11g can not select and copy data from cell of readonly table in IE

    hi,
    In ADF 11g, when render view object as readonly table with Single RowsSelection, using IE browser can not select and copy data from the cell, but it work in firefox.
    is it a bug?
    Edited by: kent2066 on 2009-5-18 上午8:46

    Hi Timo,
    Sorry forgot to mention versions.
    We are using 11.1.1.7 and IE 9.
    I tried in Google but could not get the solution.
    Kindly let me know solution for this.
    PavanKumar

  • Select DBase (.dbf) data from Oracle on Linux

    How to select DBase (.dbf) data from Oracle on Linux ?
    dbf files connected to Linux form NetWare server as 'ncpmount'.
    Oracle has access as oracle 'Directory' object.

    If you have an ODBC driver for it and are using Oracle 10g you can use Generic Connectivity. For more information on Generic Connectivity refer to the Chap 7 of the Heterogeneous Connectivity Administrator's Guide.
    http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10764/gencon.htm#1005900

  • Select DBASE IV data from Oracle on Linux

    Can I select DBASE IV data from Oracle on Linux

    You can connect to DBase IV from Oracle by configuring Oracle Heterogenous Services. That will let you create a database link from Oracle to a non-Oracle database. Since there isn't a specific DBASE IV gateway, though, I believe you'll have to use the ODBC gateway, which would probably imply the necessity of a Windows box hosting Heterogenous Services.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Pls help : How To select fields and data from user_table for each tablename

    Please help with the query to generate a output which selects the code,meaning,inuse for each table in the user_table that has "CODED" as a part of table name.
    User table has some 800 table that contains CODED in the tablename.
    Desc of the table:
    DESCPTION:
    Name Null? Type
    SHORT_NAME NOT NULL VARCHAR2(20)
    CODE NOT NULL VARCHAR2(4)
    MEANING NOT NULL VARCHAR2(240)
    IN_USE VARCHAR2(1)
    NOTES VARCHAR2(2000
    UNITS NOT NULL VARCHAR2(1)
    AMOUNT NOT NULL VARCHAR2(3)
    CONVERTED VARCHAR2(1)
    RUN_NAME VARCHAR2(30)
    But all the table have code, meaning,in_use fields.
    O/P format :
    TABLE_NAME CODE MEANING IN_USE
    Help me pls.

    Not 100% sure what you want. If you want to see all the tables that have all three of those columns, then you could do something like:
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'CODE' and
          table_name like '%CODED%'
    INTERSECT
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'MEANING' and
          table_name like '%CODED%'
    INTERSECT
    SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
    FROM user_tab_columns
    WHERE column_name = 'INUSE' and
          table_name like '%CODED%'If you want to select those three columns from each of the tables, then you could do something like this.
    Create a command file called, for example, makesel.sql that looks like:
    SET PAGES 0 lines 500 trimspool on feedback off;
    spool sel.sql;
    prompt spool selout.txt;
    SELECT 'SELECT '''||table_name||''', code, meaning, in_use FROM '||
           table_name||';'
    FROM (SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'CODE' and
                table_name like '%CODED%'
          INTERSECT
          SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'MEANING' and
                table_name like '%CODED%'
          INTERSECT
          SELECT table_name
          FROM user_tab_columns
          WHERE column_name = 'INUSE' and
                table_name like '%CODED%')
    prompt 'spool off;'
    spool off;
    @sel.sqlAt the sqlplus prompt run the file using @makesel.sql. This will create another file called sel.sql containing the commands to select those three columns from each table that has all three columns, then after the new file is created, it runs the file (@sel.sql). The output will be spooled to a file called selout.txt.
    HTH
    John

  • NIO Socket implementation - delay between select and get data from socket

    Hi all,
    I have implemented a internal CallAPI for RPC over a socket connection. It works fine but if there are more than five clients and some load I have the phenomena that the READ selector returns a SelectorKey but I did not get any data from the socket.
    My implementation is based on NIO has following components:
    + Accept-Thread
    Thread handles new clients.
    + Read-Thread
    Thread handles the data from the socket for the registered client. Each request is handled in an own Process-Thread. A Thread-Pool implementation is used for processing.
    + Process-Thread
    The Process-Thread reads the data from the socket and starts the processing of the logical request.
    In my tests I get the notification of data at the socket. The Process-Thread want to read the data for the socket, but no data are available. In some situations if have to read about 20 times and more to get the data. Between each read attempt I have inserted a sleep in the Process-Thread if no data was available. This have improved the problem, but it already exists. I tested the problem with several systems and jvm's but it seams that it is independent from the system.
    What can I to do improve the situation?
    I already include the read implementation from the grizzly-Framework. But it doesn't improve the situation.
    Socket - Init
         protected void openSocket( String host, int port ) throws IOException
              serverChannel = ServerSocketChannel.open();
              serverChannel.configureBlocking( false );
              serverSocket = serverChannel.socket();
              serverSocket.setReuseAddress( true );
              this.serverhost = host;
              this.serverport = port;
              this.srvAcceptSelector = Selector.open();
              this.srvReadSelector = Selector.open();
              InetSocketAddress isa = null;
              if ( serverhost != null )
                   isa = new InetSocketAddress( this.serverhost, this.serverport );
              else
                   isa = new InetSocketAddress( this.serverport );
              serverSocket.bind( isa, 50 );
              serverChannel.register( this.srvAcceptSelector, SelectionKey.OP_ACCEPT );
         }New Client � Init
         // New Client
         if ( key.isAcceptable())
              keyCountConnect++;
              ServerSocketChannel actChannel =
                   (ServerSocketChannel) key.channel();
              // Socket akteptieren
              SocketChannel actSocket = actChannel.accept();
              if ( actSocket != null )
                   actSocket.finishConnect();
                   actSocket.configureBlocking( false );
                   actSocket.socket().setTcpNoDelay( true );
                   this.registerSocketList.add( actSocket );
                   this.srvReadSelector.wakeup();
         }Read Data from Socket
        protected int readDatafromSocket( ByteArrayOutputStream socketdata )
             throws IOException
             int readedChars = 0;
            int count = -1;
            Selector readSelector = null;
            SelectionKey tmpKey = null;
            if ( sc.isOpen())
                  ByteBuffer inputbuffer = null;
                 try
                      inputbuffer = bufferpool.getBuffer();
                      while (( count = sc.read( inputbuffer )) > 0 )
                           readedChars += count;
                          inputbuffer.flip();
                           byte[] tmparray=new byte[inputbuffer.remaining()];
                           inputbuffer.get( tmparray );
                           socketdata.write( tmparray );
                          inputbuffer.clear();
                      if ( count < 0 )
                           this.closeSocket();
                           if( readedChars == 0 )
                                readedChars = -1;
                           if ( log.isDebug())
                                  log.debug( "Socket is closed! " );
                      else if ( readedChars == 0 )
                           if ( log.isDebug())
                                  log.debug( "Reread with TmpSelector" );
                           // Glassfish/Grizzly-Implementation
                         readSelector = SelectorFactory.getSelector();
                         if ( readSelector == null )
                              return 0;
                          count = 1;
                          tmpKey = this.sc.register( readSelector, SelectionKey.OP_READ );
                         tmpKey.interestOps(
                              tmpKey.interestOps() | SelectionKey.OP_READ );
                         int code = readSelector.select( 500 );
                         tmpKey.interestOps(
                             tmpKey.interestOps() & ( ~SelectionKey.OP_READ ));
                         if ( code == 0 )
                             return 0;
                             // Return on the main Selector and try again.
                           while (( count = sc.read( inputbuffer )) > 0 )
                                readedChars += count;
                               inputbuffer.flip();
                                byte[] tmparray=new byte[inputbuffer.remaining()];
                                inputbuffer.get( tmparray );
                                socketdata.write( tmparray );
                               inputbuffer.clear();
                           if ( count < 0 )
                                this.closeSocket();
                                if( readedChars == 0 )
                                     readedChars =-1;
                           else if ( count == 0 )
                                  // No data
                 finally
                      if ( inputbuffer != null )
                           bufferpool.releaseBuffer( inputbuffer );
                           inputbuffer = null;
                      // Glassfish-Implementierung
                    if ( tmpKey != null )
                        tmpKey.cancel();
                    if ( readSelector != null)
                        // Bug 6403933
                         try
                            readSelector.selectNow();
                         catch (IOException ex)
                        SelectorFactory.returnSelector( readSelector );
            return readedChars;
        }Thanks for your time.

    I've commented on that blog before. It is rubbish:
    - what does 'overloading the main Selector' actually mean? if anything?
    - 'Although this not clearly stated inside the NIO API documentation': The API documentation doesn't say anything about which Selector you should register channels with. Why would it? Register it with any Selector you like ...
    - 'the cost of maintaining multiple Selectors can reduce scalability instead of improving it' Exactly. So what is the point again?
    - 'wrapping a ByteBuffer inside a ByteBufferInputStream:' Code is rubbish and redundant. java.nio.channels.Channels has methods for this.
    There is no a priori advantage to using multiple Selectors and threads unless you have multiple CPUs. And even then not much, as non-blocking reads and writes don't consume significant amounts of CPU. It's the processing of the data once you've got it that takes the CPU, and that should be done in a separate thread.
    So I would re-evaluate your strategy. I suspect you're getting the channel registered with more than one Selector at a time. Implement it the simple way first then see if you really have a problem with 'overloading the main Selector' ...

  • To add a method on select of a date from a date input field

    Hi,
    I have a input field which is binded to context element, type date. Hence the output screen has a date popup, from which user can select any dates.
    Is it any way i can have a action executed on select of a date value?
    I mean when the user selects a date from the date field an wction should be called.
    As I have chosen it to be input field so at present I have only the option of OnEnter, which is not fulfilling the requirement.
    Regards,
    Pranay

    Hi Pranay,
    Use the Date Navigator instead. It has got the same functionality as Date Picker (this is what you are using) & moreover, you can achieve what you desired. It has got the functions like onDaySelect, onWeekSelect & onMonthSelect & onSelect.
    That will trigger the action what you want.
    Regards
    Chander Kararia
    # Please close the thread once get the correct answer. Give rewards for answers.

  • Selective Transfer of Data from MacBook to MacBook Pro (both Intel)

    Just got a new MacBook Pro. Needless to say, I'm feeling very lucky and excited.
    I already activated it and have been using it. Nice!
    Can anyone provide suggestions on how to selectively transfer data from my old MacBook to the new MacBook Pro. Information on each computer is provided below.
    Data From (old computer)
    Model Name: MacBook
    Model Identifier: MacBook4,1
    Processor Name: Intel Core 2 Duo
    Processor Speed: 2.4 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 3 MB
    Memory: 4 GB
    Bus Speed: 800 MHz
    Boot ROM Version: MB41.00C1.B00
    SMC Version (system): 1.31f0
    Serial Number (system): WQ827FDE0P1
    Hardware UUID: 414D4BBF-EB7E-5A86-9AA3-B2C9BE31C9AA
    Data To (New Computer):
      Model Name:    MacBook Pro
      Model Identifier:    MacBookPro6,1
      Processor Name:    Intel Core i7
      Processor Speed:    2.66 GHz
      Number Of Processors:    1
      Total Number Of Cores:    2
      L2 Cache (per core):    256 KB
      L3 Cache:    4 MB
      Memory:    8 GB
      Processor Interconnect Speed:    4.8 GT/s
      Boot ROM Version:    MBP61.0057.B09
      SMC Version (system):    1.57f17
      Serial Number (system):    C02CQ0Z0DD6Y
      Hardware UUID:    ABC70E84-F9B2-5EB3-8109-80A2229DE8D2

    Turn off both computers. Connect a Firewire cable between the two computers. Boot the old computer into Target Disk Mode. Boot the new computer normally. Upon startup you should find a disk icon for the old computer's hard drive on the Desktop of the new computer. You can access it like you would any normal disk drive.
    You can use Migration Assistant if you wish to transfer the entire Home folder, third-party applications and support files, and preferences from the old computer. MA cannot be used to make selective file/folder transfers.
    If you have a Time Machine backup of the old computer you can do selective restores from the TM backup using the TM application.

  • How to pass the selected table row data from popup to source view

    Hi ,
    I have requirement of passing the data from popup view to source. , searching some data in  popup view and displaying in table,
    Like i am passing some input and click search button will display the data in table, when select any of the row in the table and click on the another button , i should be able to pass the select row to the source view and also should close the popup.
    When i implement , In the popup windiw, when i enter the customer no, and click on search button, it is closing the popup itslef. not able to see the data in popup.
    Can u tell me what is that soultion.
    Regards
    Vijay

    Hi Harsimran
    Thanks for the reply,
    1) Source view
    In  "Source View" i have input field called Customer_no. But,  the end user will not have any idea , what customer no to enter. so i am searching the customer no in the popup view.
    1) Customer_no( This is an inputfiled , to get the customer no from the popup view)
    2) Get Customer NO( This is a button to call the popup view)
    "Get Customer NO" This button action will open the popup view.
    In this popup, i have
    1) Input field (To enter the search term)
    2) Search (To seach the customer no based on the search term)
    3) Table ( To display the search data)
    4) Button in Table tool bar called "Select" .( To close the popup view after selected the required data in the table to pass it back to the source view).
    so in the popup view what happening is, when i click on the search button itself , it is closing the popupview  by transfering the first row of the tbale ,with out select the required row in the table.
    i need to close the window after click on the "Select" button in the toolbar , after selected the required row data to trasfer in the table.
    Can u pelase tell me what are the modifcations i need to do it.
    Regards
    Vijay

  • Error occured in the data selection while extract data from Source system

    Hello Friends
    i am facing Problem while extracting data to Biw System from SAP R/3 system
    The error mesage is 'Error occured in the data selection '
    i.e. Monitoring - Details tab - Extraction - With error

    Hi
    The delta wil take the Last init selection for loading data in to the BW...
    Did u check the IP at the Update tab is it the correct delta only.. or its a full..
    better to go to the RSA3 and check the extractor in the Delta mode .. if u give ur delta mode it automatically takes the selction options.. so please try in RSA3..
    regards
    CK
    PS: CHECK THE INIT SELECTIONS TOO  or do an init with outdatatransfer and perform the delta...
    Message was edited by:
            BW Star

  • Spread Data Over Multiple Months & Years with Data from Multiple Years

    Hello Everyone,
    I have a complex calculation for spreading values over several months spanning mulitle years. Because we have a 36 month rolling Forecast, a more sophisticated calc is required as opposed to hard coding months or years.
    Heres the description:
    Users enter the following data,
    FY11     BegBalance     Number of BOD Members     10
              BOD Options Vesting Months     20
              BOD Options Accounting Value     10
              BOD Options- Number of Shares     100
              BOD Grant Month     Aug
    FY12     BegBalance     Number of BOD Members     5
              BOD Options Vesting Months     10
              BOD Options Accounting Value     5
              BOD Options- Number of Shares     200
              BOD Grant Month     Oct
    FY13     BegBalance     Number of BOD Members     20
              BOD Options Vesting Months     8
              BOD Options Accounting Value     20
              BOD Options- Number of Shares     100
              BOD Grant Month     Feb
    Based on the above;
    "BOD Stock" is calculated as following/month=Number of BOD Members*BOD Options Accounting Value*BOD Options- Number of Shares/ BOD Options Vesting Months
    Start month for the above is based on "BOD Grant Month". So, for instance considering data for FY11:
    The total "BOD Stock" value is $10000 (originating from FY11) with start month of AUG in FY11 and the number of months to spread over is 20 months. So, essentially the "BOD Stock" per month (originating from FY11) is $500 starting from AUG FY11 to Mar FY13.
    Similarly, the total "BOD Stock" value is $5000 (originating from FY12) with start month of OCT in FY12 and the number of months to spread over is 10 months. So, essentially the "BOD Stock" per month (originating from FY12) is $500 starting from OCT FY12 to JUL FY13.
    The challange I am facing is because of the number of months to spread. Because I have data to spread from multiple years and each year's data spills into the following years, each year should accumulate data from prior years. For instance;
    FY11 should include only FY11
    FY12 should include FY11 and FY12
    FY13 should include FY11, FY12 and FY13.
    Could anyone suggest a smarter way to do this without writting code for each year, maybe using @MDALLOCATE function? The following shows how data should be spread and accumulated.
                             BegBalance     Jan     Feb     Mar     Apr     May     Jun     Jul     Aug     Sep     Oct     Nov     Dec     Period
    FY11     Number of BOD Members          10     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Vesting Months          20     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Accounting Value     10     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options- Number of Shares     100     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Grant Month               Aug     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
              BOD Stock               10000     #mi     #mi     #mi     #mi     #mi     #mi     #mi     500     500     500     500     500     #mi
    FY12     Number of BOD Members          5     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Vesting Months          10     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Accounting Value     5     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options- Number of Shares     200     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Grant Month               Oct     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
              BOD Stock               5000     500     500     500     500     500     500     500     500     500     1000     1000     1000     #mi
    FY13     Number of BOD Members          20     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Vesting Months          8     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Accounting Value     20     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options- Number of Shares     100     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Grant Month               Feb     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
              BOD Stock               40000     1000     6000     6000     5500     5500     5500     5500     5000     5000     #mi     #mi     #mi     #mi
    Appreciate your inputs!
    Edited by: user10678366 on Oct 12, 2010 3:21 PM

    Why not use substitution variables for Years? you could have something like &Year1, &Year2, &Year3
    Cheers

  • Selective deletion of data from ODS

    Hai,
             I need to delete selectively data from an ODS. I know that I have the option of selective deltionin cube. But how can I delete them in ODS?
    Thank you.

    Hi Vasu,
    In ODS > right click > Manage on the Contents tab you also have the option of Selective Delete...were you looking for something else?

  • Partitioning two Years Of Data From One Cube Yo Another

    Hi Experts,
    Can any one please help me on the following issue.
    I got the requirement where I need to copy the data from one cube to another having unequal number of dimensions.
    I have achieved this using Transparent partitioning, But I could be able to copy only one year data.
    In cube1 I have the months like Jan, Feb...Dec and in cube2 I have the structure like Jan-11..Dec-11, Jan-12...Dec-12.
    While creating the partition how can I map the Jan with Jan-11 and Jan-12.
    Thanks In Advance,
    Ram

    You can map manually. it is possible.

  • How to get year,month,date from a Date object?

    thanks

    The getTime() method will return the number of milliseconds since January 1, 1970, 00:00:00 GMT. You can then write a number of functions to calculate the date from this.
    The toString() function returns a string with the current value of the object - i.e 2002-10-17 (it's unusual formatting (YYYY-MM-DD) is useful when validating an input in real time, though beyond this, I've no idea why they put it this way around). You can then use string function substirng() to break this down into parts.
    i.e. if your Date object was called today:
    String DD = today.toString().substring()(8)
    String MM = today.toString().substring()(5,2)
    String YYYY = today.toString().substring()(0,4)
    There are other methods (see API) - but these have been deprecated - that means, although they can be used, they are not recomended.
    There is also a Calendar object, though this seems to have the same problems.
    Hope this helps :)

  • Help with selecting chuncks of data from a table

    Hi all,
    I need help with a query that should do the following.
    I have a table with vessel messages, and I need to get the last "NumMsgs" messages from a group of vessels.
    The problem I have is that if I order the table by Vessel_ID, MessageDate DESC, I can´t do ROWNUM < NumMsgs (<-- Then number of messages to be shown is a user parameter)
    I know it should be something like:
    select * from (
    select *
    from Messages m
    where TRIM(m.V_ID) = '11597' /* I was trying for a single vessel atm */
    order by m.V_ID, m.MESSAGEDATE desc
    where rownum < :NumMsgs
    Any ideas?
    Thanks in advance !

    Hi,
    What about :
    select *
    from (
    select m.*, row_number() (order by m.V_ID, m.MESSAGEDATE desc) rn
    from Messages m
    where TRIM(m.V_ID) = '11597' /* I was trying for a single vessel atm */
    where rn < :NumMsgsAnyway, I don't very well understand your problem, your query work fine, see for example :
    SQL> ed
    Wrote file afiedt.buf
      1  select object_name, object_id
      2  from
      3  (select object_name, object_id, row_number() over (order by object_id desc) as rn
      4   from dba_objects)
      5* where rn < 4
    SQL> /
    PS_TL_MTCHD_118     71763
    PS_TL_MTCHD_117     71762
    PS_TL_MTCHD_116     71761
    SQL> ed
    Wrote file afiedt.buf
      1  select object_name, object_id
      2  from
      3  (select object_name, object_id
      4   from dba_objects
      5   order by object_id desc)
      6* where rownum < 4
    SQL> /
    PS_TL_MTCHD_118     71763
    PS_TL_MTCHD_117     71762
    PS_TL_MTCHD_116     71761
    SQL> Nicolas.
    Message was edited by:
    N. Gasparotto

  • Passing from data from one page to another

    Hi All, i'm currently doing a CSV file upload into a database
    application, and I'm wondering if it is possible to pass the data
    from the file field to another php file which executes the command
    of inserting the data of the csv file into the database? Thanks!!
    Wanqi

    You have this in test.php -
    $target_path = $_GET['uploadfile'];
    That implies that the page calling test.php is passing
    'uploadfile' as a URL
    variable. But it isn't.
    <form id="form1" name="form1"
    enctype="multipart/form-data" method="post"
    action="test.php">
    Why wouldn't $target_path be the same as $uploadfile?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "taywanqi" <[email protected]> wrote in
    message
    news:[email protected]...
    > Attached below is the code i used for my application:
    >
    > form.php
    >
    >
    >
    >
    >
    >
    >
    > <?php
    > session_start();
    > ?>
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN"
    > "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <html xmlns="
    http://www.w3.org/1999/xhtml">
    > <head>
    > <meta http-equiv="Content-Type" content="text/html;
    charset=utf-8" />
    > <title>Untitled Document</title>
    > <style type="text/css">
    > <!--
    > .style13 { color: #FFFFFF;
    > font-family: Georgia, "Times New Roman", Times, serif;
    > font-size: 14px;
    > }
    > -->
    > </style>
    > </head>
    >
    > <body>
    > <form id="form1" name="form1"
    enctype="multipart/form-data" method="post"
    > action="test.php">
    > <p align="center">
    > <input type="file" name="fileupload" id="fileupload"
    />
    > <input type="hidden" name="csvfile" id="csvfile"/>
    >
    > </p>
    > <p align="center">
    > <input type="submit" name="upload" id="upload"
    value="Submit" />
    > </p>
    > </form>
    > </body>
    > </html>
    >
    >
    > Test.php
    >
    > <?php
    > session_start();
    > echo $name;
    > ob_start();
    > ?>
    >
    > <?php require_once('connection.php'); ?>
    >
    > <?php
    >
    > //UPLOADING FILE
    > if(isset($_POST['upload']))
    > {
    >
    > $uploaddir = 'uploads';
    >
    > $uploadfile = $uploaddir .
    basename($_FILES['fileupload']['name']);
    >
    > $target_path = $_GET['uploadfile'];
    >
    > echo $target_path;
    >
    > //$target_path = ini_get('$uploadfile');
    >
    > echo $file;
    >
    > echo '<pre>';
    > if
    (move_uploaded_file($_FILES['fileupload']['tmp_name'],
    $uploadfile)) {
    >
    > echo "File is valid, and was successfully uploaded.\n";
    >
    > } else {
    > echo "Possible file upload attack!\n";
    > }
    >
    > echo 'Here is some more debugging info:';
    > print_r($_FILES);
    >
    > print "</pre>";
    > }
    >
    >
    > $fcontents = $_SESSION[csvfile];
    >
    > for($i=0; $i<sizeof($fcontents); $i++) {
    >
    > $line = trim($fcontents[$i]);
    > $arr = explode("\t", $line);
    >
    > echo $arr."<br>\n";
    >
    >
    > }
    >
    > //ATTRIBUTES
    > //$fieldseparator = ',';
    > //$lineseparator = '\n';
    >
    > //READING OF FILE
    > $csvfile = $uploaddir .
    basename($_FILES['fileupload']['name']);
    >
    > //TRUNCATE THE FILE BEFORE INSERTING IT INTO THE
    DATABASE
    > mysql_select_db($database, $test);
    > mysql_query("TRUNCATE TABLE timetable") or die("MySQL
    Error: " .
    > mysql_error()); //Delete the existing rows
    >
    > //IMPORT CSV INTO DATABASE
    > $lines = 0;
    > $queries = "";
    > $linearray = array();
    > $fcontents = file($csvfile);
    >
    > for($i=0; $i<sizeof($fcontents); $i++) {
    >
    > $lines++;
    >
    > $line = trim($fcontents[$i]);
    >
    > $linearray = explode(',',$line);
    >
    > $linemysql = implode("','",$linearray); // convert the
    array to a string
    >
    > echo "$linemysql". "\n";
    >
    > //$query = "INSERT INTO timetable
    values('$linemysql')";//Insert query to
    > insert values into the database
    > $query = 'LOAD DATA INFILE "$target_path" REPLACE
    > INTO TABLE timetable
    > FIELDS TERMINATED BY ","
    > OPTIONALLY ENCLOSED BY """"
    > LINES TERMINATED BY "\r\n"';
    >
    > mysql_query($query, $test) or die('SQL
    ERROR:'.mysql_error()); //Insert
    > in
    > the new values into the database
    >
    > }
    >
    > ?>
    >
    > </head>
    > <body>
    > </body>
    > </html>
    > <?php ob_flush(); ?>
    >

Maybe you are looking for

  • Need suggestion for creating 'whispy smoke'

    Hi All, I'm trying to figure out a way to create a cartoonish looking whispy smoke. I've played with Trapcode Particular and that creates some very realistic looking smoke, probably too realistic.  I've played with CC Particle World, and also tried p

  • My iPod touch gen 3 won't update to iOS 5!?!?!?!?!

    My iPod touch shows that the current software is 4.2.1, and that that is the current one... But it isn't. Because iOS 5 is supposed to be compatible...!?

  • Are there any third party apps for Mavericks outside the Apple store?

    I am looking for a way to highlight / color code the full file or folder name. Mavericks changed my color codes to small dots, worthless.  Are there still such things as "helper" apps or "plug-ins" that change the way finder behaves, or has Apple loc

  • S_DEVELOP  Missing debug authorization

    Hi, i just found that in our prod env. for bw for all developers we have S_DEVELOP authorization with all activities (*). i just need to provide them debug access in prd without having access to change the values while debugging. i see all the activi

  • Why have three installation methods for ACR ?(and that's just on Windows)

    I am sitting here patiently waiting for my Olympus PEN E-P1 ORF files to be supported. ACR 5.5 RC has just popped up but to my frustration is only compatible with Photoshop & Bridge. So I continue sitting patiently in front of Lightroom 2 and Element