1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
| alter table student add (ssex varchar2(2));
alter table student add stel varchar2(11);
alter table student add saddr integer;
alter table student modify saddr varchar2(255);
alter table student add saddre integer;
alter table student drop column saddre;
alter table student add sidcard varchar2(18);
rename student to stu
create table stu( s_id number(10) primary key, s_name varchar2(255) not null, s_sex varchar2(2) check(s_sex='男' or s_sex='女'), s_addr varchar2(255) default '山西省太原市', s_idcard varchar2(18) unique );
create table stu1( s_id number(10), s_name varchar2(255) not null, s_sex varchar2(2), s_addr varchar2(255) default '山西省太原市', s_idcard varchar2(18) , constraint pri_sid primary key(s_id), constraint unique_idcard unique(s_idcard), constraint check_sex check(s_sex='男' or s_sex='女') );
select * from stu; insert into stu values(3,'rose','女','北京市朝阳区','000001'); insert into stu(s_id,s_name) values(2,'mary');
create table stu (s_id number(10) primary key, s_name varchar2(255)); create table student( s_id number(10), s_name varchar2(255), constraint primary_sid primary key(s_id) ); select * from stu;
insert into stu values(1,'mike');
insert into stu values(2,'rose');
alter table stu disable constraint stu_clazz_fk
alter table stu enable constraint stu_clazz_fk
alter table stu drop constraint stu_clazz_fk alter table clazz drop constraint SYS_C009658 cascade
insert into clazz values(1,'软件开发与测试') insert into stu values(1,'mary',1) insert into stu values(2,'mary',2)
delete from stu where s_id = 3 delete from clazz where c_id=1
select * from clazz select * from stu
create table stu(s_id number(10) primary key ,s_name varchar2(255), c_id number(20), constraint stu_clazz_fk foreign key(c_id) references clazz(c_id) on delete cascade ); create table stu(s_id number(10) ,s_name varchar2(255), c_id number(20) references clazz(c_id) );
alter table stu add c_id number(20) ;
alter table stu add constraint stu_clazz_fk foreign key (c_id) references clazz(c_id);
create table clazz(c_id number(10) primary key,c_name varchar2(255));
select * from stu; select sid,sname from stu; select s.sid 编号,s.sname 名字 from stu s
insert into stu values(1,'mike','男','13888888888','山西省太原市','00001'); insert into stu(sid,sname) values(2,'rose');
update stu set ssex='女'; update stu set ssex='男' where sid=1; update stu set stel='13001234567',saddr='北京市朝阳区' where sid=2;
delete from stu where sid=3; delete from stu;
truncate table stu;
insert into stu values(1,'mike','男','山西省太原市','13888888888',20,'00001',1); insert into stu values(2,'mary','女','山西省太原市','13000000000',18,'00002',2); insert into stu values(3,'rose','女','山西省太原市','13111111111',28,'00003',3); insert into stu values(4,'john','男','山西省太原市','13546354321',30,'00004',3); insert into stu values(5,'alin','女','山西省太原市','13789312381',16,'00005',2); insert into stu values(6,'keven','男','山西省太原市','13324432544',25,'00006',1); insert into stu values(7,'张三','男','山西省太原市','13813128312',40,'00007',1); insert into stu values(8,'李四','男','山西省太原市','13857123574',53,'00008',1); insert into stu values(9,'王五','男','山西省太原市','13898411624',30,'00009',3); insert into stu values(10,'貂蝉','女','山西省太原市','13854101464',19,'00010',2); insert into stu values(11,'王昭君','女','山西省太原市','13016779414',16,'00011',1);
insert into clazz values(1,'java'); insert into clazz values(2,'UI'); insert into clazz values(3,'测试');
select * from stu select * from clazz
SELECT * FROM STU WHERE S_NAME = upper('keven') select s_name,length(s_name) from stu select * from stu where length(s_name)=2 select s_name,substr(s_addr,1,3) from stu select s_name,instr(s_name,'e') from stu select concat(111,222) from dual
select * from stu select s_id,s_name,s_sex,s_addr,s_tel,s_age,s_idcard,c_id from stu select * from clazz
select trunc(3.67,1) from dual select MOD(10 , 3) from dual
select last_day(sysdate+4) from dual
select sysdate+7 from dual
select * from stu where s_addr is not null select to_number(s_tel) from stu select to_char(sysdate,'yyyy-MM-dd') from dual
select replace(to_date('20170829','yyyy/MM/dd'),'/','-') from dual select s_name,nvl(s_addr,'暂未登记地址') from stu select s_name,nvl2(s_addr,'已登记地址','未登记地址') from stu select s_name,s_age,(case when s_age <18 then '未成年' when s_age <30 and s_age>20 then '青年' else '不合法的年龄' end) 区间 from stu select s_name,s_age,(case s_age when 18 then '成年' when 30 then '而立' else '不合法的年龄' end) 区间 from stu select s_name,s_age,decode(s_age ,20,'加冠',30,'而立') from stu
select trim(leading 'H' from 'Hello World') from dual
select s_id from stu minus select c_id from clazz
select 1,1 from dual union select 1,1 from dual union select 1,1 from dual
select s.rowid,s.* from stu s where s.rowid = 'AAARVcAAGAAAADMAAG';
select rownum,s.* from stu s where rownum>5 and rownum <=10
select * from stu s,clazz c where s.c_id = c.c_id ;
select * from stu s inner join clazz c on s.c_id=c.c_id ;
select * from stu s left join clazz c on s.c_id = c.c_id
select * from stu s full join clazz c on s.c_id = c.c_id
select count(1) from stu select s.s_sex,s.s_age,count(1) from stu s where s.s_age<>20 group by s.s_sex,s.s_age having count(1)>1
select * from stu s order by s.s_age desc,s.s_id desc
select * from stu s where s.s_name like '_o%'
select * from stu select * from clazz select s.* from stu s where s.c_id=(select c.c_id from clazz c where c.c_name='UI') select * from stu s where s.c_id in (select c.c_id from clazz c where c.sch_id = (select sch.sch_id from school sch where sch.sch_name='中北大学')) select a.s_name,a.c_name,a.a,a.b from ( select s.s_name,s.s_sex,s.s_age,s.c_id a,c.c_id b,c.c_name from stu s,clazz c where s.c_id=c.c_id ) a
create or replace view v1 as( select s.s_name,s.s_sex,s.s_age,s.c_id a,c.c_id b,c.c_name from stu s,clazz c where s.c_id=c.c_id) select * from v1
select s1.s_name,s1.s_age,(select count(1) from stu s2 where s2.s_age<s1.s_age)+1 a from stu s1 order by a
select distinct s.s_age from stu s insert into a select distinct * from stu
|