简体   繁体   English

如何仅在Oracle SQL中更新选定的行

[英]How to update selected rows only in Oracle SQL

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: 所以我的SQL看起来像这样:

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? 显然,这只会将当前为“否”的所有行的“隐藏”列更新为“是”,但是我该如何使其仅更新用户使用复选框选择的行呢?

You are going to want to use the HTMLBD_APPLICATION package to do this. 您将要使用HTMLBD_APPLICATION包来执行此操作。 When you create a tabular form APEX automatically assigns an id to each of the editable fields in the table. 创建表格形式时,APEX会自动为表中的每个可编辑字段分配一个ID。 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). 您可以通过检查表中该字段的HTML来找出APEX分配给每个字段的名称(它是HTML ID,看起来像G_FXX,其中X是数字)。 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. update语句中的XX将是表中包含行ID的字段。 This will get a list of the checked boxes and the loop through the list updating the each row that have been checked. 这将获得一个复选框列表,并通过列表循环更新已选中的每一行。

update nameoftable 
  set hidden='yes'
   where id =selectedcheckboxid

here id is the primary key of the table id是表的主键

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. 只需将用户选择的主键(id)的值传递给数据库查询,然后将其与主键字段进行比较。 and obviously the above answer by @SRIRAM will definitely work for you..!! 显然@SRIRAM的上述答案肯定对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM