<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    yerenzyy

    sqlplus常用命令

     

    1.登陸系統(tǒng)用戶
    sqlplus 然后輸入系統(tǒng)用戶名和密碼
    登陸別的用戶
    conn 用戶名/密碼;
    2.創(chuàng)建表空間
    create tablespace 空間名
    datafile 'c:"空間名' size 15M --表空間的存放路徑,初始值為15M
    autoExtend on next 10M --空間的自動增長的值是10M
    permanent online; --永久使用
    3.創(chuàng)建用戶
    create user shi --創(chuàng)建用戶名為shi
    identified by scj --創(chuàng)建密碼為scj
    default tablespace 表空間名 --默認表空間名
    temporary tablespace temp --臨時表空間為temp
    profile default --profile文件的限制
    quota unlimited on 表空間名; --在表空間下面建表不受限制
    4.創(chuàng)建角色
    create role 角色名 identified by 密碼;
    5.給角色授權
    grant create session to 角色名;--給角色授予創(chuàng)建會話的權限
    grant 角色名 to 用戶名; --把角色授予用戶
    6.給用戶授予權限
    grant create session,resource to shi;--shi用戶授予所有權限
    grant create table to shi; --shi用戶授予創(chuàng)建表的權限
    7.select table_name from user_tables; 察看當前用戶下的所有表
    8.select tablespace_name from user_tablespaces; 察看當前用戶下的 表空間
    9.select username from dba_users;察看所有用戶名稱命令 必須用sys as sysdba登陸
    10.創(chuàng)建表
    create table 表名
    (
    id int not null,
    name varchar2(20) not null
    )tablespace 表空間名 --所屬的表空間
    storage
    (
    initial 64K --表的初始值
    minextents 1 --最小擴展值
    maxextents unlimited --最大擴展值
    );
    11.--usrs表添加主鍵和索引
    alter table users
    add constraint pk primary key (ID);
    12.為已經(jīng)創(chuàng)建users表添加外鍵
    alter table users
    add constraint fk_roleid foreign key (roleid)
    references role(role_id) on delete cascad; --下邊寫主表的列
    on delete cascad是創(chuàng)建級聯(lián)
    13.把兩個列連接起來
    select concat(name,id) from 表名; --nameid連接起來
    14.截取字符串
    select column(name,'') from 表名; --name中的去掉
    15.運行事務之前必須寫
    set serveroutput on; --打開輸入輸出(不寫的話,打印不出信息)
    16.while的應用
    declare --聲明部分
    ccc number:=1; --復職
    a number:=0;
    begin --事務的開始
    while ccc<=100 loop --循環(huán)
    if((ccc mod 3)=0) then --條件
    dbms_output.put_line(ccc||','); --打印顯示
    a:=a+ccc;
    end if; --結束if
    ccc:=ccc+1;
    end loop; --結束循環(huán)
    dbms_output.put_line(a);
    end; --結束事務
    /
    17.select into 的用法 --只能處理一行結果集
    declare
    name varchar(30);
    begin
    select username into name
    from users
    where id=2;
    dbms_output.put_line('姓名為:'||name);
    end;
    /
    18.利用%rowtype屬性可以在運行時方便的聲明記錄變量和其他結構
    Set serveroutput on;
    Declare
    utype users%rowtype;
    Begin
    Select * into utype from users where id=20;
    Dbms_output.put_line('姓名'|| utype.username);
    Dbms_output.put_line('生日'|| utype.brithday);
    end;
    / --%rowtype想當于復制一個表
    19.游標的定義和使用
    Declare
    Cursor ucur is select * from users; --聲明游標
    Us users%rowtype;--定義與游標想匹配的變量
    Begin
    Open ucur;--打開游標
    Fetch ucur into us;
    While ucur %found loop --使用循環(huán)遍歷游標的查詢結果
    Dbms_output.put_line('姓名:'||us.username||'生日'||us.brithday);
    Fetch ucur into us;
    End loop;
    Close ucur; --關閉游標
    End;
    =======================================
    %found在前一條的fetch語句至少對應數(shù)據(jù)庫的一行時,%found屬性值為true,否則為false;
    % notfound 在前一條fetch語句沒有對應的數(shù)據(jù)庫行時,%notfound屬性值為true,否則為false;
    %isopen 在游標打開時%isopen屬性值為true;否則為false;
    %rowcount顯示迄今為止從顯示游標中取出的行數(shù)

    20.
    刪除
    drop tablespace 空間名 including contents; --刪除表空間和里面的內(nèi)容
    drop table 表名 --刪除表
    drop user 用戶名 --刪除用戶

    posted on 2008-09-10 16:49 冶人 閱讀(1102) 評論(1)  編輯  收藏

    評論

    # re: sqlplus常用命令 2008-09-17 09:27 jeasonzhao

    It's useful,thx  回復  更多評論   


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    <2008年9月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    導航

    統(tǒng)計

    常用鏈接

    留言簿(1)

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: mm1313亚洲精品无码又大又粗| 久久久久久国产精品免费免费男同 | 亚洲精品卡2卡3卡4卡5卡区| 韩国亚洲伊人久久综合影院| 在线观看免费大黄网站| 久久精品国产亚洲αv忘忧草| 日本视频一区在线观看免费| 18gay台湾男同亚洲男同| 色欲A∨无码蜜臀AV免费播| 亚洲视频中文字幕| 99久热只有精品视频免费看| 亚洲福利视频导航| 亚洲毛片免费视频| 亚洲欧洲日本在线观看| 在线a毛片免费视频观看| 亚洲AV无码片一区二区三区| 日本免费人成黄页在线观看视频 | 人妻无码久久一区二区三区免费 | 亚洲精品日韩专区silk| 100000免费啪啪18免进| 四虎亚洲精品高清在线观看| 免费观看的a级毛片的网站| 亚洲AV成人一区二区三区观看 | 久久99精品视免费看| 亚洲成AV人在线观看天堂无码| 国产免费久久精品丫丫| 亚洲精品高清国产一线久久| 免费国产成人α片| 亚洲人成网站日本片| 免费高清小黄站在线观看| 日韩在线视精品在亚洲| 国产亚洲色婷婷久久99精品91| 无码精品人妻一区二区三区免费看| 亚洲精品国产福利在线观看| 在线A级毛片无码免费真人| 一本久久免费视频| 亚洲伊人久久大香线蕉苏妲己| 欧洲精品成人免费视频在线观看| 亚洲国产无线乱码在线观看| 国产成人精品亚洲精品| 最近2019年免费中文字幕高清|