?
Solved

Coldfusion Last Inserted value in database

Posted on 2014-11-04
3
Medium Priority
?
351 Views
Last Modified: 2014-11-05
Is there any function in coldfusion, i want last inserted value from database.
if there is no function so what is the right way to do it.

database could be oracle or MSSQL

Thank you.....
0
Comment
Question by:xeondxb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40423230
I don't believe Coldfusion is much more than an interface to a database.  It only remembers/tracks what you tell it to.

Unless you return the value from the database, I don;t think it has any 'smarts' built in.

An example:
Oracle has a 'returning' clause hat allows you to return specific values from DML.  If the app coded the DML to take advantage of the returning clause and handled the return values properly, then yes.

If not, I'm afraid you might be out of luck.

Then again, I'm not a Coldfusion expert...
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 40423292
EDIT:

I don't use Oracle, but for SQL Server table's that have an IDENTITY column, you can use cfquery's "result" attribute to return the new record ID from an INSERT.

       <cfquery name="addRecord" result="yourResult" ...>
              INSERT INTO SomeTable (..Columns..) VALUES ( ... values ...)
       </cfquery>

        The new identity value is <cfoutput>#yourResult.IDENTITYCOL#</cfoutput>

The exact syntax is db dependent. For Oracle, try the ROWID value. For more details see the cfquery docs.
0
 

Author Closing Comment

by:xeondxb
ID: 40424824
Thanks
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question