這篇文章主要介紹“怎么求數(shù)據(jù)庫嵌套表平均值”,在日常操作中,相信很多人在怎么求數(shù)據(jù)庫嵌套表平均值問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么求數(shù)據(jù)庫嵌套表平均值”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、網(wǎng)站制作、龍馬潭網(wǎng)絡(luò)推廣、成都微信小程序、龍馬潭網(wǎng)絡(luò)營銷、龍馬潭企業(yè)策劃、龍馬潭品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供龍馬潭建站搭建服務(wù),24小時服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
我創(chuàng)建了一個SCHEMA級別的NUMBER型嵌套表:
CREATE OR REPLACE TYPE plch_numbers_t IS TABLE OF NUMBER /
哪些選項實現(xiàn)了一個名字為plch_avg的函數(shù),能夠計算一個上述嵌套表中所有元素的平均值,從而使得下列代碼塊執(zhí)行之后會顯示"3.5"?
DECLARE l_numbers plch_numbers_t := plch_numbers_t (1, 2, 3, 4, 5, 6); BEGIN DBMS_OUTPUT.put_line (plch_avg (l_numbers)); END; /
(A)
CREATE OR REPLACE FUNCTION plch_avg (numbers_in IN plch_numbers_t) RETURN NUMBER IS l_index PLS_INTEGER := numbers_in.FIRST; l_sum NUMBER := 0; BEGIN WHILE l_index IS NOT NULL LOOP l_sum := l_sum + numbers_in (l_index); l_index := numbers_in.NEXT (l_index); END LOOP; RETURN l_sum / numbers_in.COUNT; END; /
(B)
CREATE OR REPLACE FUNCTION plch_avg (numbers_in IN plch_numbers_t) RETURN NUMBER IS l_average NUMBER; BEGIN SELECT AVG (COLUMN_VALUE) INTO l_average FROM TABLE (numbers_in); RETURN l_average; END; /
(C)
CREATE OR REPLACE FUNCTION plch_avg (numbers_in IN plch_numbers_t) RETURN NUMBER IS BEGIN RETURN AVG (numbers_in); END; /
(D)
CREATE OR REPLACE FUNCTION plch_avg (numbers_in IN plch_numbers_t) RETURN NUMBER IS l_index PLS_INTEGER := numbers_in.FIRST; l_average NUMBER := 0; BEGIN WHILE l_index IS NOT NULL LOOP l_average := l_average + numbers_in (l_index)/numbers_in.count; l_index := numbers_in.NEXT (l_index); END LOOP; RETURN l_average; END; /
(E)
CREATE OR REPLACE FUNCTION plch_avg (numbers_in IN plch_numbers_t) RETURN NUMBER IS l_average NUMBER; BEGIN SELECT AVG (numbers_in(ROWNUM)) INTO l_average FROM numbers_in; RETURN l_average; END; /
實測答案ABC
C報錯 PLS-00204: 函數(shù)或偽列 'AVG' 只能在 SQL 語句中使用
E報錯 PL/SQL: ORA-00942: 表或視圖不存在
答案ABD, B是最佳答案,注意D在某些情況下可能出現(xiàn)誤差。
到此,關(guān)于“怎么求數(shù)據(jù)庫嵌套表平均值”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
網(wǎng)頁標(biāo)題:怎么求數(shù)據(jù)庫嵌套表平均值
地址分享:http://weahome.cn/article/gccpod.html