/tupian/20230522/thread-1499223-20-1.html
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、網(wǎng)站制作、儀隴網(wǎng)絡(luò)推廣、微信平臺(tái)小程序開(kāi)發(fā)、儀隴網(wǎng)絡(luò)營(yíng)銷(xiāo)、儀隴企業(yè)策劃、儀隴品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供儀隴建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com191樓
為了鼓勵(lì)訪問(wèn)者越來(lái)越多地使用我們的網(wǎng)站,我們針對(duì)他們的活動(dòng)給予積分。我們的積分計(jì)算方法為基本點(diǎn)數(shù)和系數(shù)的乘積。如果活動(dòng)發(fā)生在 08:00 之前,系數(shù)為3; 如果發(fā)生在 16:00 之前,系數(shù)為2; 其他的系數(shù)為1. 這個(gè)公式以如下函數(shù)實(shí)現(xiàn):
CREATE OR REPLACE FUNCTION plch_multiplier RETURN PLS_INTEGER IS c_hour CONSTANT PLS_INTEGER := TO_NUMBER (TO_CHAR (SYSDATE, 'HH24')) ; BEGIN RETURN CASE WHEN c_hour < 8 THEN 3 WHEN c_hour < 16 THEN 2 ELSE 1 END; END; /
然后我用這個(gè)包里的函數(shù)為活動(dòng)計(jì)算積分:
CREATE OR REPLACE PACKAGE plch_pkg IS FUNCTION points_for_activity (base_points_in IN INTEGER) RETURN PLS_INTEGER; END; /
先不假設(shè)我們的應(yīng)用程序是狀態(tài)相關(guān)或者狀態(tài)無(wú)關(guān),哪些選項(xiàng)實(shí)現(xiàn)了包體,使得計(jì)算總是正確的?
(A)
CREATE OR REPLACE PACKAGE BODY plch_pkg IS g_multiplier PLS_INTEGER; FUNCTION points_for_activity (base_points_in IN INTEGER) RETURN PLS_INTEGER IS BEGIN RETURN base_points_in * g_multiplier; END; BEGIN g_multiplier := plch_multiplier(); END; /
(B)
CREATE OR REPLACE PACKAGE BODY plch_pkg IS FUNCTION points_for_activity (base_points_in IN INTEGER) RETURN PLS_INTEGER IS BEGIN RETURN base_points_in * plch_multiplier(); END; END; /
(C)
CREATE OR REPLACE PACKAGE BODY plch_pkg IS g_multiplier PLS_INTEGER; FUNCTION points_for_activity (base_points_in IN INTEGER) RETURN PLS_INTEGER IS BEGIN IF g_multiplier IS NULL THEN g_multiplier := plch_multiplier(); END IF; RETURN base_points_in * g_multiplier; END; END; /
(D)
CREATE OR REPLACE PACKAGE BODY plch_pkg IS g_multiplier PLS_INTEGER := plch_multiplier(); FUNCTION points_for_activity (base_points_in IN INTEGER) RETURN PLS_INTEGER IS BEGIN RETURN base_points_in * g_multiplier; END; END; /
答案在194樓
2011-11-25答案B. 其他寫(xiě)法都是“靜態(tài)”的,不能取到當(dāng)前時(shí)間。