欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ORACLE应用经验(1)

程序员文章站 2023-11-07 19:52:40
正在看的oracle教程是:oracle应用经验(1)。...
正在看的oracle教程是:oracle应用经验(1)。 jan-1(january) feb-2(february) mar-3(march)
apr-4(april) may-5(may) jun-6(june)
jul-7(july) aug-8(august) sep-9(september)
oct-10(october) nov-11(november) dec-12(december)
********************************************************************
****************************常用设置********************************
---on-log 触发器编写示范
declare
flag varchar2(80):=null;
cou number:=1;
n number;
begin
loop
logon(username,password||@||connect,property_false....);
flag:=get_application_property(datasource);
exit when cou>8 or flag=oracle;
cou:=cou+1;
end loop;
if flagoracle then
set_alert_property(a_1,alert_message_text,
登录失败,请返回重试);
n:=show_alert(a_1);
raise form_trigger_failure; --中断 form
end if;
end;
---对基表执行查询(只对基表)
set_block_property(block_name,default_where,where ......);
go_block(block_name);
execute_query;
***************************************************
变量:
局部变量;
全局变量--------------1.:block.item
2.:parameter.v_name
3.:global.v_name

***************************************************
---同步发生显示
synchronize;
---实施trigger触发
execute_trigger(trigger_name);
---清除模块
clear_block(no_validate); no_validate不生效
--建立警告栏并由警告栏选择
declare
n number;
begin
set_alert_property(alert_name,alert_message_text,message);
n:=show_alert(alert_name);
if n=alert_button1 then
...;
elsif n=alert_button2 then
...;
end if;
end;
---window设置
--运行时最大化,最小化
set_window_property(forms_mdi_window, window_state, maximize|minimize);
--window标题
set_window_property(forms_mdi_window, title,text);
--退出是否为真
set_window_property(forms_mdi_window, remove_on_exit,property_false|true);
---设置系统提示信息等级
:system.message_level:= 5|10|15|20;
---设置item属性
--设置item属性enabled
set_item_property(block_name.item_name,enabled,property_true|false);
--设置item属性navigable
set_item_property(block_name.item_name,navigable,property_true|false);
--设置item属性visual_attribute
set_item_property(block_name.item_name,visual_attribute,vname);
--vname由导航器中(visual_attributes)定义
--设置item属性displayed
set_item_property(block_name.item_name,displayed,true|false);
--设置item属性position
set_item_property(block_name.item_name,position,x,y);
--设置item_size
set_item_property(block_name.item_name,item_size,x,y);
--设置item属性lable
set_item_property(block_name.item_name,label,message)
---设置list item示范
declare
n number;
begin
clear_list(b1.fkfs);
m:=populate_group(fkfs);
populate_list(b1.fkfs,fkfs);
/*
其中fkfs 为 record group ;
*/
end;
---增加list item
add_list_element(list_name, list_index, list_label, list_value);
add_list_element(list_id, list_index, list_label, list_value);
---删除list item项
delete_list_element(list_name, list_index);
delete_list_element(list_id, list_index);
例:
begin
delete_list_element(years,1);
add_list_element(years, 1, 1994, 1994);
end;
---获得list item项的组成
1.获得list item的总和
get_list_element_count(list_id);
get_list_element_count(list_name);
2.获得list item的标签
get_list_element_label(list_id, list_name, list_index);
get_list_element_label(list_name, list_index);

3.获得list item的值
get_list_element_value(list_id, list_index);
get_list_element_value(list_name, list_index);

---设置时间
declare
timer_id timer;
one

[1] [2] [3] 下一页

正在看的oracle教程是:oracle应用经验(1)。_minute number(5) := 60000;
begin
timer_id := create_timer(emp_timer, one_minute, repeat|no_repeat);
end;
---产生一个editer框
declare
ed_id editor;
status boolean;
begin
ed_id:=find_editor(edit_name); ---由edit_name导航器定义

if not id_null(ed_id) then
show_editor(ed_id, null, :block_name.item_name, status);
else
message(editor "happy_edit_window" not found);
raise form_trigger_failure;
end if;
end;
----产生一个lov框
declare
lv_id lov;
status boolean;
begin
lv_id := find_lov(lov_name); ---lov_name 由导航器定义
-- if id_null(lv_id) then
-- lv_id := find_lov(lov_name1); ---lov_name1 由导航器定义
-- end if;
status := show_lov(lv_id,10,20);
end;
---定义一个exception例外
declare
err_1 exception;
begin
if ... then
raise err-1;
end if;
exception
when err_1 then
....
end;
---设置应用特性(光标类型)
set_application_property(cursor_style,
crosshair|busy|help|default|insertion);

***********************************************************************
**********************************函数*********************************
---把字符串的字符变成全大写(upper)全小写(lower)第一个字母大写(initcap)
upper|lower|initcap(string)
---在文件的左(lpad)右(rpad)粘贴字符
lpad|rpad(string,length,set) "length"为总字符长"set"为粘贴字符
---在文件的左(ltrim)右(rtrim)删除字符
ltrim|rtrim(srting,set) "set"为待删除字符
---找出字符集在字符串中的位置
instr(string,set,n,m) 从string中找出set从n位起第m个
---数的绝对值
abs(value)
---mod模
mod(value,除数) 返回除数除value的余数常用判断value是否为整数
---把value从n位四舍五入round 或从n位截断trunc
round|trunc(value,n)
---返回value的符号
sign(value)

