![1986 1986]()
本文介绍了cursor for循环将o / p作为游标返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 嗨 我是游标的新手 我有一张桌子 SQL> select * from commodity_m_details; COMMODITY_ID COMMODITY_NAME STAR END INTERVAL -------------------- ------------------------------ ---- ---- ------------ --- C1 Commodity1 1996 2006 2 C2 Commodity2 1996 2000 2 C3 Commodity3 1983 1995 4 i需要为每种商品编写不同年份的程序 o / p就像是 对于C3 年 ----------------- 1983-1986 1986-1989 1989-1992 1992-1995 i写得像这样HiI am new to cursorsI have a tableSQL> select * from commodity_m_details;COMMODITY_ID COMMODITY_NAME STAR END INTERVAL-------------------- ------------------------------ ---- ---- ---------------C1 Commodity1 1996 2006 2C2 Commodity2 1996 2000 2C3 Commodity3 1983 1995 4i need to write a procedure for different years for every commodityo/p is likeFor C3year-----------------1983-19861986-19891989-19921992-1995i have written like this 展开 | 选择 | Wrap | 行号推荐答案 是的,它只会打印1986年因为: 检查以下行: V_data:= 0; V_data:= V_data +(record.end_year-record.start_year) /record.interval_number; V_data:= record.start_year + V_data; 例如: V_data:= 0 +(1995 - 1983)/ 4 - 这将给你3 V_data:= 1983 + 3 - 这将给你1986 DBMS_OUTPUT.PUT_LINE(V_data); 为了获得1986,1989,1992,1995,你需要每年增加3次。 例如: V_data现在= 1986 增加3将它给予V_data:= 1989然后1992然后1995你需要 所以对于光标中的每条记录,LOOP到interval no of times (即这里4次),计算(end_year - start_year)/ interval并将其存储在变量V_data中 现在执行以下操作:Yes for C3 it will print only 1986 because:check below lines:V_data := 0;V_data:=V_data+(record.end_year-record.start_year)/record.interval_number;V_data:=record.start_year+V_data;Eg:V_data:= 0 + (1995 - 1983)/4 -- this will give you 3V_data:= 1983 + 3 -- this will give you 1986DBMS_OUTPUT.PUT_LINE(V_data);In order to get 1986,1989,1992,1995, you need to add 3 to the year 4 times.Eg:V_data now = 1986adding 3 to it will givve V_data:= 1989 then 1992 then 1995 as you requireSo For each record from cursor, LOOP through "interval no of times" (ie 4 times here), calculate (end_year - start_year)/interval and store it in a variable V_dataNow do the following: 展开 | 选择 | Wrap | Line数字 这篇关于cursor for循环将o / p作为游标返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-08 09:55