How to update selected rows only in Oracle SQL

4.3k views Asked by At

So basically I have a tabular form. One of the columns is a checkbox, another column is called 'hidden' and will contain either the value 'yes' or 'no'.

I have a button for hiding rows, so the user should be able to select certain rows using the checkboxes, then click the hide button and it should change the rows that the user has selected to 'yes' under the 'hidden' column

So my SQL looks like this:

UPDATE nameOfTable
SET hidden = 'Yes'
WHERE hidden = 'No';

Obviously this will just update the 'hidden' column to 'yes' for all rows that are currently 'no' but how do I instead make it to just update the rows that user has selected using the checkboxes?

3

There are 3 answers

0
Ankit Chhajed On BEST ANSWER

just pass the value of the primary key (id) selected y the user to the database query and compare it with the primary key field. and obviously the above answer by @SRIRAM will definitely work for you..!!

5
SRIRAM On
update nameoftable 
  set hidden='yes'
   where id =selectedcheckboxid

here id is the primary key of the table

0
Patrick548 On

You are going to want to use the HTMLBD_APPLICATION package to do this. When you create a tabular form APEX automatically assigns an id to each of the editable fields in the table. When you click the submit button you will want a function that loops through the selected items in the table. You can find out what the name that APEX assigns to each field is by inspecting the HTML for that field in that table (it will be the HTML id and will look like G_FXX where the X is a number). You will also have to have some field in the table to identify each row (like a primary key) so that the database knows what row to update on the backend.

BEGIN
  FOR i IN 1..HTMLBD_APPLICATION.G_F01.COUNT LOOP
    UPDATE nameoftable SET hidden = 'yes' WHERE
      HTMLDB_APPLICATION.G_FXX(HTMLDB_APPLICATION.G_F01(i)) = row_key;
  END LOOP;
END;

The XX in the update statement will be the field in the table that contains the id for the row. This will get a list of the checked boxes and the loop through the list updating the each row that have been checked.