상세 컨텐츠

본문 제목

[오라클] 4월21 연습

카테고리 없음

by esoesmio 2023. 4. 21. 20:48

본문

create table employee
(
    eno   number,
    ename varchar2(10)
);
insert into employee
values (1, '김은석');
insert into employee
values (2, '김지혜');
insert into employee
values (3, '조지');
insert into employee
values (4, '아놀드');
insert into employee
values (5, '파마');


select *
from employee;

declare
    type esam is record
                 (
                     eno   number,
                     ename varchar2(10)


                 );
    erec esam;
begin
    erec.eno := 7;
    erec.ename := '김동주';
    DBMS_OUTPUT.PUT_LINE(erec.eno);
    DBMS_OUTPUT.PUT_LINE(erec.ename);

    insert into employee values erec;
end;
/



DECLARE
    type eesample is record
                     (
                         eno   number,
                         ename varchar2(10)

                     );
    ess eesample;

begin
    ess.eno := 8;
    ess.ename := 'geiss';

    DBMS_OUTPUT.PUT_LINE(ess.eno);
    DBMS_OUTPUT.PUT_LINE(ess.ename);

    insert into employee values ess;


end;
/


declare
    type esample is record (eno employee.eno%type, ename employee.ename%type);
    ess esample;

begin
    ess.eno := 9;
    ess.ename = '가마니';
    DBMS_OUTPUT.PUT_LINE(ess.eno);
    DBMS_OUTPUT.PUT_LINE(ess.ename);
    insert into employee values ess;
end;


declare
    type esample is record
                    (
                        eno   employee.eno%type,
                        ename employee.ename%type
                    );
    ess esample;
begin
    ess.eno := 15;
    ess.ename := 'gaing';

    DBMS_OUTPUT.PUT_LINE(ess.eno);
    DBMS_OUTPUT.PUT_LINE(ess.ename);
    insert into employee values ess;
end;

select *
from employee;

declare
    type esample is record
                    (
                        eno   employee.eno%type,
                        ename employee.ename%type
                    );

    ess esample;
begin
    ess.eno := 15516;
    ess.ename := 'halmoni';

    DBMS_OUTPUT.PUT_LINE(ess.eno);
    DBMS_OUTPUT.PUT_LINE(ess.ename);
    insert into employee values ess;
end;

select *
from employee;

declare
    type esample is record
                    (
                        eno   employee.eno%type,
                        ename employee.ename%type
                    );
    ess esample;
begin
    ess.eno := 155;
    ess.ename := ' galzija';
    insert into employee values ess;
end;

select *
from employee;


declare
    type esample is record
                    (
                        eno   employee.eno%type,
                        ename employee.ename%type
                    );
    ess esample;
begin
    ess.eno := 5115;
    ess.ename := ' hahkil';

    update employee
    set row = ess
    where eno = 155;

end;

declare
    type esample is record (eno employee.eno%type, ename employee.ename%type);

    ess esample;
begin
    ess.eno := 99;
    ess.ename := 'santina';

    update employee
    set row = ess
    where eno = 5115;
end;



create table sss
(
    sno     number,
    sname   varchar2(10),
    sresult number,
    sloc    number
);



-- declare
--     type ssample1 is record(sno sss.sno%type, sname sss.sname%type);
--     type ssample2 is record(sresult sss.sresult%type, sloc sss.sloc%type ,ssample22 ssample1);
--     ss ssample2;
--     begin
--     select st.sno, st.sname, st.stresult, st.sloc
--         into  ss.ssample22.sno, ss.ssample22.sname, ss.sresult, ss.sloc;
-- end;


declare
    type numberarray is table of number
        index by pls_integer;
    num    number := 0;
    numarr numberarray;

begin

    loop
        num := num + 1;
        numarr(num) := num;
        --- 이거 루프 안에서는 왜 안찍힘???
        --- 이거 루프 안에서는 왜 안찍힘???
        --- 이거 루프 안에서는 왜 안찍힘???
        --- 이거 루프 안에서는 왜 안찍힘???
        --- 이거 루프 안에서는 왜 안찍힘???
        --- 이거 루프 안에서는 왜 안찍힘???
        --- 이거 루프 안에서는 왜 안찍힘???
        DBMS_OUTPUT.PUT_LINE(numarr(num));

        exit when num > 5;
    end loop;


end;


declare
    geg number := 4;
begin
    dbms_output.PUT_LINE(geg);

end;

declare
    type numarr is table of number
        index by pls_integer;
    num number := 0;
    arr numarr;

