GET LAST INSERTED RECORD

I am fairly new to flex. So please bear with me no this
question.
I would like to get MYSQL ID of the last record I inserted.
MSQL has as function LAST_INSERT_ID() that is connection based and
will return the last id of the last inserted record. My thought was
in the function contained within the cfc to do 2 queries insert the
record and return the last id directly after (see below). However,
I don't know how I would read the results back into flex. I am
unsure how to write the event handler. Thanks
<cffunction name="insertUser" access="remote"
returntype="query" >
<cfargument name="SSN" required="false" type="string"
hint="SSN"/>
<cfargument name="FNAME" required="false" type="string"
hint="FNAME"/>
<cfargument name="LNAME" required="false" type="string"
hint="LNAME"/>
<cfargument name="CLIENTID" required="false"
type="string" hint="NEW CLIENTID"/>
<cfquery name="insUser" datasource="DBT">
INSERT INTO CLIENT (SSN, FNAME, LNAME) VALUES (
<cfqueryparam value="#ARGUMENTS.SSN#"
cfsqltype="CF_SQL_VARCHAR" maxlength="12"/>,
<cfqueryparam value="#ARGUMENTS.FNAME#"
cfsqltype="CF_SQL_VARCHAR" maxlength="20"/>,
<cfqueryparam value="#ARGUMENTS.LNAME#"
cfsqltype="CF_SQL_VARCHAR" maxlength="30"/>)
</cfquery>
<cfquery name="qRead" datasource="DBT">
SELECT last_insert_id() AS CLIENTID
</cfquery>
<cfreturn qRead >
</cffunction>

