Search code examples
mysqloraclepercentage

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

  • 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)