日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Oracle 調(diào)用存儲(chǔ)過(guò)程執(zhí)行CRUD的小DEMO

系統(tǒng) 2074 0

-----------------------------修改(表名,主鍵ID,要修改的列)

create or replace procedure pro_code_edit(p_tbname in varchar2,p_ct_id in varchar2,p_codename in varchar2) as
? ?p_str varchar2(400);
begin
? p_str := 'update '||p_tbname||' set codename = '''||p_codeName||''' where ct_id = '''||p_ct_id||'''';
? execute immediate p_str;
end;

--查詢所有記錄,直接返回游標(biāo) 在調(diào)用處做下一步處理

create or replace procedure pro_code_queryall(p_tbname in varchar2,p_list out sys_refcursor ) as
begin
? ? open p_list for 'select * from '||p_tbname||'';
end;

--查詢單條記錄(表名,主鍵,要查詢的字段)

create or replace procedure pro_code_queryone(p_tbname in varchar2,p_ct_id in varchar2,
? ? ? ? ? ? ? ? ?p_code out varchar2,p_codename out varchar2,p_fathercode out varchar2) as
? ? ?v_code varchar2(40);
? ? ?v_codename varchar2(40);
? ? ?v_fathercode varchar2(40);
? ? ?v_str varchar2(400);
begin
? ? ?v_str:='select code,codename,fathercode ?from '||p_tbname||' where ct_id = :p' ;
? ? ?execute immediate v_str into v_code,v_codename,v_fathercode ?using p_ct_id ;
? ? ?p_code:=v_code;
? ? ?p_codename:=v_codename;
? ? p_fathercode:=v_fathercode;
end;

--刪除記錄(表名,主鍵值)

--這里的主鍵名稱是通過(guò)命令查詢出來(lái)的

create or replace procedure pro_code_remove(p_tbname in varchar2,p_ct_id in varchar2) as
? ? v_str varchar2(400);
? ? v_con_name varchar2(40);
? ? v_pid varchar2(40):=trim(p_ct_id);
? ? v_pk_column_name varchar2(40);
? ? v_tbname varchar2(400):=upper(trim(p_tbname));
begin
? ? select constraint_name into v_con_name from all_constraints where owner=upper('daily') and constraint_type = 'P'
? ? and table_name=v_tbname;
? ? select column_name into v_pk_column_name from all_cons_columns where owner=upper('daily') and table_name=v_tbname
? ? and constraint_name = v_con_name;
? ?v_str :='delete ?from doorkind where '||v_pk_column_name||' = :p ';
? ?execute immediate v_str using v_pid;
end;


--保存記錄(在這里由于數(shù)據(jù)設(shè)計(jì)的特殊之處,主鍵是按照規(guī)則自動(dòng)生成的)

create or replace procedure pro_code_save(p_tbname in varchar2,p_codename in varchar2) as
? ? ?v_codetype varchar2(100);
? ? ?p_id varchar2(400);
? ? ?p_str varchar2(400);
? ? ?v_len number(10);
? ? ?v_left varchar2(100);
? ? ?v_right varchar2(100);
begin
? ? ?v_codetype:=p_tbname;
? ? ?p_str:='select max(ct_id) from '||v_codetype;
? ? ?execute immediate p_str into p_id;
? ? ?dbms_output.put_line(p_id);
? ? ?select codetype,codelength into v_codetype,v_len from codenavigation where upper(codetype) = upper(v_codetype);


? ? ?if p_id is not null then
? ? ? ? v_left := regexp_substr(p_id,'[A-Za-z]+',1,1);
? ? ? ?v_right := regexp_substr(p_id,'[0-9]+',1,1);
? ? ? ?v_right := lpad(v_right + 1,v_len,'0');
? ? ?else
? ? ? ?v_left:=v_codetype;
? ? ? ?v_right := lpad(1,v_len,'0');
? ? ?end if;
? ? ? ?p_id:=v_left||v_right;
? ? ? ?dbms_output.put_line(p_id);


? ? ?p_str:='insert into '||v_codetype||' ?'||' values('''||p_id||''','''||v_right||''','''||p_codeName||''','''||v_left||''')';
? ? ?
? ? ?execute immediate p_str;
? ? ?dbms_output.put_line(p_str);
end;

?

Oracle 調(diào)用存儲(chǔ)過(guò)程執(zhí)行CRUD的小DEMO


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 呼伦贝尔市| 和政县| 元朗区| 黎城县| 措勤县| 溧水县| 外汇| 宜城市| 五家渠市| 碌曲县| 绿春县| 临海市| 肥城市| 多伦县| 公安县| 嘉定区| 比如县| 柳州市| 贡觉县| 岱山县| 荔波县| 天台县| 上蔡县| 岐山县| 冕宁县| 石泉县| 论坛| 阿巴嘎旗| 蒲城县| 达州市| 霞浦县| 鄂州市| 莒南县| 吉林省| 恭城| 新化县| 兴安县| 桃江县| 方正县| 岳阳市| 金堂县|