How can I update a column with PL\SQL by using a calculated value

Botond Éles

I created a dummy database for learning purposes, and I purposefully created some duplicated records in one of the tables. In every case I want to flag one of the duplicated records as Latest='Y', and the other record as 'N', and for every single record the Latest flag would be 'Y'.

I tried to use PlSQL to go through all of my records, but when I try to use the previously calculated value (which would tell that its a duplicated record) it says that:

ORA-06550: line 20, column 17: PLS-00201: identifier 'COUNTER' must be declared

Here is the statement I try to use:

DECLARE CURSOR cur IS SELECT order_id, order_date, person_id, amount, successfull_order, country_id, latest, ROWCOUNT AS COUNTER FROM (SELECT order_id, order_date, person_id, amount, successfull_order, country_id, latest, ROW_NUMBER () OVER (PARTITION BY order_id, order_date, person_id, amount, successfull_order, country_id ORDER BY order_id, order_date, person_id, amount, successfull_order, country_id) ROWCOUNT FROM orders) orders FOR UPDATE OF orders.latest; rec cur%ROWTYPE; BEGIN FOR rec IN cur LOOP IF MOD (COUNTER, 2) = 0 THEN UPDATE orders SET latest = 'N' WHERE CURRENT OF cur; ELSE UPDATE orders SET latest = 'Y' WHERE CURRENT OF cur; END IF; END LOOP; END;

I am new to PlSQL so I tried to modify the statements I found here: http://www.adp-gmbh.ch/ora/plsql/cursors/for_update.html

What should I change in my statement, or should I use a different approach?

Thanks for your answers in advance! Botond

Maheswaran Ravisankar

Your refer the ROWNUM as COUNTER in your cursor.
While fetching, you should be accessing it from the cursor reference like MOD (rec.COUNTER, 2)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I update to columns with the same value?

From Java

How can I compare many datasets update several columns based on the max value of a single column in SAS?

From Dev

I have the same column in multiple tables, and want to update that column in all tables to a specific value. How can I do this?

From Dev

JAVA:How can I update my arraylist value (using singleton), asigning another value, it keeps erroring out

From Dev

How can I take a value calculated in a if statement and use it outside the if statement?

From Dev

How can I update a value in a mutable HashMap?

From Dev

Using xmlstarlet and BASH, how can I update a value of an element based on the elements current value

From Dev

How can I sort by a calculated value in elasticsearch

From Dev

How I can replace an existing html val with a value calculated later using html and/or css?

From Dev

How to have a MySQL table column with a calculated value

From Dev

How do I create an automated calculated column?

From Dev

How to update a column using another column's value with a condition?

From Dev

How can I turn a Calculated Column back into a data column in an Excel Table?

From Dev

How can I add a calculated column based on another column in an SQL select statement

From Dev

Update a column with a calculated value

From Dev

How can I update value of array in database

From Dev

How to query on calculated column using Breeze

From Dev

how can I add a calculated column that would show the total # of matching rows in a one-to-many relationship

From Dev

rails mass update column by inserting value calculated from other columns

From Dev

How can I update a column with same value in another table ssms?

From Dev

Using xmlstarlet and BASH, how can I update a value of an element based on the elements current value

From Dev

How can I update a value without resetting it?

From Dev

How I can replace an existing html val with a value calculated later using html and/or css?

From Dev

How can I update and divide column values?

From Dev

How can I update an integer column with a value from a decimal column in two tables?

From Dev

Using SQL how can I update field values of one column to match a different column's field value only if the values do NOT equal?

From Dev

How can update a column based on the value of another column in SQL?

From Dev

How can I make a dynamic value for update?

From Dev

How to update a column using another column value?

Related Related

  1. 1

    How can I update to columns with the same value?

  2. 2

    How can I compare many datasets update several columns based on the max value of a single column in SAS?

  3. 3

    I have the same column in multiple tables, and want to update that column in all tables to a specific value. How can I do this?

  4. 4

    JAVA:How can I update my arraylist value (using singleton), asigning another value, it keeps erroring out

  5. 5

    How can I take a value calculated in a if statement and use it outside the if statement?

  6. 6

    How can I update a value in a mutable HashMap?

  7. 7

    Using xmlstarlet and BASH, how can I update a value of an element based on the elements current value

  8. 8

    How can I sort by a calculated value in elasticsearch

  9. 9

    How I can replace an existing html val with a value calculated later using html and/or css?

  10. 10

    How to have a MySQL table column with a calculated value

  11. 11

    How do I create an automated calculated column?

  12. 12

    How to update a column using another column's value with a condition?

  13. 13

    How can I turn a Calculated Column back into a data column in an Excel Table?

  14. 14

    How can I add a calculated column based on another column in an SQL select statement

  15. 15

    Update a column with a calculated value

  16. 16

    How can I update value of array in database

  17. 17

    How to query on calculated column using Breeze

  18. 18

    how can I add a calculated column that would show the total # of matching rows in a one-to-many relationship

  19. 19

    rails mass update column by inserting value calculated from other columns

  20. 20

    How can I update a column with same value in another table ssms?

  21. 21

    Using xmlstarlet and BASH, how can I update a value of an element based on the elements current value

  22. 22

    How can I update a value without resetting it?

  23. 23

    How I can replace an existing html val with a value calculated later using html and/or css?

  24. 24

    How can I update and divide column values?

  25. 25

    How can I update an integer column with a value from a decimal column in two tables?

  26. 26

    Using SQL how can I update field values of one column to match a different column's field value only if the values do NOT equal?

  27. 27

    How can update a column based on the value of another column in SQL?

  28. 28

    How can I make a dynamic value for update?

  29. 29

    How to update a column using another column value?

HotTag

Archive