Oracle SQL 스 크 립 트 학습 기록 5
5152 단어 sql
declare
x number;
begin
x:=0;
loop
x:=x+1;
if x>=3 then
exit;
end if;
DBMS_OUTPUT.PUT_LINE(‘ :x=’||x);
end loop;
DBMS_OUTPUT.PUT_LINE(‘ :x’||x);
end;
/
—-while
declare
x number;
begin
x:=0;
while x<=3 loop
x:=x+1;
DBMS_OUTPUT.PUT_LINE(‘ :x=’||x);
end loop;
DBMS_OUTPUT.PUT_LINE(‘out:x=’||x);
end ;
/
—-for declare
begin
for i in 1..5 loop
DBMS_OUTPUT.PUT_LINE(‘i=’||i);
end loop;
DBMS_OUTPUT.PUT_LINE(‘end of for loop’);
begin
for i in reverse 1..5 loop
DBMS_OUTPUT.PUT_LINE(‘i=’||i);
end loop;
DBMS_OUTPUT.PUT_LINE(‘end of for loop’);
declare
test varchar(12);
begin
select name into test from deptement where id=’tt’;
DBMS_OUTPUT.PUT_LINE(test);
exception
when NO_DATA_FONUD THEN
DBMS_OUTPUT.PUT_LINE(‘NOTHINGS’);
END;
DECLARE
tname varchar2(10);
e exception;
begin
select name into tname from deptment where id=’01′;
if tname<>’B ’ then
raise e;//
end if ;
DBMS_OUTPUT.PUT_LINE(tname);
exception
where e then
DBMS_OUTPUT.PUT_LINE(‘false is not b’);\
end ;
/
—
declare
type myrecord is RECORD
id varchar2(10),
name varchar2(10);
real_record myrecord;—
begin
select eid,ename into real_record from emp where eid=’001′;
DBMS_OUTPUT.PUT_LINE(real_record.id||’,'||real_record.name);
end;
/
declare
type myrecord is RECORD
id emp.id%type,
name varchar2(10);
real_record myrecord;—
begin
select eid,ename into real_record from emp where eid=’001′;
DBMS_OUTPUT.PUT_LINE(real_record.id||’,'||real_record.name);
end;
/
declare
myrec emp%ROWTYPE;
begin
select * into myrec from emp where eid=’001′;
DBMS_OUTPUT.PUT_LINE(myrec.eid||’,'myrec.ename);
end;
/
—
declare
CURSOR mycur is
select * from books ;
myrecord books%rowtype;
begin
open mycur –
fetch mycur into myrecord; –
while mycur%FOUND then loop
DBMS_OUTPUT.PUT_LINE(myrecord.books_id||’ , ‘||myrecord.books_name);
fetch mycur into myrecord;
end loop;
close mycur;
end ;
/
—–
declare
cursor cur_para(id varchar2) is
select books_name from books where books_id=id;
t_name books.books_name%type;
begin
open cur_para(’0001′);
loop
fetch cur_para into t_name;
exit when cur_para%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(t_name);
end loop;
close cur_para;
end ;
/
declare
cursor cur_para(id varchar2) is
select books_name from books where books_id=id;
——for open close
begin
DBMS_OUTPUT.PUT_LINE(‘***********RESLUES***********’);
FOR cur in cur_para(’0001′) loop
DBMS_OUTPUT.PUT_LINE(cur.books_name);
end loop;
end ;
/
declare
t_name books.books_name%type;
cursor cur(id varchar2) is
select books_name from books where books_id=id;
begin
if cur%isopen then
DBMS_OUTPUT.PUT_LINE(‘cur is opened’);
else
open cur(’0003′);
end if;
fetch cur into t_name;
DBMS_OUTPUT.PUT_LINE(‘cur is closed’||t_name);
close cur;
end ;
/
————rowcount use method
declare
t_name varchar2(10);
cursor mycur is
select name from deptment;
begin
open mycur;
loop;
fetch mycur into t_name;
exit when mycur%notfound or mycur%notfound is null ;
DBMS_OUTPUT.put_line(‘mycur is rowcount is’||mycur%ROWCOUNT);
end loop;
close mycur;
end ;
/
———– select for update
declare
cursor cur is
select name from deptment for update;
text varchar2(10);
open cur;
fetch cur into text;
while cur%rowcount loop
update deptment set name=name||’t’ where CURRENT OF cur;
fetch cur into text;
end loop;
close cur;
end ;
/
——————————–
begin
for cur in(select name from deptment) loop
dbms_output.put_line(cur.name);
end loop;
end;
/
—————————-
create or replase proceduer myproc(id in varchar2)—
is
name varchar2(10);——–
begin
select books_name into name from books where books_id=id;
DBMS_OUTPUT.PUT_LINE(name);
end ;
end myproc;
/
show errors;—
show errors procedure myproc
——————–
declare
tid varchar2(10);
begin
tid:=’0001′;
myproc(tid)l
end;
/
——————-
begin
myproc(’0001′);
end;
/
execute myproc(’0001′); —- begin executre
———–
create or replace trigger del_deptid
after delete on deptment —
for each row
begin
delete from emp where id:=old.id;
end del_deptid;
/
–alert
create or replace trigger insert_deptid
after insert on deptment —
for each row
begin
insert into emp(eid,ename,id) valus(’121′,’wqwe’,:new.id);
end insert_deptid;
/
create or replace trigger update_dept
after update on deptment
for each row
begin
update emp set id=:new.id where id=:oid.id;
end;
/
create or replace trigger books_delete
after delete on books
for each row —-
begin
if ld.books_id =’0001′ then
RAISE_APPLICATION_ERROR(-20000,’NOT ALLOW DELELE’); — 20000—20999
end if;
end;
/
—————- DBMS_OUTPUT.PUT_LINE(); rollback commit
create table mylog(curr_user varchar2(100),curr_date date,act char(1));
create or replace trigger dml_aa
after insert or delete or update
begin
if inserting then
insert into mylog values(user,sysdate,’1′);
elsif deleting then
insert into mylog values(user,sysdate,’d');
else
insert into mylog values(user,sysdate,’u');
end if;
end;
/
CREATE OR REPLACE TRIGGER set_no
before insert on auto
for each row
declare
sn number(5);
begin
select myseq.nextval into sn from dual;
:NEW.a:=sn;
end ;
/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
깊이 중첩된 객체를 정확히 일치 검색 - PostgreSQL목차 * 🚀 * 🎯 * 🏁 * 🙏 JSON 객체 예시 따라서 우리의 현재 목표는 "고용주"사용자가 입력한 검색어(이 경우에는 '요리')를 얻고 이 용어와 정확히 일치하는 모든 사용자 프로필을 찾는 것입니다. 즐거운 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.