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

  • Home
  • SEARCH
  • 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 8890663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:33:13+00:00 2026-06-14T22:33:13+00:00

I’m trying to update a table with the multiple returns of a function. I

  • 0

I’m trying to update a table with the multiple returns of a function.

I have created a TYPE

CREATE OR REPLACE TYPE city_state AS OBJECT
(
  city VARCHAR2(30),
  state VARCHAR2(2)
);
/

and I have a function that returns a variable of this type.

CREATE OR REPLACE FUNCTION closestcity(lat IN NUMBER, lon IN NUMBER) RETURN city_state IS
...

I need to update a table that contains city, state, latitude and longitude columns. With the lat/lon, I should call the function and use the result to update the value of the city/state. I only want to call the function once for each row and there are only some rows that I need to update (let’s say city is NULL)

This is what I got so far

UPDATE (SELECT * FROM t t1 WHERE city IS NULL)
SET (city, state) = (
                     SELECT newcity.city, newcity.state FROM
                       ( SELECT closestcity(latitude, longitude) newcity
                         FROM t t2
                         WHERE t1.latitude = t2.latitude AND
                               t1.longitude = t2.longitude)
                    );

but I get an invalid identifir error. I feel like I’m overcomplicating it, what would be the correct approach to this?

  • 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-06-14T22:33:14+00:00Added an answer on June 14, 2026 at 10:33 pm

    The reason you’ve got that error is because Oracle attempts to qualify newcity referenced in the SELECT newcity.city, newcity.state select statement. It cannot find the object newcity and thus throws the error. Also alias the inline view as t1 if you really need it. As @Rene has mentioned, you can successfully replace it with the table name. To that end you may rewrite your update statement as follows:

    UPDATE (SELECT * FROM t t1 WHERE city IS NULL) t1
       SET (city, state) = (
                             SELECT closestcity(latitude, longitude).city 
                                  , closestcity(latitude, longitude).state
                               FROM t t2
                              WHERE t1.latitude = t2.latitude 
                                AND t1.longitude = t2.longitude 
                            );
    

    Or simply:

    UPDATE t t1 
       SET city  = closestcity(latitude, longitude).city 
         , state = closestcity(latitude, longitude).state
    where t1.city is null
    

    Update#1

    update (select nd.newdata.city  as newcity
                 , nd.newdata.state as newstate
                 , city
                 , state
              from (                             
                     SELECT closestcity(latitude, longitude) newdata
                          , city
                          , state
                       FROM t
                      where city is null
                    ) nd
                  ) q  
    set q.city  = q.newcity
      , q.state = q.newstate 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.