--绝对值,取余,判断数值正负函数
select abs(100),abs(-100),abs('100') from dual;
select mod(100,10),mod(100,0) ,mod(34,7) from dual;
select sign(-9),sign(10) from dual;
--四舍五入截取函数
select round(98.36,1) from dual;
select trunc(23562.3,-4) ,trunc(23532.34634,4) from dual;
insert into productinfo(productid,productname,productprice,quantity) values('024004001','鞋子',22.3,10);
set serveroutput on;
--记录类型
declare
type product_rec is record (
v_productid productinfo.productid%type,
v_productname varchar2(20),
v_productprice number(8,2)
);
v_product product_rec;
v_product2 productinfo%rowtype;
begin
select productid,productname,productprice into v_product from productinfo where productid='024004001';
select * into v_product2 from productinfo where productid='024004001';
dbms_output.put_line(v_product2);
exception
when no_data_found then dbms_output.put_line('未找到数据');
when too_many_rows then dbms_output.put_line('不只一行');
when others then dbms_output.put_line('其他异常导致的');
end;
--索引表类型
declare
type t1 is table of productinfo%rowtype index by binary_integer;
type t2 is table of productinfo.productname%type index by varchar(10);
v_t1 t1;
v_t2 t2;
begin
v_t2(0) := '正确';
v_t2(1) := '错误';
v_t2('hello'):= 'hello';
select * into v_t1(1) from productinfo where productid='024004001';
dbms_output.put_line('v_t1(1):'||v_t1(1).productname);
dbms_output.put_line('v_t2(1):'||v_t2(1));
dbms_output.put_line('v_t2(0):'||v_t2(0));
dbms_output.put_line('v_t2(hello):'|| v_t2('hello'));
end;
/
--varray变长数组
declare
type varr is varray(100) of varchar(10) not null;
v_array varr := varr('a','b','c','hello');
begin
v_array(2):='sdfsdf';
dbms_output.put_line(v_array(2));
dbms_output.put_line(v_array(1));
end;
/
declare
v_price number(8,2):=1.4;
begin
if v_price > 12 then dbms_output.put_line('big than 12');
elsif v_price <10 then dbms_output.put_line('less than 12');
end if;
case v_price
when 2 then dbms_output.put_line('2');
when 1.4 then dbms_output.put_line('1.4');
--when v_price<10 then dbms_output.put_line('s')
else dbms_output.put_line('no');
end case;
end;
/
--loop while-loop
declare
v_price number(8,2):=1.4;
begin
<<basic_loop>>
loop
v_price := v_price+1;
dbms_output.put_line('basic'||v_price);
/** if v_price > 210 then
exit basic_loop;
end if;**/
exit basic_loop when v_price > 210;
end loop;
/****/
<<while_loop>>
while v_price<410
loop
v_price:=v_price+1;
dbms_output.put_line('while'||v_price);
end loop;
<<for_loop>>
for i in 1..200
loop
dbms_output.put_line('for'||i);
end loop;
end;
/
--以上是基础,下面是PL/SQL使用DML和DDL
declare
v_category categoryinfo.categoryid%type;
v_categoryinfo categoryinfo%rowtype;
begin
select categoryid into v_category from categoryinfo where categoryinfo.categoryid='f';
exception
when no_data_found then
dbms_output.put_line('没有对应的产品类型编号,将添加编号');
insert into categoryinfo(categoryid,categoryname) values('f','食物');
commit;
select * into v_categoryinfo from categoryinfo where categoryinfo.categoryid='f';
dbms_output.put_line(v_categoryinfo.categoryid||','||v_categoryinfo.categoryname);
when too_many_rows then
dbms_output.put_line('不止一条记录被发现');
end;
/
declare
v_ddl varchar(200);
begin
v_ddl:='
create table testtable(
id varchar2(100) primary key not null
)';
execute immediate v_ddl;
end;
/
--查询预定义异常
select * from dba_source where name='STANDARD' and text like '%EXCEPTION_INIT%';
--自定义异常
declare
v_char number(8,0):=9.9;
myException Exception;
pragma exception_init(myException,-11111);
begin
/** **/
if v_char=10 then raise myException;
end if;
exception
when myException then dbms_output.put_line('myException raise');
end;
drop function testfun;
create function testfun
return number
as
v_count number(8,0);
begin
select count(*) into v_count from categoryinfo;
return v_count;
end;
select testfun() from dual;
分享到:
相关推荐
这本书深入浅出地介绍了Oracle数据库中最重要的编程语言——PL/SQL,帮助读者掌握在Oracle 10g环境中进行高效、安全的数据库编程技巧。 PL/SQL(Procedural Language/Structured Query Language)是Oracle数据库...
学习Oracle 8 PL/SQL程序设计,你需要掌握以下几个关键知识点: 1. **基本语法和数据类型**:了解PL/SQL的基本结构,包括声明变量、常量、游标、表类型等,并熟悉各种内置数据类型,如NUMBER、VARCHAR2、DATE等。 ...
报告——PL/SQL Developer提供内置的报告功能,您可以根据程序数据或Oracle字典运行报告。PL/SQL Developer本身提供了大量标准报告,而且您还可以方便的创建自定义报告。自定义报告将被保存在报告文件中,进而包含在...
<br>报告——PL/SQL Developer提供内置的报告功能,您可以根据程序数据或Oracle字典运行报告。PL/SQL Developer本身提供了大量标准报告,而且您还可以方便的创建自定义报告。自定义报告将被保存在报告文件中,...
在"精通Oracle10g PL/SQL编程"这本书中,读者可以期待学习到以下关键知识点: 1. **PL/SQL基础**:了解PL/SQL的基本结构,包括声明变量、常量、游标、异常处理和控制流结构(如IF-THEN-ELSE,WHILE循环,FOR循环)...
在本次实验中,我们将重点学习PL/SQL的基本语法、控制结构、复合数据类型以及异常处理技术。 首先,PL/SQL块结构是PL/SQL程序的基础,包括声明部分(DECLARE)、执行部分(BEGIN...END)和异常处理部分(EXCEPTION...
<br>报告——PL/SQL Developer提供内置的报告功能,您可以根据程序数据或Oracle字典运行报告。PL/SQL Developer本身提供了大量标准报告,而且您还可以方便的创建自定义报告。自定义报告将被保存在报告文件中,...
《Introduction to Oracle SQL and PL/SQL》是一本专为初学者设计的教程,全面涵盖了Oracle数据库管理系统中的核心语言——SQL(结构化查询语言)和PL/SQL(过程化语言/SQL)。这本书分为两卷,旨在帮助读者从基础到...
原书名:Oracle 9i Java Programming <br>Oracle 9i Java程序设计——使用PL/SQL和Java的解决方案 <br>【原出版社】 Wrox Press 【作 者】Bjarki Holm,John Carnell等 【译 者】 康博 【丛 ...
然而,当用户在使用Oracle客户端进行PL/SQL开发时,经常遇到一个棘手的问题——中文乱码。这个问题通常出现在查询结果、日志输出或者交互式输入时,给数据库操作带来不便。本文将深入探讨这个问题,并提供解决方案。...
PL/SQLDeveloper是一种集成的开发环境,专门用于开发、测试、调试和优化OraclePL/SQL存储程序单元,比如触发器等。PL/SQLDeveloper功能十分全面,大大缩短了程序员的开发周期。强大的PL/SQL编辑器,完善的Debugger...
为了辅助学习,你可以参考官方的PL/SQL用户指南和参考文档,以及《应用开发者指南——基础》和SQL参考,这些资源提供了详细的说明和实例。此外,Google、AskTom、Metalink、OraFAQ和DBAzone等在线社区也是获取帮助和...
报告——PL/SQL Developer提供内置的报告功能,您可以根据程序数据或Oracle字典运行报告。PL/SQL Developer本身提供了大量标准报告,而且您还可以方便的创建自定义报告。自定义报告将被保存在报告文件中,进而包含...
《Oracle PL/SQL Packages and Types Reference》是一本针对Oracle数据库编程的重要参考资料,主要涵盖了PL/SQL包和类型的详细信息。这本书对于那些具有英文阅读能力的开发者来说,是开发过程中的重要工具,能够帮助...
这些任务——编辑、编译、纠正、测试、调试、优化和查询——都可以在不离开 PL/SQL Developer IDE 的情况下被完成。此外,PL/SQL Developer 还提供了其他几个能在每天的PL/SQL 开发中提供帮助的工具。 注册有图示,...
### PL/SQL手册——Oracle 10g #### 概述 PL/SQL(Procedural Language for SQL)是Oracle数据库的一种内置编程语言,用于增强SQL的功能并支持更复杂的业务逻辑处理。它结合了SQL的数据操作能力和过程化的编程结构...
<br>报告——PL/SQL Developer提供内置的报告功能,您可以根据程序数据或Oracle字典运行报告。PL/SQL Developer本身提供了大量标准报告,而且您还可以方便的创建自定义报告。自定义报告将被保存在报告文件中,...
Oracle Database 11g PL/SQL程序设计 ★第二部分(part2)★ ——※ 注意:该电子书99.4M,分为2个压缩包, 需要将全部2个压缩包下载才能解压缩,单个部分无法解压。 此为第2个包,另外1个包以及源代码包可通过本人...