0 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 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
SQL> create user byrd identified by admin123; #在SYS用户下建立byrd用户 SQL> grant connect to byrd; #byrd用户拥有链接权限 SQL> grant resource to byrd; #授予resource权限 SQL> grant dba to byrd; #授予dba权限 SQL> conn byrd/admin123 #登录byrd用户 SQL> show user; #查看当前用户 USER is "BYRD" SQL> select * from tab; #查看用户tab; no rows selected SQL> conn / as sysdba Connected. SQL> show user USER is "SYS" SQL> alter user hr account lock; #锁hr用户 SQL> conn hr/hr ERROR: ORA-28000: the account is locked Warning: You are no longer connected to ORACLE. SQL> alter user hr account unlock identified by hr; SP2-0640: Not connected SQL> conn / as sysdba Connected. SQL> alter user hr account unlock identified by hr; #解锁hr账户,且密码为hr SQL> conn scott/admin123 SQL> select * from tab; TNAME -------------------------------------------------------------------------------- TABTYPE CLUSTERID ------- ---------- BONUS TABLE DEPT TABLE EMP TABLE TNAME -------------------------------------------------------------------------------- TABTYPE CLUSTERID ------- ---------- SALGRADE TABLE SQL> desc emp; #显示emp表的字段 Name Null? Type ----------------------------------------- -------- ---------------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2) SQL> set linesize 1000 SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7900 JAMES CLERK 7698 03-DEC-81 950 30 7934 MILLER CLERK 7782 23-JAN-82 1300 10 SQL> select empno,ename,sal from emp; EMPNO ENAME SAL ---------- ---------- ---------- 7369 SMITH 800 7499 ALLEN 1600 7521 WARD 1250 7566 JONES 2975 7654 MARTIN 1250 7698 BLAKE 2850 7782 CLARK 2450 7788 SCOTT 3000 7844 TURNER 1500 7876 ADAMS 1100 EMPNO ENAME SAL ---------- ---------- ---------- 7900 JAMES 950 7934 MILLER 1300 SQL> select empno,ename,sal,comm,sal+comm 2 from emp; #空值不参与运算 EMPNO ENAME SAL COMM SAL+COMM ---------- ---------- ---------- ---------- ---------- 7369 SMITH 800 7499 ALLEN 1600 300 1900 7521 WARD 1250 500 1750 7566 JONES 2975 7654 MARTIN 1250 1400 2650 7788 SCOTT 3000 7839 KING 5000 7844 TURNER 1500 0 1500 7876 ADAMS 1100 EMPNO ENAME SAL COMM SAL+COMM ---------- ---------- ---------- ---------- ---------- 7900 JAMES 950 7902 FORD 3000 7934 MILLER 1300 SQL> select empno,ename,sal,comm,nvl(comm,0)+sal 2 from emp; #nvl(comm,0) 当comm有数值的时候按照数值参与运算,没有则用0替代 EMPNO ENAME SAL COMM NVL(COMM,0)+SAL ---------- ---------- ---------- ---------- --------------- 7369 SMITH 800 800 7499 ALLEN 1600 300 1900 7521 WARD 1250 500 1750 7566 JONES 2975 2975 7654 MARTIN 1250 1400 2650 7788 SCOTT 3000 3000 7839 KING 5000 5000 7844 TURNER 1500 0 1500 7876 ADAMS 1100 1100 EMPNO ENAME SAL COMM NVL(COMM,0)+SAL ---------- ---------- ---------- ---------- --------------- 7900 JAMES 950 950 7902 FORD 3000 3000 7934 MILLER 1300 1300 SQL> select empno,ename,sal,comm,nvl(comm,0)+sal as newsale 2 from emp; #字段别名 SQL> select empno,ename,sal,comm,nvl(comm,0)+sal newsale 2 from emp; EMPNO ENAME SAL COMM NEWSALE ---------- ---------- ---------- ---------- ---------- 7369 SMITH 800 800 7499 ALLEN 1600 300 1900 7521 WARD 1250 500 1750 7566 JONES 2975 2975 7654 MARTIN 1250 1400 2650 7698 BLAKE 2850 2850 7782 CLARK 2450 2450 7788 SCOTT 3000 3000 7839 KING 5000 5000 7844 TURNER 1500 0 1500 7876 ADAMS 1100 1100 EMPNO ENAME SAL COMM NEWSALE ---------- ---------- ---------- ---------- ---------- 7900 JAMES 950 950 7902 FORD 3000 3000 7934 MILLER 1300 1300 SQL> select e.empno,e.ename,e.sal 2 from emp e; #表别名 EMPNO ENAME SAL ---------- ---------- ---------- 7369 SMITH 800 7499 ALLEN 1600 7521 WARD 1250 7566 JONES 2975 7654 MARTIN 1250 7698 BLAKE 2850 7782 CLARK 2450 7788 SCOTT 3000 7839 KING 5000 7844 TURNER 1500 7876 ADAMS 1100 EMPNO ENAME SAL ---------- ---------- ---------- 7900 JAMES 950 7902 FORD 3000 7934 MILLER 1300 SQL> select ename||empno #连接符 2 from emp; ENAME||EMPNO -------------------------------------------------- SMITH7369 ALLEN7499 WARD7521 JONES7566 MARTIN7654 BLAKE7698 CLARK7782 SCOTT7788 KING7839 TURNER7844 ADAMS7876 ENAME||EMPNO -------------------------------------------------- JAMES7900 FORD7902 MILLER7934 SQL> select count(*) from emp; COUNT(*) ---------- 14 SQL> select 'byrd' from emp; 'BYR ---- byrd byrd byrd byrd byrd byrd byrd byrd byrd byrd byrd 'BYR ---- byrd byrd byrd SQL> select 'dr_'||ename||'_'||empno 2 from emp; 'DR_'||ENAME||'_'||EMPNO ------------------------------------------------------ dr_SMITH_7369 dr_ALLEN_7499 dr_WARD_7521 dr_JONES_7566 dr_MARTIN_7654 dr_BLAKE_7698 dr_CLARK_7782 dr_SCOTT_7788 dr_KING_7839 dr_TURNER_7844 dr_ADAMS_7876 'DR_'||ENAME||'_'||EMPNO ------------------------------------------------------ dr_JAMES_7900 dr_FORD_7902 dr_MILLER_7934 14 rows selected. SQL> show user; USER is "SYS" SQL> select NAME from v$datafile; NAME -------------------------------------------------------------------------------- +DATA/ORCL/DATAFILE/system.258.916143117 +DATA/ORCL/DATAFILE/sysaux.257.916143011 +DATA/ORCL/DATAFILE/undotbs1.260.916143253 +DATA/ORCL/DATAFILE/example.266.916143453 +DATA/ORCL/DATAFILE/users.259.916143253 SQL> select name from v$controlfile; #控制文件 NAME -------------------------------------------------------------------------------- +DATA/ORCL/CONTROLFILE/current.261.916143337 +FRA/ORCL/CONTROLFILE/current.256.916143341 SQL> select MEMBER FROM V$LOGFILE; #所有日志文件 MEMBER -------------------------------------------------------------------------------- +DATA/ORCL/ONLINELOG/group_3.264.916143385 +FRA/ORCL/ONLINELOG/group_3.259.916143397 +DATA/ORCL/ONLINELOG/group_2.263.916143365 +FRA/ORCL/ONLINELOG/group_2.258.916143377 +DATA/ORCL/ONLINELOG/group_1.262.916143345 +FRA/ORCL/ONLINELOG/group_1.257.916143357 SQL> select deptno from emp; DEPTNO ---------- 20 30 30 20 30 30 10 20 10 30 20 DEPTNO ---------- 30 20 10 14 rows selected. SQL> select distinct deptno from emp; #取消重复 DEPTNO ---------- 30 20 10 SQL> select empno,ename,sal,deptno from emp where deptno=10; # EMPNO ENAME SAL DEPTNO ---------- ---------- ---------- ---------- 7782 CLARK 2450 10 7839 KING 5000 10 7934 MILLER 1300 10 SQL> SELECT ENAME FROM EMP WHERE ENAME='SCOTT'; #叫做scott的用户 ENAME ---------- SCOTT SQL> SELECT ENAME,SAL,HIREDATE FROM EMP WHERE HIREDATE>'1-JAN-81'; #1981年以后入职的员工 ENAME SAL HIREDATE ---------- ---------- --------- ALLEN 1600 20-FEB-81 WARD 1250 22-FEB-81 SQL> SELECT ENAME,SAL,HIREDATE FROM EMP WHERE HIREDATE > TO_DATE('1981-01-01','YYYY-MM-DD'); #TO_DATE 指定时间格式 ENAME SAL HIREDATE ---------- ---------- --------- ALLEN 1600 20-FEB-81 WARD 1250 22-FEB-81 SQL> SELECT EMPNO,ENAME,SAL,DEPTNO FROM EMP WHERE SAL > 2000 AND SAL < 3000; #大于2000,小于3000 EMPNO ENAME SAL DEPTNO ---------- ---------- ---------- ---------- 7566 JONES 2975 20 7698 BLAKE 2850 30 7782 CLARK 2450 10 SQL> SELECT EMPNO,ENAME,SAL,DEPTNO FROM EMP WHERE SAL BETWEEN 2000 AND 3000; #2000-3000之间 EMPNO ENAME SAL DEPTNO ---------- ---------- ---------- ---------- 7566 JONES 2975 20 7698 BLAKE 2850 30 7782 CLARK 2450 10 7788 SCOTT 3000 20 7902 FORD 3000 20 |
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!