一半记录的设置值(Oracle,PL / SQL)

时间:2019-02-05 12:37:30

标签: sql oracle loops plsql oracle12c

我试图循环所有来自tableA的记录,并为columnA = 1设置一半的记录,为columnA = 2的记录下一半。

declare

Type T2 Is Table Of TableA%Rowtype Index By Binary_Integer;
V2 T2;
Type T3 Is Table Of TableA%Rowtype Index By Binary_Integer;
V3 T3;

Maxrow Number(10);
mHalf  Number(10);
begin

 Select round(Max(Rownum)/2) Into Maxrow From TableA;

 Select * Bulk Collect Into V2 From TableA Where Rownum < Mhalf;
 Select * Bulk Collect Into V3 From TableA Where Rownum >= Mhalf;

 For I In 1..2 Loop
   If I=1 Then          
      For Z In V2.First..V2.Last Loop
         update tableA set columnA = 1 where Rownum = V2(Z);
      End Loop;
   Elsif I=2 Then
      For ZZ In V3.First..V3.Last Loop
         update tableA set columnA = 2 where Rownum = V3(ZZ);
      End Loop;
   End if;       

 End Loop;    
end;

但是出了点问题。当我检查时:

Select Count(*) From tableA Where Rownum > 300;

这里我没有任何记录

2 个答案:

答案 0 :(得分:2)

constructor(props) {
  super(props);
  this.state = { posts: null };
}

_isMounted = false;
componentDidMount() {
  this._isMounted = true;
  getPosts()
    .then(snapshot => {
      const result = snapshot.val();
      if(this._isMounted) { 
          this.setState(() => ({ posts: result }))
      }
    })
    .catch(error => {
      console.error(error);
    });
}

componentWillUnmount() {
  this._isMounted = false;
  this.setState({ posts: null });
}

render() {
  return (
    <div>
      <PostList posts={this.state.posts} />
    </div>
  );
}

答案 1 :(得分:0)

Select * Bulk Collect Into V2 From TableA Where Rownum < Mhalf;
 Select * Bulk Collect Into V3 From TableA Where Rownum >= Mhalf;

更改为:

SELECT  * 
BULK COLLECT INTO V2
FROM    (
         SELECT a.*,
                ROWNUM rn 
         FROM   (
                  SELECT  *
                  FROM    tablea
                ) a
        )
WHERE   rn < Mhalf;

SELECT  * 
BULK COLLECT INTO V#
FROM    (
         SELECT a.*,
                ROWNUM rn 
         FROM   (
                  SELECT  *
                  FROM    tablea
                ) a
        )
WHERE   rn >= Mhalf;