| |

VerySource

 Forgot password?
 Register
Search
Author: 0小宝贝0

On the seat sorting problem! Online etc ... (.net)

[Copy link]

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-30 14:18:02
| Show all posts
Wrong at the beginning, only the seatno of status1 = N is unchanged
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-1-30 15:36:01
| Show all posts
Does seatno allow duplicates?
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-30 17:00:02
| Show all posts
seatno is unique
Reply

Use magic Report

1

Threads

26

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 Unknown

Post time: 2020-1-31 14:45:01
| Show all posts
This should be written in Procedure!
---- For Oracle!
Create or Replace Procedure ListSequence (V_EMPNO IN NUMBER) as
V_SQL VARCHAR2 (200);
V_COUNT NUMBER: = 1;
V_DELETE_SEATNO NUMBER: = 0;
TYPE REFCUR IS REF CURSOR;
   C_T1 REFCUR;
CURSOR C1 IS
    SELECT * FROM TABLE_NAME;
C1_DATA C1% ROWTYPE;

BEGIN
V_SQL: = 'SELECT SEATNO FROM TABLE_NAME WHERE EMPNO =' || V_EMPNO;
EXECUTE IMMEDIATE V_SQL INTO V_DELETE_SEATNO;

EXECUTE IMMEDIATE 'DELETE FROM TABLE_NAME WHERE EMPNO =' || V_EMPNO;
COMMIT;

OPEN C1;
LOOP
   FETCH C1 INTO C1_DATA;
   EXIT WHEN C1% NOTFOUND;
   IF C1_DATA.SEATNO> V_DELETE_SEATNO THEN
      IF C1_DATA.STATUS1 = 'N' THEN
         V_COUNT: = V_COUNT + 1;
      ELSE
         V_SQL: = 'UPDATE TABLE_NAME SET SEATNO = SEATNO-' || V_COUNT || 'WHERE SEATNO =' || C1_DATA.SEATNO;
          EXECUTE IMMEDIATE V_SQL;
          COMMIT;
      END IF;
   END IF;
END;
Reply

Use magic Report

1

Threads

26

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 United States

Post time: 2020-1-31 17:00:01
| Show all posts
Of course, it is best to change the above procedure to trigger. Then, after you delete the data, it will automatically update the relevant values ​​for you. You can use select * from table_name order by seatno!

Remember to create the index. This method is a bit slow when the amount of data is large and the data is read and written frequently.
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-1-31 18:00:02
| Show all posts
Mark
Reply

Use magic Report

1

Threads

26

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-2-1 00:54:01
| Show all posts
There was a problem with Procedure just now, and the following changes have been made!
---- For Oracle!
Create or Replace Procedure ListSequence (V_EMPNO IN NUMBER) as
V_SQL VARCHAR2 (200);
V_DELETE_SEATNO NUMBER: = 0;
V_TEMP_INDEX NUMBER: = 0;
TYPE REFCUR IS REF CURSOR;
   C_T1 REFCUR;
CURSOR C1 IS
    SELECT * FROM TABLE_NAME;
C1_DATA C1% ROWTYPE;

BEGIN
V_SQL: = 'SELECT SEATNO FROM TABLE_NAME WHERE EMPNO =' || V_EMPNO;
EXECUTE IMMEDIATE V_SQL INTO V_DELETE_SEATNO;

EXECUTE IMMEDIATE 'DELETE FROM TABLE_NAME WHERE EMPNO =' || V_EMPNO;
COMMIT;

OPEN C1;
LOOP
   FETCH C1 INTO C1_DATA;
   EXIT WHEN C1% NOTFOUND;
   IF C1_DATA.SEATNO> V_DELETE_SEATNO THEN
      IF C1_DATA.STATUS1 <> 'N' THEN
         V_TEMP_INDEX: = C1_DATA.SEATNO;
         V_SQL: = 'UPDATE TABLE_NAME SET SEATNO =' || V_DELETE_SEATNO || 'WHERE SEATNO =' || C1_DATA.SEATNO;
          EXECUTE IMMEDIATE V_SQL;
          COMMIT;
          V_DELETE_SEATNO: = V_TEMP_INDEX;
      END IF;
   END IF;
END;
Reply

Use magic Report

1

Threads

26

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-2-1 03:45:02
| Show all posts
One missing End Loop; haha, please add in the penultimate line!
Reply

Use magic Report

1

Threads

26

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-7 00:15:02
| Show all posts
The above is written with reference to the way in which holes in dislocations in materials science move! Ha ha
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list