日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

根据消费定额生成菜单的算法(原创)

發布時間:2023/12/31 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 根据消费定额生成菜单的算法(原创) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在去年一個實驗性項目中有這樣一個問題,飯店根據顧客消費意愿進行菜單自動生成,如:699元套餐、899元套餐等。菜品類型有涼菜、熱菜、蒸菜等等,具體需求不詳細描述。關鍵是一個根據消費金額自動生成菜單的算法。可惜當時的代碼找不到了。
今天在論壇中又遇到一個類似問題,正好可用以回顧。如下:
表結構:

SQL>?create?table?t_money(id?int?primary?key,amount?int?not?null);
?
Table?created
?
Executed?
in?0.468?seconds

插入數據:

Code
SQL>?insert?into?t_money?values(1,2);
?
1?row?inserted
?
Executed?
in?0?seconds
?
SQL
>?insert?into?t_money?values(2,2);
?
1?row?inserted
?
Executed?
in?0?seconds
?
SQL
>?insert?into?t_money?values(3,3);
?
1?row?inserted
?
Executed?
in?0?seconds
?
SQL
>?insert?into?t_money?values(4,5);
?
1?row?inserted
?
Executed?
in?0?seconds
?
SQL
>?insert?into?t_money?values(5,2);
?
1?row?inserted
?
Executed?
in?0.016?seconds
?
SQL
>?insert?into?t_money?values(6,8);
?
1?row?inserted
?
Executed?
in?0.016?seconds
?
SQL
>?insert?into?t_money?values(7,1);
?
1?row?inserted
?
Executed?
in?0?seconds
?
SQL
>?insert?into?t_money?values(8,2);
?
1?row?inserted
?
Executed?
in?0?seconds
?
SQL
>?insert?into?t_money?values(9,3);
?
1?row?inserted
?
Executed?
in?0?seconds
?
SQL
>?insert?into?t_money?values(10,3);
?
1?row?inserted
?
Executed?
in?0?seconds


?

Code
SQL>?select?substr(id,1,3)?id,substr(amount,1,3)?amount?from?t_money;
?
ID?????AMOUNT
------?------
1??????2
2??????2
3??????3
4??????5
5??????2
6??????8
7??????1
8??????2
9??????3
10?????3
?
10?rows?selected
?
Executed?
in?0.156?seconds

?

問題是:
從表中選取若干條數據,使得被選出來的幾條數據的amount(金額)字段之和等于10,要求存儲過程能返回被選取出來的數據的序列號。 舉例:2+3+5=10 返回序列號:1,3,4?
存儲過程代碼:

Code
create?or?replace?procedure?P_test(O_str?out?varchar2)exp user1/pwd@server owner=user1 file=c:\file.dmp
imp user2/pwd@server fromuser=user1 touser=user2 file=c:\file.dmp
as
???????v_str??????
varchar2(20):=',';
???????v_id???????
number;
???????v_count????
number;
???????v_tmp??????
number?:=0;
???????v_money????
number?:=0;
begin
???????
???????
select?count(0)?into?v_count?from?t_money;
???????loop
???????????
select?count(0)?into?v_count?from?t_money?where?not?instr(v_str,',' || id || ',')>0?and?amount?<=?10-v_money;
???????????
if?v_count?=?0?then
??????????????
exit;
??????????????
--?or?restart
???????????end?if;
???????????
select?id,amount?into?v_id,v_tmp?from?
??????????????????(
select?id,amount?from?t_money?where?not?instr(v_str,',' || id || ',')>0?and?amount?<=?10-v_money?order?by?dbms_random.value)
????????????????
where?rownum?<2;
???????????v_money?:
=?v_money?+?v_tmp;
???????????v_str?:
=?v_str?||?v_id?||',';
???????????
exit?when?v_money?=10;
???????
end?loop;
???????O_str?:
=?v_str;
???????
???????
???????
--?Error
end;


結果:,7,9,10,3,

轉載于:https://www.cnblogs.com/fyonline/archive/2009/08/26/1554178.html

總結

以上是生活随笔為你收集整理的根据消费定额生成菜单的算法(原创)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。