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 8272539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:09:12+00:00 2026-06-08T07:09:12+00:00

I have this function: Procedure UpdateDefaultWeight ( vYear Number, costWeight Number, qualityWeight Number, serviceWeight

  • 0

I have this function:

      Procedure UpdateDefaultWeight  ( vYear Number, costWeight Number, qualityWeight Number, serviceWeight Number ) 
      AS

        type weight_table is table of Number(5,2) index by varchar2(50);
        weightArray weight_table;
        currentPosition varchar2(50);
      Begin

        weightArray('Cost Weighting')    := costWeight;
        weightArray('Quality Weighting') := qualityWeight;
        weightArray('Service Weighting') := serviceWeight;

        currentPosition := weightArray.first;

        Loop
          Exit When currentPosition is null;
          Insert Into GVS.GVSSD16_DFLT_WEIGHT
            ( cal_year, metric_name, metric_val )
          Values
            ( vYear, currentPosition, weightArray(currentPosition) ); 

          currentPosition := weightArray.next(currentPosition);
        End Loop;
      END;

Right now as I wrote it, it just does an INSERT. However, I need it to UPSERT. I’ve looked around at documentation on MERGE, but mainly it’s just left me confused on how to apply the syntax to my specific case.

I’ve looked here and here and I get the jist of it, but syntax fails me.

Anyone care to help an Oracle newbie out?

  • 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-08T07:09:15+00:00Added an answer on June 8, 2026 at 7:09 am

    Assuming that cal_year and metric_name define the join criteria, this should get you close (untested):

    MERGE INTO GVS.GVSSD16_DFLT_WEIGHT d
         USING (SELECT vYear AS YY,
                       currentPosition AS POS,
                       weightArray (currentPosition) AS WA
                  FROM DUAL) v
            ON (d.cal_year = v.YY AND d.metric_name = v.pos)
    WHEN MATCHED
    THEN
       UPDATE SET metric_val = v.WA
    WHEN NOT MATCHED
    THEN
       INSERT     (cal_year, metric_name, metric_val)
           VALUES (v.YY, v.POS, v.WA);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL function which is wrapped by a stored procedure: ALTER FUNCTION
I have this recommendations table: Table public.recommendations Column | Type | Modifiers -----------------------+-----------------------------+-------------------------------------------------------------- id
I have this function defined in a delphi code: procedure TestFLASHWNew( name: array of
I have this procedure in the database: CREATE OR REPLACE FUNCTION replacePageRelevance(id INT, value
So I have this user-defined table type parameter, which is used in my scalar
Have this objects and table types: CREATE TYPE Person_typ AS OBJECT ( name CHAR(20),
I have this scenario: a recursive procedure (or function) is called like {DoSomething Data
I have this function // add history paths and save data function AddPath( strTag,
I have this function: int firstHeapArray (IntHeapArray h) { if(!emptyHeapArray(h)) return h.array[0]; } It's
I have this function to create a request to another file to update the

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.