I assume you have LCDS installed with CF and you are using
the remote object service,
<mx:RemoteObject
id="myService"
destination="ColdFusion"
source="full.path.to.cfc"
showBusyCursor="true">
<mx:method name="insertUser"
result="insertUser_result(event)" />
</mx:RemoteObject>
<mx:Scrpit>
private function insertUser_result(event:ResultEvent) {
trace(event.result);
event.result will be the id of the newly inserted record.
BTW, I would highly recommend you looking into the data
management servcie. the SQLAssembler can spare you of the CF code
for simple CRUDs like this.

Similar Messages

  • Fatch last inserted record in ztable

    hi all,
    any buddy can tell me how can i get last inserted record from my ztable.

    Hi,
    I think this wont work .....
    Ex: table has   (considering first two cols as PK's)
    000123   AA   124
    000123   AB   124
    000123   AC   124
    000123   BA   124
    000123   BB   124
    000123   BC   124
    000123   LH   124
    Now i am inserting         000123   BD   124
    => Records will be arranged as
    000123   AA   124
    000123   AB   124
    000123   AC   124
    000123   BA   124
    000123   BB   124
    000123   BC   124
    000123   BD   124
    000123   LH   124
    How will yur query works ? Please clarify ....

  • SQL query to get last 10 records in the table?

    Hi,
    Can anyone tell me the SQL query to get last 10 records in the table?
    Thanks!!
    MCP

    Please, define what "last" means. Sets are unordered by definition, so if you want to retrieve rows from a table in a specific order you need to specify what that order is - e.g. by maintaining a value in a column (or a combination of columns) that you can use in the ORDER BY clause of the SELECT statement.
    If, for instance, you kept the time when the row was inserted in a special column (InsertedTime), you could use this in your query like this:
    select top (10)
      <column list>
      from <table or view>
      where <restriction(s)>
      order by InsertedTime desc;
    ML
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

  • Retrive a record before the last inserted record

    Hi,
    I use simple select statement to retrive records where cola = 'Yes':
    select * from tbl1
    where cola = 'Yes';
    The result gives me about 10 records with different date.
    From the above result, I want to get the record right before the last inserted record according to the date field; which means I can not use MAX function (all I want just one record).
    If I write a function to return a date and passes it back to the SELECT statement, I'll get a date for each record, which I don't want.
    I know there's a way to do that in PL/SQL.
    Plese help me.
    pem

    select * from (
    select * from
    (select * from (select * from (table> order by <date> desc) where rownum < 3)
    order by <date>) where rownum =1

  • Retrive last inserted  record  from database table

    Hi,
    some body inserting a record into table 'A' through some procedure/java program.i want to retrive the last inserted record from database table.records are not stored in order.Can any body help me.

    In general, unless you are storing a timestamp as part of the row or you have some sort of auditing in place, Oracle has no idea what the "first" or "last" record in a table is. Nor does it track when a row was inserted.
    - If you have the archived logs from the point in time when the row was inserted, you could use LogMiner to find the timestamp
    - If the insert happened recently (i.e. within hours), you may be able to use flashback query to get the value
    - If you're on 10g or later and the table was built with ROWDEPENDENCIES and the insert happened in the last few days and you can deal with a granularity of a few seconds and you don't need 100% accuracy, you could get the ORA_ROWSCN of the row and convert that to a timestamp.
    If this is something you contemplate needing, you need to store the data in the row or set up some sort of auditing.
    Justin

  • How to find last inserted record in the table.

    Version: Oracle 10g
    I have a table called "Manufacture" and 3 columns as mfno,itemname,quantity.
    How to find last inserted record in the table "Manufacture".
    As i come to know that Rowid is not result perfect results. Please provide your inputs.

    user13416294 wrote:
    Version: Oracle 10gThat is not a version. That is a product name. A version is 10.1.0.2 or 10.2.0.4, etc.
    I have a table called "Manufacture" and 3 columns as mfno,itemname,quantity.
    How to find last inserted record in the table "Manufacture".Not possible as your data model does not cater for it. That simple.
    If there is a need to determine some order or associate some time to an entity, then that should be part of the data model - and a relationship, or one or more attributes are needed to represent that information. Thus your data model in this case is unable to meet your requirements.
    If the requirements are valid, fix the data model. In other words - your question has nothing to do with Oracle and nothing to do with rowid, rowscn or other pseudo columns in Oracle. It is a pure data modeling issue. Nothing more.

  • Last inserted record

    HI,
    we have created a table with a field ID.
    we have inserted 1000 records in that table,.
    I want to retrieve only the last inserted record.
    How it's possible?
    is it possible with rowid?
    e.g:
    CREATE TABLE TEST(id number(2));
    insert into TEST values(1);
    insert into TEST values(2);
    insert into TEST values(3);
    insert into TEST values(4);
    insert into TEST values(5);
    In this case i want to retrieve only 5.
    How we can achieve this?

    There is no concept of order in a heap table. Blocks can be reused so the ROWID cannot ever be used to determine when a row was inserted. The only way to determine the last row that was inserted into a table is to use a timestamp and/or a sequence column. If you need to determine the last inserted row and you don't already have a timestamp or sequence column, you need to add one.
    HTH
    David

  • How to get the last inserted record from a table ?

    :-) Hiee E'body
    I work on Oracle 8i and need to get the last
    record inserted in a table.
    I have tried using rownum and rowid pseudo-columns
    but that doesn't work.
    Can you please help me out ?
    :-) Have a nice time
    Vivek Kapoor.
    IT, Atul Ltd.,
    India.

    I'm not sure about 8i features.
    I assume here that you don't have 'Date-Time' stamp columns on the table which is the easiest way to determine the last inserted row in the table.
    If not try the following :-
    select address, piece, SQL_TEXT
    from V$SQLTEXT
    where upper(sql_text) like '%INSERT INTO TABLE_NAME%'
    Substiute the TABLE_NAME with the name of the actual table.
    Have fun.
    Regards,
    Shailender
    :-) Hiee E'body
    I work on Oracle 8i and need to get the last
    record inserted in a table.
    I have tried using rownum and rowid pseudo-columns
    but that doesn't work.
    Can you please help me out ?
    :-) Have a nice time
    Vivek Kapoor.
    IT, Atul Ltd.,
    India.

  • Getting Last Payroll Record

    Hi all,
    I need to fetch last payroll record of a pernr,from transaction pc_payresult.
    I am using the LDB PNP.
    After calling GET PERNR, I am using functions CU_READ_RGDIR and then PYXX_READ_PAYROLL_RESULT to fetch the last active payroll record.
    But is there any way to <b>directly</b> fetch the last active payroll record,based on the pernr? Please suggest a way.
    Thanks&Regards
    Ananya

    Hi
    To get the payroll results, you need to read the cluster CU to get RGDIR. For this CU_READ_RGDIR is used and almost all standard programs also use this FM.
    Simple Report using LDBs to get latest payroll result.
    report ythr_read_payroll .
    data: t_rgdir type pc261 occurs 0,
          t_result type payus_result,
          w_bt type line of hrpay99_bt,
          out_seqnr like pc261-seqnr.
    tables: pernr.
    get pernr.
      call function 'CU_READ_RGDIR_NEW'
           exporting
                persnr                = pernr-pernr
           tables
                in_rgdir              = t_rgdir
           exceptions
                no_record_found       = 1
                import_mismatch_error = 2
                no_read_authority     = 3
                others                = 4.
      if sy-subrc <> 0.
        write:/1 'No payroll results for ', pernr-pernr.
      endif.
    call function 'CD_READ_LAST'
           exporting
                begin_date      = pn-begda
                end_date        = pn-endda
           importing
                out_seqnr       = out_seqnr
           tables
                rgdir           = t_rgdir
           exceptions
                no_record_found = 1
                others          = 2.
      if sy-subrc <> 0.
        write:/1 'Error for ', pernr-pernr.
      endif.
      call function 'PYXX_READ_PAYROLL_RESULT'
           exporting
                clusterid                    = 'RU'
                employeenumber               = pernr-pernr
                sequencenumber               = out_seqnr
           changing
                payroll_result               = t_result
    exceptions
                illegal_isocode_or_clusterid = 1
                error_generating_import      = 2
                import_mismatch_error        = 3
                subpool_dir_full             = 4
                no_read_authority            = 5
                no_record_found              = 6
                versions_do_not_match        = 7
                error_reading_archive        = 8
                error_reading_relid          = 9
                others                       = 10.
      if sy-subrc <> 0.
        write:/1 'Error for ', pernr-pernr.
      endif.
      loop at t_result-inter-bt into w_bt.
        write:/1 pernr-pernr, out_seqnr, w_bt-bankl, w_bt-bankn.
      endloop.
    Regards
    Navneet

  • Oracle - Last inserted record

    hello
    I need select last added/inserted records where value = 'test1' and = 'test2' and = 'test3' in column 'NAME'
    should be one record for each 'test1','test2' ...
    aslo..table have column 'DATE_USR' with data_type = timestamp(6)
    thanks for help
    Edited by: user8855885 on 2012-08-07 02:00
    Edited by: user8855885 on 2012-08-07 02:01
    Edited by: user8855885 on 2012-08-07 02:01

    /* Formatted on 8/7/2012 4:56:36 PM (QP5 v5.139.911.3011) */
    WITH t AS (SELECT 99 id,
                      'test1' name,
                      '12/08/03 11:38:43' dt,
                      'ok' DES
                 FROM DUAL
               UNION ALL
               SELECT 24,
                      'test2',
                      '12/07/01 11:38:43',
                      'nok'
                 FROM DUAL
               UNION ALL
               SELECT 97,
                      'test2',
                      '11/07/01 11:38:43',
                      'ok'
                 FROM DUAL
               UNION ALL
               SELECT 55,
                      'test2',
                      '11/07/01 11:38:43',
                      'nok'
                 FROM DUAL
               UNION ALL
               SELECT 43,
                      'test3',
                      '12/07/01 11:38:43',
                      'ok'
                 FROM DUAL
               UNION ALL
               SELECT 88,
                      'test3',
                      '10/07/01 11:38:43',
                      'nok'
                 FROM DUAL
               UNION ALL
               SELECT 34,
                      'test4',
                      '12/07/01 11:38:43',
                      'nok'
                 FROM DUAL
               UNION ALL
               SELECT 44,
                      'test4',
                      '09/07/01 11:38:43',
                      'nok'
                 FROM DUAL)
    SELECT *
      FROM (SELECT t.*,
                   RANK ()
                   OVER (PARTITION BY name
                         ORDER BY TO_DATE (dt, 'dd/mm/yy hh:mi:ss') DESC)
                      rk
              FROM t) x
    WHERE 1 = rkoutput:
    99     test1     12/08/03 11:38:43     ok     1
    24     test2     12/07/01 11:38:43     nok     1
    43     test3     12/07/01 11:38:43     ok     1
    34     test4     12/07/01 11:38:43     nok     1

  • Get last add record using UI

    Hi is there anyway to get the last added record from UI-API?
    I want to return the last added doc num from the delivery screen after the user press the add button.
    The method i am using now to get the doc num is to return the docnum after the itempressed event = true. After that i will minus 1 to that result. Is this the only way to get the last added number or is there another method to use?
    Thanks

    Thanks Ibai
    I tried making an UDF in the Document/Title part, and created a new field called GUID. When i tried entering the GUID into that field using UI-API, it does not enters. My code are something like this
    sGuid = guid.newguid.tostring
    oitem = odevnote.items.item("U_GUID")
    oedittext = oitem.specific
    oedittext.value = sguid
    pls help
    ps. one more thing, if the UDF screen is not opened, the GUID value would not be entered right? is there a way to force the user to open the UDF screen? or is there any other solution for this?
    Message was edited by: Melvin Teng

  • How to get last inserted id from database

    Hello,
    In PHP Language, mysql_insert_id() gives the last inserted ID without writing any Queries in the code. Is there similar mechanism to do in Jsp page. I need to insert data in one table and in the meantime, with the last inserted ID i need to insert another sort of data in another table.
    Can u plz help me out?

    You can use Statement#getGeneratedKeys().
    The DDL should look like at least (you can use INT UNSIGNED instead, your choice):ID BIGINT AUTO_INCREMENT PRIMARY KEYBasic example:int affectedRows = statement.executeUpdate("INSERT INTO table (column1, column2) VALUES ('value1', 'value2')");
    Long insertID = null;
    if (affectedRows == 1) {
        ResultSet generatedKeys = statement.getGeneratedKeys();
        if (generatedKeys.next()) {
            insertID = new Long(generatedKeys.getLong(1));
    }Using MySQL Connector/J 5.0.

  • How to get last year records in P&L

    Hii gurus,
    I am creating Profit & Loss report.
    I need to show last year records.
    Please explain.....
    Thanks in advance......
    Moderator message: please do more research before asking, show what you have done yourself when asking.
    Edited by: Thomas Zloch on Sep 27, 2011 2:11 PM

    Hi,
    Better still if you want this to be easily changeable, i.e. not without a repository migration, put the search spec on the Applet in the Application - Personalization screen. In this way you can change the Search Spec in case of Business Requirement change without needing to go through a development cycle. Do not forget to do a Reload Personalization Rules after changing Search Spec to bring this in effect.
    If you have a standard requirement then do it preferably on the Applet so that you can use the BusComp at other locations also without having to deal with the search spec coming in uninvited.
    Thanks and Regards,
    Tanmay Jain.

  • To get last 10 records

    hi
    suppose there are 50 records in a table
    but i want last 10 records .how can we retrive them?
    thanks in advance.......

    It works fine. The only odd thing is the timestamp appears later and the message (alert) appears first. But this is much better.
    Like this -
    Current log# 2 seq# 7479 mem# 0: D:\TESTDB\ORADATA\DATAFILES\TESTDB\REDO02.LOG
    Thread 1 advanced to log sequence 7479
    Thu May 01 12:30:40 2008
    ORA-00600: internal error code, arguments: [qkatab_10], [16], [79557], [], [], [], [], []
    Errors in file d:\admin\testdb\udump\testdb_ora_2092.trc:
    Thu May 01 11:35:21 2008
    ORA-00600: internal error code, arguments: [qknltAllocate_10], [79557], [], [], [], [], [], []
    Errors in file d:\admin\testdb\udump\testdb_ora_2092.trc:
    Thu May 01 11:34:45 2008
    WARNING: inbound connection timed out (ORA-3136)
    Thu May 01 11:26:38 2008
    Thank you all,
    Sanju.

  • CREATING A TRIGGER THAT PICKS UP THE LAST INSERTED RECORD

    Hello everybody
    my question. is it possible to embed a sql query whitin a trigger? the thing is that when I have to insert the value, this actually would have to be retrieved from another table. It is an AFTER INSERT, but it needs to know which name I inserted in table 1 in order to also insert it into table 2.
    More specifically. Imagine a table with usernames and passwords that I populate as I set them up
    Then I need a trigger that as it sees that I have entered that username it takes it and populates another table with that plus a generated sequence that could be the result of some string function
    CREATE OR REPLACE
    TRIGGER GENERATE_SEQUENCE
    AFTER INSERT ON USERS_TABLE
    FOR EACH ROW
    BEGIN
    insert into GENERATED_SEQUENCES_TABLE (lastinserted_name,surrogate_key)
    values(SELECT USERNAME FROM USERS_TABLE WHERE USERID....., SUBSTR (lastinsertedname¦¦ password), 1,12);
    END;
    so, this lastinserted name is what I am trying to retrieve. I mean if it is not madness to insert a sql query in the way I have done it, I could write in the query to select the highest ID from the PK and that would give me the last inserted name.
    thanks a lot
    Alvaro

    In an insert trigger you can reference all the inserting values with :new.column_name, hence there's no need to select from the USERS_TABLE table:
    CREATE OR REPLACE
    TRIGGER GENERATE_SEQUENCE
    AFTER INSERT ON USERS_TABLE
    FOR EACH ROW
    BEGIN
    insert into GENERATED_SEQUENCES_TABLE (lastinserted_name,surrogate_key)
    values(:new.USERNAME, ...);
    END;
    /Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/02/05/gestione-degli-errori-in-sql-con-log-errors/]

Maybe you are looking for