日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ORACLE的基础用法

發布時間:2025/7/14 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ORACLE的基础用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ORACLE的基礎用法

轉 自:http://blog.163.com/kelly_19831017/blog/static/6196787020083133348873/

sqlplus sys/oracle as sysdba? //以SYS用戶名進入數據庫
startup? //啟動數據庫
shutdown immediate? //正常關閉數據庫(迫使每個用戶執行完SQL語句時斷開連接)
shutdown abort //強行關閉數據庫(不建議使用)
help index //查詢sqlplus所有功能
set sqlblanklines on //支持空格行
select * from dept where deptno=&tt //tt為變量,要給tt副值
list //查看在緩沖區查看數據(l是簡寫)
l2 4 //查看在緩沖區查看數據(第二行到第4行)
change //修改
c/n/m //把n改成m
/ //執行緩沖區的命令
del 4 //刪除緩沖區第行
a from dept //追加緩沖區的信息
save c:\text.txt //保存緩沖區的信息到C盤下text.txt
@c:\text.txt? //對記事本的信息保存緩沖區里頭
get c:\text.txt //獲得腳本內容
edit //用記事本打開緩沖區的內容
col deptno heading "編號" //把deptno改成編號
desc dept //查看數據庫對象dept表字段類型
col dname format a10 //取10個字符格式華輸出
connect //改變連接用戶
break on dept //對重復的數據只顯示一條
comp count label "別名" of 字段 on 字段? //對重復的字段進行記數


-------
create table abc? //創建表
alter table abc add c number? //向表abc追加一個字段
alter table abc drop column c? //向表abc刪除一個字段
grant select on dept to tt??? //授權dept這張表給TT用戶
revoke select on dept from tt //收回使用這張表的權限
select to_char(sysdate,'yyyy-mm-dd') from dual //把日期轉化為yyyy-mm-dd這種格式
select user from dual //查詢當前用戶
decode? //做統計用
---
create sequence identity
increment by 1
start with 1000
nomaxvalue??????? //創建自動增長列
---
insert into 表 select 字段 from 表? //從一張表插入多條數據到另外一張表
create table 表 as (select 字段 from 表)? //創建一張新表并且把另外一張表的數據插入進去
exp scott/oracle file=路徑? //把scott這個空間的表備份到這個路徑
imp scott/oracle ignore=true file=路徑 //把這個路徑下的文件導入到scott這個空間里面

---
declare
x number;? //定義一個變量
begin
x:=0;?? //給變量賦值
loop??? //循環
x:=x+1;? //記數
if x>=3 then exit; //當變量>=3時,跳出當前循環
end if;
end loop;
dbms_output.put_line('x='||x); //打印X的值
end;

---
while x<3 loop
x:=x+1;
end loop;

---
begin
for i in 1..5 loop? //循環i從1到5
dbms_output.put_line('x='||x);
end loop;
end;

---
begin
for i in reverse 1..5 loop? //循環i從1到5,倒序輸出
dbms_output.put_line('x='||x);
end loop;
end;

---
declare num number;
begin
select ClassID into num from Class where id=1000;?? //把查詢出來的ClassID這個值放入num這個變量中
exception
when no_date_found then dbms_output.put_line('沒有找到數據');
end;

---法器創建格式
create or replace trigger 法器名
after delete on 表名
for each row?? //對每一行進行
begin
?~~~~~~~~~~~~~~~``
end

----
raise_application_error(-2000,"錯誤內容")? //強行不準刪除


---
alter user scott identified by aaa? //把scott用戶的表空間密碼改成aaa
alter user scott account lock? //把Scott表空間進行鎖定
alter user scott account unlock? //把Scott表空間進行解除鎖定
create user qqq identified by qqq123 default tablespace user //創建一個qqq,密碼為的用qqq123戶表空間, 默認表空間為qqq123
grant connect to qqq? //為qqq創建連接
with grant option //下放權限
grant all on scott.dept to tt //把所有權限給TT用戶
grant execute on tt.proc01 to text //把使用存貯過程的權限給Test用戶
grant create user to text //把創建用戶的權限給text用戶
grant drop user to text //把刪除用戶的權限給text用戶
grant connect,resource to userBook? //把一般的權限受給這個用戶
---
creare tablespace tabs?
datafile 'E:\Oracle\product\10.1.0\oradata\oracle\tabs.dbf' size 10M autoextend on;//創建一個tabs的表空間,默認的文件路徑,大小為10M
grant unlimited tablespace ,dba to test? //給表空間授權

---
select constraint_name,constraint_type from user_constraints
where table_name='emp';


日期函數:
select * from XiangMuBiao where kaishishijian<=last_day(sysdate) and kaishishijian>=add_months(last_day(sysdate)+1,-1)? //在本月中的所有字段
Select last_day(sysdate) from dual;//一個月的最后一天
select add_months(last_day(sysdate)+1,-1) month from dual;//本月的第一天
select?? to_date('20040401 122525','yyyymmdd?? hh24miss') from dual;//轉換為日期格式

轉載于:https://www.cnblogs.com/lzx_ok/archive/2010/10/20/1856649.html

總結

以上是生活随笔為你收集整理的ORACLE的基础用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。