/*查询*/
declare v_num menu.name%type;
begin
select name
into v_num from menu where mid=&no;
dbms_output.put_line(v_num);
end;
/* 别名*/
select mid as "编号",name as "名称" from menu
declare v_abs number(6,2);
begin
v_abs:=abs(&no);
dbms_output.put_line('绝对值:'||v_abs);
end;
/* 加法 */
declare
v_num1 number(6,2);
v_num2 number(6,2);
v_sum number(6,2);
begin
v_num1:=abs(&no1);
v_num2:=abs(&no2);
v_sum:=v_num1+v_num2;
dbms_output.put_line('总值:'||v_sum);
end;
/* 精通oracle编程 */
declare
v_num1 int;
v_num2 int;
begin
v_num1:=abs(&no1);
v_num2:=abs(&no2);
if nullif(v_num1,v_num2) is null then
dbms_output.put_line('二者相等');
else
dbms_output.put_line('二者不等');
end if;
end;
/*创建Type,感觉有点类似 C#中的结构体*/
Create type demo_001 as object
(
id varchar2(16),
name varchar(50)
);
create table demot_001 of demo_001;
insert into demot_001 values('user1','张三')
select * from demot_001
/* 使用记录变量接受数据 page /130 */
declare type menu_record_type is record
(
mid menu.mid%type,
name menu.name%type
);
menu_record1 menu_record_type;
begin
select mid,name into menu_record1 from menu where mid=&no;
dbms_output.put_line('编号 '||menu_record1.mid);
dbms_output.put_line('姓名 '||menu_record1.name);
end;
/* oracle 事务 */
declare
v_mid menu.mid%type:=&Id;
v_name menu.name%type:='&Name';
begin
update menu set name=v_name where mid=v_mid;
dbms_output.put_line('成功');
commit;
exception
when others then
rollback;
end;
/* oracle 游标 page 191 of 488 */
declare cursor banks_cursor is
select bankid,name from banks where setid=2;
v_bankid banks.bankid%type;
v_name banks.name%type;
begin
open banks_cursor;
loop
fetch banks_cursor into v_bankid,v_name;
exit when banks_cursor%notfound;
dbms_output.put_line('记录:'||v_bankid||':'||v_name);
end loop;
close banks_cursor;
end;
/*存储过程返回数据集*/
CREATE OR REPLACE PROCEDURE Sp_menu (cv_results IN OUT SYS_REFCURSOR)
IS
BEGIN
OPEN cv_results FOR
select mid,name from menu;
return;
END;
/*创建表空间*/
CREATE TABLESPACE Demo DATAFILE 'C:/oracle/product/10.1.0/oradata/TANZ10G/Demo.DBF'
SIZE 100M
AUTOEXTEND ON NEXT 500K MAXSIZE UNLIMITED; //自动面的表示增加
/*创建用户*/
Create user demouser identified by 12345
default tablespace demo
temporary tablespace temp;