'Get percentage calculation and update the column

I want to update two columns UG_length and AR_length as 80% and 20% respectively of NE_length from below query.

SELECT 
   CALCULATED_LENGTH AS NE_LENGTH , 
   (CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) 
                  ELSE 0 END) AS UG_length,
    (CASE WHEN RJ_CONSTRUCTION_METHODOLOGY  LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) 
                  ELSE 0 END) AS AR_length
   FROM NE.MV_SPAN@DB_LINK_NE_VIEWER;

What is the easiest way of doing it in Oracle?

I need the percentage wise bifurcation of the NE_length column.



Solution 1:[1]

You can use update

update NE.MV_SPAN@DB_LINK_NE_VIEWER
   set UG_length  =  (CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0)*0.8
                  ELSE 0 END)
   , AR_length  = (CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0)*0.2
                  ELSE 0 END) 
  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1