begin
    loop
        num := num + 1;
        arr(num) := num;
        exit when num > 5;
        DBMS_OUTPUT.PUT_LINE(arr(num));
    end loop;
    DBMS_OUTPUT.PUT_LINE(arr(num));


end;


declare
    type numarr is table of number
        index by pls_integer;
    num number := 0;
    arr numarr;

begin

    loop
        num := num + 1;
        arr(num) := num;

        DBMS_OUTPUT.PUT_LINE(arr(num));

        exit when num > 10;
    end loop;

end ;



declare
    type numarr is table of number
        index by pls_integer;
    num number := 0;
    arr numarr;
begin
    loop
        num := num + 1;
        arr(num) := num;
        DBMS_OUTPUT.PUT_LINE(arr(num));
        exit when num > 10;

    end loop;
end;



declare
    type numarr is table of number
        index by pls_integer;
    num number := 0;
    arr numarr;

begin

    loop
        num := num + 1;
        arr(num) := num;
        DBMS_OUTPUT.PUT_LINE(arr(num));
        exit when num > 10;
    end loop;
end;

create table stusample
(
    sno   number,
    sname varchar2(10)
);
select *
from stusample
;
insert into stusample
values (1, '하나만');
insert into stusample
values (2, '두개만');
insert into stusample
values (3, '세개만');
insert into stusample
values (4, '네개만');
insert into stusample
values (5, '섯개만');

select *
from stusample;


declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;

begin

    for strow in curst
        loop

            DBMS_OUTPUT.PUT_LINE(strow.sno);
            DBMS_OUTPUT.PUT_LINE(strow.sname);
        end loop;
end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;

begin
    for strow in curst
        loop
            DBMS_OUTPUT.PUT_LINE(strow.sno);
            DBMS_OUTPUT.PUT_LINE(strow.sname);
        end loop;
end;



declare type stuarr is table of stusample%rowtype index by pls_integer;
    idx number := 1;
    arr stuarr;
begin
    loop
        arr(idx).sno := idx;
        arr(idx).sname := '바나나';


        DBMS_OUTPUT.PUT_LINE(arr.PRIOR(idx));
        idx := idx + 1;

        exit when idx > 10;

    end loop;
end;



declare type stuarr is table of stusample%rowtype index by pls_integer;
    idx number := 1;
    arr stuarr;
begin
    loop
        arr(idx).sno := idx;
        arr(idx).sname := '바보';

        insert into stusample
        values arr(idx);
        DBMS_OUTPUT.PUT_LINE(arr(idx).sno);
        DBMS_OUTPUT.PUT_LINE(arr(idx).sname);
        idx := idx + 1;
        exit when idx > 10;


    end loop;

end ;
/



declare type stuarr is table of stusample%rowtype index by pls_integer;
    idx number := 1;
    arr stuarr;
begin
    loop
        arr(idx).sno := idx;
        arr(idx).sname := '바';
        insert into stusample
        values arr(idx);
        DBMS_OUTPUT.PUT_LINE(arr(idx).sno);
        idx := idx + 1;
        exit when idx > 10;
    end loop;
end;



-- select *
-- from stusample;


declare type stuarr is table of stusample%rowtype index by pls_integer;
    idx number := 1;
    arr stuarr;

begin

    loop
        arr(idx).sno := idx;
        arr(idx).sname := '바나' || idx;

        insert into stusample
        values arr(idx);
        idx := idx + 1;
        exit when idx > 10;


    end loop;
end;



declare
    type sa is record (sno stusample.sno%type, sname stusample.sname%type);
    type stuarray is table of sa
        index by pls_integer;
    idx number := 1;
    arr stuarray;

begin
    loop
        arr(idx).sno := idx;
        arr(idx).sname := 'banana' || idx;
        DBMS_OUTPUT.PUT_LINE(arr(idx).sno);
        DBMS_OUTPUT.PUT_LINE(arr(idx).sname);
        exit when idx > 10;
    end loop;
end;



declare
    type ss is record (sno stusample.sno%type, sname stusample.sname%type);
    type aaaa is table of ss
        index by pls_integer;
    idx number := 1;
    ss  aaaa;

begin
    loop
        ss(idx).sno := idx;
        ss(idx).sname := '바나나' || idx;
        DBMS_OUTPUT.PUT_LINE(ss(idx).sno);
        DBMS_OUTPUT.PUT_LINE(ss(idx).sname);
        idx := idx + 1;
        exit when idx > 10;
    end loop;
end;



declare type ss is record (sno stusample.sno%type, sname stusample.sname%type);
    type stuarray is table of ss
        index by pls_integer
    ;
    idx number := 1;
    arr stuarray;

