Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6543421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:20:41+00:00 2026-05-25T11:20:41+00:00

I’m trying to update a table in Oracle and I’m running into some difficulty.

  • 0

I’m trying to update a table in Oracle and I’m running into some difficulty. I’m porting over my code from MySQL and some of the commands that MySQL allows are not supported in Oracle.

Here is the MySQL code:

 update table1 t1 set c5 = (select ContractID from table2 t2 where t1.assetid = 
 t2.assetid and t1.lastdate >= t2.lastdate and t1.firstdate= t2.firstdate 
 order by lastdate asc limit 1 offset 4);

The subquery returns a list of ContractIDS, sorted by lastdate and I only want a particular one, hence the limit 1 offset X command.

The problem is as follows. Oracle does not support the “limit” or “offset” commands. There are workarounds to the limit problem using rownum and nested queries, but the Oracle 11G parser doesn’t like them in an UPDATE command.

I had a similar problem before where I needed a limit within an update command, but not an offset. It was solved here: MySQL to Oracle Syntax Error (Limit / Offset / Update)

There is a workaround that Florin Ghita found using analytical functions.

 update table1 alf
  set nextcontractid = 
      (SELECT min(contractid) keep (dense_rank first order by lasttradedate asc) 
      FROM table1copy alf2
      WHERE alf2.assetid     = alf.assetid
      AND alf2.lasttradedate > alf.lasttradedate
      )
  where alf.complete = 0

This workaround allows me to get the top or bottom entry (by using asc or desc in the dense_rank command), but I am not able to find a proxy for the offset command, if I wanted the second or third row.

Another solution I’ve tried used a nested query. The first got the first 5 rows using the rownum command, ordered them in the opposite way, the MINUS-ed off the last four rows. This solution failed because the Oracle parser didn’t understand the reference to a table in the outermost command referenced inside one of the nested queries.

(Same problem as I was having before: MySQL to Oracle Syntax Error (Limit / Offset / Update))

The challenge isn’t simply to run a select statement in oracle with a limit and offset, as I can already do that through nested queries. The challenge is to get the select statement to work within an update statement, because even though the statement is syntactically correct, the Oracle parser fails to decode them. So far, nested queries (and Google) have failed me.

Has anyone else been having similar problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:20:42+00:00Added an answer on May 25, 2026 at 11:20 am

    Deleted original answer, not viable

    I feel this should be doable in a single SQL statement, but so far the combination of the need for a correlated subquery and the need for some sort of analytic function has made everything I tried fail.

    Here’s a procedural method that I think will do what you want:

    DECLARE
      CURSOR t IS
      SELECT LEAD(contractid,4) OVER (PARTITION BY assetid ORDER BY lasttradedate ASC) lead_contractid
        FROM table1
        FOR UPDATE;
    BEGIN
      FOR r IN t LOOP
         UPDATE table1 SET nextcontractid = r.lead_contractid
           WHERE CURRENT OF t;
      END LOOP;
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.