---列表的最大值
greatest(n1,n1...);
列表的最小值
least(n1,n1...);
---返回小于或等于数的最大整数
floor(value) floor(1.3)=1 floor(-1.3)=-2
---返回大于或等于数的最小整数
ceil(value) cell (1.3)=2 cell (-1.3)=-1

---取字符串长度
substr(string,start,number) number为string长度,start为string起点

---decode函数,多重(if,then,else)
decode(value,if1,then1,if2,then2,.....,else)
---判断value是否为空(空值替换)
nvl(ualue,wkfhz) wkfhz是为空返回值,不为空则为原值
---字段长度
length(:block_name.item_id)
---返回字符串的第一(最左)个字符的ascii值
ascii(string)
---多行value的 (作用于多行)
avg(value)平均值
count(value)行数
max(value)最大值
min(value)最小值
sum(value)和
---字符转换
translate(string,待转字符,转换字符);
如 teanslate(aaabbb,ab,ba) 返回bbbaaa

---比较单行中多个列的值获得最大(greatest最小(least)
greatest|least(列名,列名,...)
---按表达式或位置排序
order by 表达式or位置 asc|desc asc升,desc降 默认asc
***********************************************************************
***********************************************************************
---游标的属性
(1) %isopen 打开属性 布尔型 打开为true
判断光标是否打开如未打开则打开光标
if not(corsor_name%isopen) then
open corsor_name;
end if;
fetch corsor_name into ...
(2) %notfound 布尔型 最近一次fetch返回无结果 则为true
open corsor_name;
loop
fetch corsor_name into ...
exit when corsor_naem%notfound;
end loop;
(3) %found 布尔型 最近一次fetch返回无结果 则为false
open corsor_name;

while corsor_name%found loop
......
fetch corsor_name into ...
end loop;
close corsor_name;
(4) %rowcount numver型 为游标取出的行数
open corsor_name;
loop
fetch corsor_name into ...
exit when corsor_name%rowcount>5;
......
end loop;
close corsor_name;

---循环语句
(1)基本循环
loop
.....
exit while; 如(exit when x>100)
end loop;
(2)while循环
while 如( when x>100) loop

上一页  [1] [2] [3] 下一页

正在看的oracle教程是:oracle应用经验(1)。 .....
end loop;
(3)数值型for循环 x为计数器
for x in (第减值) y..z loop
.....
end loop;
(4)游标for循环


---exception(例外)在最近的begin和end之间
exception
语法1 当没有数据找到时
when no_data_found then
语法2 当发生任何错误时
when others then
语法3 当发现多行时
when too_many_rows then
语法4 当字符向数字转换失败时
when invalid_number then
语法5 当被零除时
when zero_divide then
语法6 当向唯一索引中插入重复数据时
when dup_val_on_index then
语法7 当非法游标操作时
when invalid_cursor then
语法8 当数字的,数据转换,截字符串或强制性的错误时
when value_error then
**************************************************************************
**************************************************************************
--常用text_io
delcare
out_file text_io.file_type;
begin
out_file:=text_io.fopen(prn,w);
text_io.new_line(out_file, );
text_io.put_line(out_file, )
text_io.fclose(out_file);
end;
---文本输入输出
text_io
text_io package
text_io fclose
text_io.file_type
text_io.fopen
text_io.is_open
text_io.get_line
text_io.new_line
text_io.put
text_io.putf
text_io.put_line
using text_io constructs
----------------------------
declare
out_file text_io.file_type;
l varchar2(100);
l1 varchar2(100);
l2 varchar2(100);
begin
out_file :=text_io.fopen(c:\ll\login.txt,r);
if text_io.is_open(out_file) then
text_io.get_line(out_file,l);
text_io.get_line(out_file,l1);
text_io.get_line(out_file,l2);
else
null;
end if;
end;
---清除全局变量
erase(global.var_name);
---隐藏window,view,menu
hide_window|view|menu(window|view|menu_name);
--- 增加参数add_parameter
declare
pl_id paramlist;
begin
pl_id:=get_parameter_list(tempdata);
if not id_null(pl_id) then
destroy_parameter_list(pl_id);
end if;
pl_id:=create_parameter_list(tempdata);
add_parameter(pl_id,emp_query,data_parameter,emp_recs);
run_product(reports,empreport,synchronous,runtime,
filesystem,pl_id,null);
end;
---
declare
largs ole2.list_type;
begin
word.happ:=ole2.create_obj(word.basic);
largs:=ole2.create_arglist;
ole2.add_arg(largs,:ole.word_doc);
ole2.invoke(word.happ,fileopen,largs);
ole2.destroy_arglist(largs);
end;
***********************删除重复记录**************
delete from emp e
where e.rowid >
(select min(f.rowid) from emp f
4 where f.empno=e.empno);

上一页  [1] [2] [3]