sql 使用遊標來刪除表中奇數行的記錄?

2025-03-16 20:30:12 字數 2626 閱讀 4309

1樓:寂夜芳心

似乎用遊遲手標有點大才小用了。

新碼鉛嫌建表激虧來測試即可。

create database test;

use test;

create table test(

id int primary key not null auto_increment

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

insert into test values(null);

delete語句:

delete from test where (id%2)=1;

select * from test;

效果:<>

2樓:匿名使用者

裡面說的很詳細者姿敬,**並茂,冊行我的首慎意見,謝謝!!!

sql如何使用遊標查詢指定行記錄

3樓:方清海

可以不過不用遊標也可以。

select * from (select *,row_number() over(order by 排序列) as rownum from table) a

where rownum>=n and rownum<=m

4樓:網友

當然可以,但如果想查第n條到第m條記錄會有很多比遊標更方便快速的方法,具體的可hi我談談。

sql中如何取得乙個按奇數偶數排列,用遊標?

5樓:網友

首先保證1到10值為整型或轉為整型。

然後select * from table order by column%2,column

把table,column分別替換即可。

6樓:阿咕嚕

oracle,不用遊標,實現奇偶分開,select * from table order by mod(id,2)

幹嘛非要用遊標,又不是很複雜的東西,

sql 遊標會生成的表有重複,怎麼刪除重複的表只保留乙個

7樓:網友

多次執行遊標的原因?

如果是這樣每次執行遊標open之前先把表truncate table tbname

或則delete from 表。

truncate比較快。

8樓:

雖然不明白你的意思,但是你試試distinct

sql 怎麼使用儲存過程迴圈刪除多張表記錄?

9樓:網友

用while 迴圈。

create procedure 儲存過程名。

傳的表名的字元陪搏串 varchar(max)

asdeclare @inx int

declare @tablename varchar(max)

aswhile(charindex('&傳的表名的字串)>0)

beginset @idx =charindex('&傳的表好亂缺名的字串)>

set @tablename = substring(@傳的友辯表名的字串,0,@idx)

delete @tablename where 條件。

set @傳的表名的字串 = substring((@傳的表名的字串,@idx+1, len(@傳的表名的字串)-@idx)

不過傳的字串是table1&table2$table3& 這個樣子的。

為什麼我在sql procedure裡用遊標遍歷後,得到的返回的結果是n張一行的表不是一張表的n行資料?

10樓:

你可以用在遊標處理時把每一行的資料寫入乙個表,再到c#呼叫這個表。

11樓:網友

那要你用遊標後呼叫的sql是什麼。

12樓:網友

要從你寫的**中找問題,把你的**貼上來吧。

sql server2008怎麼刪除遊標????

13樓:阿冬

遊標使用完,先用close語句關閉它,然後用deallocate語句釋放遊標即可。

sql中刪除表中的內容,SQL中刪除表中的內容

1 如果想清空表裡面的內容可以使用 delete from kf 2 如果是想刪除整個表可以使用 drop table kf。sql中刪除表中的所有資料的方法 1 truncate table 刪除表中的所有行,而不記錄單個行刪除操作。1 語法 truncate table name 2 引數 na...

sql語句刪除某欄位中資料sql語句刪除某欄位中一個資料

update 表名 set 欄位名 null where 欄位名 值 and 欄位2 值2 值就是你要刪除的資料 欄位2和值2值是用來定位值在表中的具體位置 只有前面的值很容易刪除同欄位等值的數 加上欄位2值2就可以精準定位 值2最好是唯一約束下面這是我寫的 update student set 年...

求刪除SQL資料庫中某個表的重複資料

1.先將umane用一個臨時表存起來 select distinct uname uname into a form users 2.刪除users表內的資料 delete from users 3.把臨時表使用者加到users表中,並將預設upwd全設為1234要看你upwd是什麼資料型別 如果是...