Oracle SQL脚本学习记录一

set serveroutput on
declare
v_age number;
begin
v_age:=12;
v_age:=v_age/0;
exception
when ZERO_DIVIDE then
dbms_output.put_line(‘divde by zero’);
end;
declare
v_name varchar2(10);
begin
v_name:=’wmsjhappy’;
DBMS_OUTPUT.PUT_LINE(v_name);
end;
/
declare 
begin 
select * from tb_personresumes;
end;
/
——————————————————————————————————————-
create table protest (name varchar2(10),pass varchar2(10));
insert into protest values (‘wmsjhappy’,’20070701′);
select * from protest;
commit;
CREATE or replace procedure sp_proUserInfo(sApName varchar2,sApPass varchar2) is
begin
update protest set name=sapname,pass=sappass;
end;
commit;
call sp_proUserInfo(‘diwaycom’,'radius’);
exec sp_proUserInfo(‘diway’,'radius’);
select * from protest;
commit;
select * from protest;
DECLARE
CURSOR c1 IS
SELECT prod_id, cust_id, time_id, amount_sold 
FROM sales
WHERE amount_sold > 100;
c1_rec c1%rowtype;
l_cust_first_name customers.cust_first_name%TYPE;
l_cust_lasT_name customers.cust_last_name%TYPE;
BEGIN
FOR c1_rec IN c1
LOOP
– Query customer details
SELECT cust_first_name, cust_last_name
INTO l_cust_first_name, l_cust_last_name
FROM customers
WHERE cust_id=c1_rec.cust_id;
–
– Insert in to target table
–
INSERT INTO top_sales_customers (
prod_id, cust_id, time_id, cust_first_name, cust_last_name,amount_sold
)
VALUES
(
c1_rec.prod_id,
c1_rec.cust_id,
c1_rec.time_id,
l_cust_first_name,
l_cust_last_name,
c1_rec.amount_sold
);
END LOOP;
COMMIT;
END;
create table protest(name varchar2(10),pass varchar2(10));
set serveroutput on;
declare 
  cursor get_date is
  select name,pass from protest;
begin
  for i in get_date
  loop
    DBMS_OUTPUT.PUT_LINE(‘name: ‘||i.name||’   pass: ‘||i.pass);
  end loop;
end;
/
L> declare                                                                                        cursor t is                                                                                    select susername from tbl_usersagentgoogle;                                                    tname t%rowtype;                                                                               begin                                                                                              for tname in t                                                                                 loop                                                                                           select susername into tname from tbl_usersagentgoogle;                                         end loop;                                                                                  end;                                                                                          /


你可能感兴趣的:(Oracle SQL脚本学习记录一)