Oracle程序开发范例宝典
童心同萌
有一头牛,每天默默耕耘,七年后,他还在默默耕坛,这是一头自己吃草让别人喝奶的高产奶牛。。。
展开
-
Oracle计算两个整数的和与这两个整数差的商
set serveroutput onDECLARE a int := 100; b int := 200; c NUMBER;BEGIN c := ( a + b ) / ( a - b ); dbms_output.put_line ( c );EXCEPTION WHEN zero_divide THEN dbms_outp...原创 2019-01-24 15:42:10 · 1022 阅读 · 0 评论 -
Oracle中while语句的使用
set serveroutput ondeclare num int; total int;begin num:=0; total:=0; while num<5 loop num:=num+1; total:=total+num; end loop; dbms_output.put_line('前5个自然数的和是'||total);en...原创 2019-02-13 12:18:39 · 2962 阅读 · 0 评论 -
Oracle中loop语句的使用
set serveroutput ondeclare num int; total int;begin num:=0; total:=0; loop num:=num+1; total:=total+num; exit when num=5; end loop; dbms_output.put_line('前5个自然数的和是'||tota...原创 2019-02-13 12:11:23 · 1286 阅读 · 0 评论 -
Oracle中case语句的使用
set serveroutput ondeclare a varchar2(10); b int;begin a:='qwer'; b:=length(a); case b when 1 then dbms_output.put_line('字符串a的长度为1'); when 2 then dbms_output.put_li...原创 2019-02-13 11:49:02 · 1883 阅读 · 0 评论 -
Oracle中if...then...elsif的使用
set serveroutput ondeclare a varchar2(10); b varchar2(20);begin a:='qwer'; b:='qwer'; if length(a)>length(b) then dbms_output.put_line('字符串"'||a||'"的长度比字符串"'||b||'"的长度大'); elsif...原创 2019-02-13 11:19:56 · 9634 阅读 · 0 评论 -
Oracle中if...then...else的使用
set serveroutput ondeclare a varchar2(10); b varchar2(20);begin a:='qwer'; b:='qwerqwer'; if length(a)>length(b) then dbms_output.put_line('字符串"'||a||'"的长度比字符串"'||b||'"的长度大'); e...原创 2019-02-13 11:10:01 · 3841 阅读 · 0 评论 -
Oracle中if...then的使用
set serveroutput ondeclare a varchar2(10); b varchar2(20);begin a:='asdfasdf'; b:='asdf'; if length(a)>length(b) then dbms_output.put_line('字符串"'||a||'"的长度比字符串"'||b||'"的长度大'); e...原创 2019-02-13 11:01:00 · 6146 阅读 · 0 评论 -
Oracle中record变量的使用
--声明record变量之前必须先定义set serveroutput ondeclare type mytype is record ( a trp_advp_copy.groupname%type, b trp_advp_copy.projectname%type ); c mytype;begin select groupname,projectnam...原创 2019-01-25 17:17:31 · 830 阅读 · 0 评论 -
Oracle中%rowtype变量的使用
--%rowtype表示与表一整行的数据类型相同,查询时必须select * 才可以将查询结果存入变量set serveroutput ondeclare a trp_advp_copy%rowtype;begin select * into a from trp_advp_copy where id = 942371; dbms_output.put_line(a.group......原创 2019-01-25 17:03:03 · 886 阅读 · 0 评论 -
Oracle中%type变量的使用
--%type表示与指定列的数据类型相同set serveroutput ondeclare a trp_advp_copy.groupname%type; b trp_advp_copy.projectname%type;begin select groupname,projectname into a,b from trp_advp_copy where id = 9423...原创 2019-01-25 16:49:14 · 880 阅读 · 0 评论 -
Oracle将查询结果存储到变量中
set serveroutput ondeclare a varchar2(10); b varchar2(20);begin select groupname,projectname into a,b from trp_advp_copy where id = 942371; dbms_output.put_line(a||'---'||b);end;原创 2019-01-25 16:31:54 · 5571 阅读 · 0 评论 -
Oracle根据结果集创建新表
--复制整表CREATE TABLE trp_advp_copy AS SELECT *FROM trp_advp--复制表的部分列CREATE TABLE trp_advp_copy AS SELECT id, advpnumber, groupname, projectname FROM trp_advp--复制表的...原创 2019-01-25 16:12:25 · 2730 阅读 · 0 评论 -
Oracle中for语句的使用
set serveroutput ondeclare total int;begin total:=0; for i in reverse 1..10 loop if mod(i,2)=0 then dbms_output.put_line('total:='||total||'+'||i); total:=total+i; end ...原创 2019-02-13 12:37:05 · 3679 阅读 · 0 评论