隨筆 - 44  文章 - 78  trackbacks - 0
          <2008年12月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

           Happy 牛 Year
          一、一周至少寫一篇博文;
          二、每天至少學(xué)習(xí)半個(gè)小時(shí)。
          三、奔向小牛!

          常用鏈接

          留言簿(6)

          我參與的團(tuán)隊(duì)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          ?????--創(chuàng)建表空間
            create tablespace yyspace
            datafile ’d:\yyspace.dbf’
            size 10m
            autoextend on;
            --創(chuàng)建臨時(shí)表空間
            create temporary tablespace yytemp
            tempfile ’d:\yytemp.dbf’
            size 10m
            autoextend on;
            --創(chuàng)建用戶
            create user yangrs
            identified by yangrs;
            alter user yangrs
            default tablespace yyspace;
            alter user yangrs
            temporary tablespace yytemp;
            --賦權(quán)
            grant connect,resource to yangrs
            --connect
            connect yangrs/yangrs;
            --建表
            --刪表
            drop table stuInfo
            create table stuInfo
            (
            s_id number(4),
            s_name varchar2(10),
            s_sex char(2),
            s_age number(3),
            s_birthday date default(sysdate),
            s_note varchar2(50)
            );
            create table stuScore
            (
            stuid number(4),
            scoreid varchar2(10),
            score number(3)
            );
            drop table stuScore;
            --加約束
            --主鍵
            alter table stuInfo
            add constraint PK_s_id primary key(s_id);
            --檢查
            alter table stuInfo
            add constraint CK_s_sex check(s_sex in (’男’,’女’));
            alter table stuInfo
            add constraint CK_s_age check(s_age>0 and s_age<100);
            --加默認(rèn)的不行
            alter table stuInfo
            add constraint DK_s_birthday default(systimestamp );
            --外鍵
            alter table stuScore
            add constraint FK_stuid foreign key(stuid) references stuInfo(s_Id);
            --insert
            insert into stuInfo(s_id,s_name,s_age,s_Sex,s_Note) values(1000,’劉德華’,20,’男’,’just do it’);
            insert into stuInfo(s_Id,s_name,s_age,s_sex,s_birthday,s_note) values(1001,’yangrs’,19,’男’,to_date(’1989-01-01’,’yyyy-mm-dd’),’i am what i am’);
            insert into stuInfo(s_Id,s_name,s_age,s_sex,s_birthday,s_note) values(1002,’yangrs2’,19,’男’,to_date(’1989-01-01’,’yyyy-mm-dd’),’i am what i am’);
            insert into stuInfo(s_Id,s_name,s_age,s_sex,s_birthday,s_note) values(1003,’yangrs3’,19,’男’,to_date(’1989-01-01’,’yyyy-mm-dd’),’i am what i am’);
            insert into stuInfo(s_Id,s_name,s_age,s_sex,s_birthday,s_note) values(1004,’yangrs4’,19,’男’,to_date(’1989-01-01’,’yyyy-mm-dd’),’i am what i am’);
            insert into stuInfo(s_id,s_name,s_age,s_Sex,s_Note) values(1005,’華仔’,20,’男’,’just do it’);  
            insert into stuScore(Stuid,scoreid,Score) values(1001,’1’,100);
            insert into stuScore(Stuid,scoreid,Score) values(1001,’1’,100);
            insert into stuScore(Stuid,scoreid,Score) values(1000,’1’,100);
            insert into stuScore(Stuid,scoreid,Score) values(1000,’1’,100);

            --復(fù)制表
            create table stuBak
            as select * from stuInfo;
            --復(fù)制表結(jié)構(gòu)
            create table stuBak2
            as select * from stuInfo where 1=2;
            --在已有的表結(jié)構(gòu)中插入數(shù)據(jù)
            insert into stuBak2
            select * from stuBak;
            update stuBak set s_sex=’男’;
            savepoint mark;
            rollback to savepoint mark;
            rollback;
            --給予其他用戶權(quán)限
            connect scott/tiger@itjob;
            grant select on emp to yangrs; --只給查詢
            grant all on emp to yangrs --給所有的權(quán)限
            connect yangrs/yangrs@itjob;
            select * from scott.emp;
            -- 取消權(quán)限
            connect scott/tiger@itjob;
            revoke select on emp from yangrs;
            connect yangrs/yangrs@itjob;
            select * from scott.emp; --此時(shí)已經(jīng)連接不上去了
            --偽列 rowid rownum
            select rowid,rownum from stuInfo;
            --用于分頁
            select * from (select rownum as num,stuInfo.* from stuInfo) where num>5;
            --sqlserver中是使用top來分頁
            --啞元表
            select sysdate from dual;
            select systimestamp from dual;
            --對表的修改
            alter table stuInfo add(s_sal number(3));
            --is null and is not null
            select * from stuInfo where s_note is null;
            select * from stuInfo where s_name like ’y%’; --%代筆任意個(gè)字符
            select * from stuInfo where s_name like ’y_’; --—_代表一個(gè)字符
            select * from stuInfo where s_name like ’y?’;
            select * from stuInfo order by s_age desc; -- 排序
            select * from stuInfo order by s_birthday asc;
            select * from stuInfo order by s_age desc,s_birthday asc;
            --可以有兩個(gè)條件
            --分組
            select * from stuInfo where s_name<>’yangrs’;
            select * from stuInfo where s_age=19;
            select * from stuInfo where s_name<>’yangrs%’; --這樣是不行的
            --調(diào)用函數(shù)
            select sum(s_sal) as 獎(jiǎng)學(xué)金 from stuInfo;
            select avg(s_age) 平均年齡 from stuInfo;
            select s_name,s_age from stuInfo group by s_age;
            select ’hell’||’loworld’ from dual;
            select 1+1 from dual;
            --轉(zhuǎn)換大小寫
            update stuInfo set s_name=upper(s_name);
            update stuInfo set s_name=lower(s_name);
            --轉(zhuǎn)換ascii碼
            select ascii(’A’) from dual;
            select ’Hello’||’\t’||’World’ from dual;
            select ’Hello’||chr(9)||’World’ from dual;
            select to_char(sysdate,’yyyy/mm/dd hh24:mi:ss’) from dual;
            select add_months(sysdate,-12) from dual;
            -- 一年以前的今天
            select last_day(sysdate) from dual;
            select to_char(sysdate,’yyyy/mm/dd’) from dual; --改變?nèi)掌诟袷?br />  select to_char(to_date(’19990214’,’yyyymmdd’),’yyyy"我"mm"月"dd"日"’) from dual;
            select to_char(to_date(’19990214’,’yyyymmdd’),’yyyy"我"mm"月"dd"日"’) from dual;?

          ?????ref:http://www.zlksw.cn/html/jsj/Oraclerenzheng/xuexiziliao/200812/24-7834.html

          posted on 2008-12-26 10:40 Tiger1102 閱讀(517) 評論(0)  編輯  收藏 所屬分類: 程序人生
          主站蜘蛛池模板: 阿克陶县| 游戏| 迭部县| 宁河县| 五指山市| 屏东县| 惠安县| 扶沟县| 鄱阳县| 平潭县| 锡林郭勒盟| 茂名市| 宜丰县| 克山县| 平和县| 喀喇沁旗| 奇台县| 锦屏县| 普兰店市| 金平| 仙居县| 普洱| 蚌埠市| 色达县| 清苑县| 龙游县| 綦江县| 西宁市| 白沙| 宁武县| 荆门市| 自贡市| 汝城县| 东城区| 霍林郭勒市| 将乐县| 五台县| 皋兰县| 横山县| 鹤山市| 丹阳市|