begin

    loop
        arr(idx).sno := idx;
        arr(idx).sname := '바나' || idx;
        DBMS_OUTPUT.PUT_LINE(arr(idx).sno);
        DBMS_OUTPUT.PUT_LINE(arr(idx).sname);
        idx := idx + 1;

        exit when idx > 10;

    end loop;
end;



declare
    type ss is record (sno stusample.sno%type, sname stusample.sname%type);
    type stuarray is table of ss
        index by pls_integer;
    arr stuarray;
    idx number := 1;

begin

    loop
        arr(idx).sno := idx;
        arr(idx).sname := '바나나' || idx;
        DBMS_OUTPUT.PUT_LINE(arr(idx).sno);
        DBMS_OUTPUT.PUT_LINE(arr(idx).sname);
        exit when idx > 10;
    end loop;
end;
;
declare
    type ss is record (sno stusample.sno%type, sname stusample.sname%type);
    type stuarray is table of ss
        index by pls_integer;
    arr stuarray;
    idx number := 1;
begin
    loop
        arr(idx).sno := idx;
        arr(idx).sname := '바나나';
        DBMS_OUTPUT.PUT_LINE(arr(idx).sno);
        DBMS_OUTPUT.PUT_LINE(arr(idx).sname);

        idx := idx + 1;
        exit when idx > 10;


    end loop;
end;



create table stusample
(
    sno   number,
    sname varchar2(10)
);
select *
from stusample
;
insert into stusample
values (1, '하나만');
insert into stusample
values (2, '두개만');
insert into stusample
values (3, '세개만');
insert into stusample
values (4, '네개만');
insert into stusample
values (5, '섯개만');

select *
from stusample;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
begin
    for strow in curst
        loop
            DBMS_OUTPUT.PUT_LINE(strow.sno);
            DBMS_OUTPUT.PUT_LINE(strow.sname);
        end loop;
end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
begin
    for strow in curst
        loop
            DBMS_OUTPUT.PUT_LINE(strow.sno);
            DBMS_OUTPUT.PUT_LINE(strow.sname);

        end loop;


end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;

begin

    for strow in curst

        loop

            DBMS_OUTPUT.PUT_LINE(strow.sno);
            DBMS_OUTPUT.PUT_LINE(strow.sname);
        end loop;
end;

select *
from stusample;

declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    type haha is record
                 (

                     sno   stusample.sno%type,
                     sname stusample.sname%type
                 );
    hah haha;
begin
    open curst;
    fetch curst into hah;
    DBMS_OUTPUT.PUT_LINE(hah.sno);
    DBMS_OUTPUT.PUT_LINE(hah.sname);
    close curst;
end;

declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;

    type haha is record (sno stusample.sno%type, sname stusample.sname%type);
    ha haha;
begin
    open curst;
    fetch curst into ha;
    DBMS_OUTPUT.PUT_LINE(ha.sno);
    DBMS_OUTPUT.PUT_LINE(ha.sname);

    close curst;

end;


declare
    cursor curst is select sno, sname
                    from stusample;
begin
    for strow in curst
        loop
            DBMS_OUTPUT.PUT_LINE(strow.sno);
            DBMS_OUTPUT.PUT_LINE(strow.sname);
        end loop;

end;


declare
    cursor curst is select sno, sname
                    from stusample;
begin

    for strow in curst
        loop
            DBMS_OUTPUT.PUT_LINE(strow.sno);
            DBMS_OUTPUT.PUT_LINE(strow.sname);


        end loop;
end;


declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    type haha is record (sno stusample.sno%type, sname stusample.sname%type);
    ha haha;

begin
    open curst;
    fetch curst into ha;
    DBMS_OUTPUT.PUT_LINE(ha.sno);
    DBMS_OUTPUT.PUT_LINE(ha.sname);
end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    type haha is record (sno stusample.sno%type, sname stusample.sname%type);
    ha haha;
begin
    open curst;
    fetch curst into ha;
    DBMS_OUTPUT.PUT_LINE(ha.sno);
    DBMS_OUTPUT.PUT_LINE(ha.sname);
    close curst;

end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    strow stusample%rowtype;

begin

    open curst;
    loop
        fetch curst into strow;
        DBMS_OUTPUT.PUT_LINE(strow.sno);
        DBMS_OUTPUT.PUT_LINE(strow.sname);

        exit when curst%notfound;
    end loop;
    close curst;
end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    strow stusample%rowtype;

