一個顯式使用游標的例子(共分為5個步驟)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Dean_Deng/article/details/7394709

SET SERVEROUTPUT ON;

DECLARE

 --第一步聲明變量
 v_product_id products.product_id%TYPE;
 v_name products.name%TYPE;
 v_price products.price%TYPE;
 --第二步聲明游標
 CURSOR cv_product_cursor IS
 SELECT product_id,name,price
 FROM products
 ORDER BY product_id;
BEGIN
 --第三步打開游標
 OPEN cv_product_cursor;
 LOOP
  --第四步從游標中取出每一行的值,分別存放到不同的列變量中
  FETCH cv_product_cursor
  INTO v_product_id,v_name,v_price;
  --exit the loop when there are no more rows,as indicated by
  --the Boolean variable cv_product_cursor%NOTFOUND (=true when
  --there are no more rows)
  --cv_product_cursor%NOTFOUND值為true,則說明游標已經達到了末尾
  --此時就退出循環
  EXIT WHEN cv_product_cursor%NOTFOUND;
  --use DBMS_OUTPUT.PUT_LINE() to display the variables
  DBMS_OUTPUT.PUT_LINE(
    'v_product_id='||v_product_id||',v_name='||v_name||',v_price='
    ||v_price
  );
 END LOOP;
 --第五步關閉游標
 CLOSE cv_product_cursor;
END;
/
阅读更多

一個顯式轉換的問題

12-18

[code=C#]rnnamespace Ch11Ex02rnrn public class Animals:CollectionBasern rn public Animals this[int animalIndex]rn rn getrn rn return (Animal)List[animalIndex];rn rn setrn rn List[animalIndex] = value;rn rn rnrn public void Add(Animal newAnimal)rn rn List.Add(newAnimal);rn rnrn public void Remove(Animal newAnimal)rn rn List.Remove(newAnimal);rn rn rnrn[/code]rnrn[code=C#]rnnamespace Ch11Ex02rnrn public class Cow : Animalrn rn public Cow(string newName):base(newName)rn rn rn rn rn public void Milk()rn rn Console.WriteLine("0 has been milk.",name);rn rn rnrn[/code]rnrn[code=C#]rnnamespace Ch11Ex02rnrn public class Chicken:Animalrn rn public Chicken(string newName):base(newName)rn rn rn rn rn public void LayEgg()rn rn Console.WriteLine("0 has laid an egg.",name);rn rn rnrn[/code]rn[code=C#]rnnamespace Ch11Ex02rnrn public abstract class Animalrn rn protected string name;rn rn public Animal()rn rn name = "The animal with no name";rn rnrn public Animal(string newName)rn rn rn rnrn public string Namern rn getrn rn return name;rn rn setrn rn name = value;rn rn rnrn public void Feed()rn rn Console.WriteLine("0 has been fed.",name);rn rn rnrn[/code]rn[code=C#]rnnamespace Ch11Ex02rnrn class Programrn rn static void Main(string[] args)rn rn Animals animalCollection = new Animals();rn animalCollection.Add(new Cow("Jack"));rn animalCollection.Add(new Chicken("Vera"));rn foreach (Animal myAnimal in animalCollection)rn rn myAnimal.Feed();rn rn Console.ReadKey();rn rn rnrnrn[/code]rn運行時卻提示這一段不能運行rn[code=C#]rn public Animals this[int animalIndex]rn rn getrn rn return (Animal)List[animalIndex];rn rn setrn rn List[animalIndex] = value;rn rn rn[/code]rn不能顯式轉換,這是怎麼一回事?

没有更多推荐了,返回首页