SQLPLUS: Set multiple values if variable != blah

时间:2016-02-12 21:20:16

标签: oracle sql-update sqlplus case-statement

So, for the first time in my life I wasn't able to find my answer here and had to create my own question.

Here is my script:

import java.text.DecimalFormat;
public class Employee implements Comparable<Employee> {
    private Double salary;
    private int hoursWorked;
    private String firstName;
    private String lastName;
    private static DecimalFormat df = new DecimalFormat("0.00");
    public Employee(double salary, int hoursWorked, String firstName,
            String lastName) {
        this.salary = salary;
        this.hoursWorked = hoursWorked;
        this.firstName = firstName;
        this.lastName = lastName;
    }
    @Override
    public String toString() {
        return firstName + " " + 
                lastName + " works " + 
                hoursWorked + " hours and makes $" + 
                df.format(salary);
    }
    public Double getSalary() {
        return salary;
    }
    public void setSalary(Double salary) {
        this.salary = salary;
    }
    public int getHoursWorked() {
        return hoursWorked;
    }
    public void setHoursWorked(int hoursWorked) {
        this.hoursWorked = hoursWorked;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    @Override
    public int compareTo(Employee o) {
        // TODO Auto-generated method stub
        if(salary.compareTo(o.getSalary()) > 0)
            return -1;
        else if(salary.compareTo(o.getSalary()) < 0)
            return 1;
        else
        {
            return lastName.compareTo(o.getLastName());
        }
    }

}

You can see that I have some of the SET commented out. How could I do this on the fly?

For example, the feed I get has a '-' in the field they don't want updated. A 'Y' or 'N' is passed otherwise and is what is placed in the field.

I tried several variations of:

 UPDATE EC_PLAN_OFFERED
    SET AUTHOR_ID = 'ATTESTATION_FIX', 
        -- MIN_ESSENTIAL_COV_IN = '&&7',
        -- MIN_VALUE_PLAN_IN = '&&8',
        DEPENDENT_COV_AVAL_IN = '&&3', 
        SPOUSE_COVERAGE_AVL_IN = '&&4', 
        SELF_INSURED_IN = '&&5'
    WHERE EMPLOYEE_ONLY_CVG_LVL_IN = 'Y'
        -- AND MEDICAL_PLAN_ID = '&&6'  
        AND (WAIVED_COVERAGE_IN = 'N' OR WAIVED_COVERAGE_IN IS NULL) 
        AND AUTHOR_ID <> 'IMPORT_NON_EMPLOYEE'
        AND OFFER_ID IN (
            SELECT OFFER_ID 
            FROM EC_COVERAGE_OFFER 
            WHERE NVL(COVERAGE_START_DT, EVENT_DT) < TO_DATE('01/01/2016','MM/DD/YYYY')
        );

hoping it would place the line when I needed it, but that doesn't work as intended.

Please note this is SQLPLUS and being called via '.bat'.

Any suggestions other than use another language lol? Thanks!

1 个答案:

答案 0 :(得分:0)

If I correctly understand your need, you can try something like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="table table-bordered table-striped" id="mobile-grid">
  <tr>
    <th>header</th>
    <td>cell</td>
    <td id="mobile-options" hidden>hidden td</td>
  </tr>
</table>

This says to always update the value of the column in this way:

MIN_ESSENTIAL_COV_IN = decode('&&7','-',MIN_ESSENTIAL_COV_IN, '&&7' )