begin

    open curst;
    loop
        fetch curst into strow;
        DBMS_OUTPUT.PUT_LINE(strow.sno);
        DBMS_OUTPUT.PUT_LINE(strow.sname);
        exit when curst%notfound;
    end loop;
    close curst;


end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    strow stusample%rowtype;
begin
    open curst;
    loop
        fetch curst into strow;
        DBMS_OUTPUT.PUT_LINE(strow.sno);
        DBMS_OUTPUT.PUT_LINE(strow.sname);
        exit when curst%notfound;
    end loop;
end;


declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    strow stusample%rowtype;

begin
    open curst;
    loop
        fetch curst into strow;
        DBMS_OUTPUT.PUT_LINE(strow.sno);
        DBMS_OUTPUT.PUT_LINE(strow.sname);
        exit when curst%notfound;
    end loop;
end;



declare
    cursor curst is select sno, sname
                    from stusample
                    where sno = 1;
    strow stusample%rowtype;

begin

    open curst;


    loop

        fetch curst into strow;
        DBMS_OUTPUT.PUT_LINE(strow.sno);
        DBMS_OUTPUT.PUT_LINE(strow.sname);
        exit when curst%notfound;

    end loop;
end;



declare
    cursor curst(param number) is select sno, sname
                                  from stusample
                                  where sno = param;
    type haha is record (sno stusample.sno%type, sname stusample.sname%type)
    ;
    ha haha;
begin
    open curst(1);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;
    end loop;
    close curst;
    open curst(2);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;

    end loop;
    close curst;
end;



declare
    cursor curst(param number) is select sno, sname
                                  from stusample
                                  where sno = param;
    type haha is record (sno stusample.sno%type, sname stusample.sname%type);
    ha haha;

begin
    open curst(1);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        exit when curst%notfound;

    end loop;
    close curst;
    open curst(2);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        exit when curst%notfound;

    end loop;
end;


declare
    cursor curst(param number) is select sno, sname
                                  from stusample
                                  where sno = param;
    type haha is record (sno stusample.sno%type, sname stusample.sname%type);
    ha haha;
begin

    open curst(1);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        exit when curst%notfound;

    end loop;

    close curst;
    open curst(4);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;
    end loop;
    close curst;
end;


declare
    cursor curst(param number) is select sno, sname
                                  from stusample
                                  where sno = param;
    type haha is record (sno stusample.sno%type, sname stusample.sname%type);
    ha haha;
begin

    open curst(2);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;

    end loop;
    close curst;
    open curst(4);

    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;


    end loop;
    close curst;

end;



declare
    cursor curst(param number) is select sno, sname
                                  from stusample
                                  where sno = param;
    type haha is record (sno stusample.sno%type, sname stusample.sname%type);
    ha haha;

begin

    open curst(2);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;

    end loop;
    close curst;
    open curst(4);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;


    end loop;

    close curst;

end;


declare
    cursor curst(param number) is select sno, sname
                                  from stusample
                                  where sno = param;
    type haha is record (sno stusample%type, sname stusample%type);
    ha haha;

begin

    open curst(2);

    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        exit when curst%notfound;

    end loop;
    close curst;
    open curst(4);
    loop
        fetch curst into ha;
        DBMS_OUTPUT.PUT_LINE(ha.sname);
        DBMS_OUTPUT.PUT_LINE(ha.sno);
        exit when curst%notfound;
    end loop;

    close curst;
end;
/

begin
    update stusample
    set sno=0
    where sno = 4;
    DBMS_OUTPUT.PUT_LINE(sql%rowcount);
    DBMS_OUTPUT.PUT_LINE(sql%rowcount)
end;



declare
    a number;
begin

    select sname into a from student where sname = '사마광';
exception
    when value_error then DBMS_OUTPUT.PUT_LINE('수치이상함');
end;


declare
    a number;

begin

    select sname into a from student where sname = '사마광';
exception
    when value_error then DBMS_OUTPUT.PUT_LINE('시발');
    when others then DBMS_OUTPUT.PUT_LINE('하하');
end;





















declare a number;
    begin

    select sname into a from student where sname='사마광';

    exception
when value_error then DBMS_OUTPUT.PUT_LINE('시발');
end;








-- declare
--
--     cursor curst is select sno, sname from stusample where sno=1;
--     type haha is record ( sno stusample.sno%type, sname stusample.sname%type);
--     ha haha;
--
--
--     begin
--   open curst;
--   fetch curst into ha;
--   DBMS_OUTPUT.PUT_LINE(ha.sno);
--   DBMS_OUTPUT.PUT_LINE(ha.sname);
--   close curst;
-- end;

댓글 영역