007--數(shù)據(jù)庫(kù)編程語(yǔ)法總結(jié)

數(shù)據(jù)庫(kù)編程總概括

  • SQL是執(zhí)行語(yǔ)句,沒(méi)有什么語(yǔ)法只是執(zhí)行方法
  • PL/SQL是語(yǔ)言,對(duì)SQL的編程規(guī)范總結(jié),形成語(yǔ)法,方法和對(duì)象

SQL學(xué)習(xí)知識(shí)概要

  • select
  • select ? from ? join on ? where ? group by ? having ? order by ?
  • select ? from (select ? from ? order by ? ) where rownum <6
  • select ? from (select ?,rownum row_id from (select ? from ? order by ?) order by ? ) where row_id bewteen 6 and 10
  • DML
  • insert into ? values(?,?,?)
  • delete from ? where ?
  • update ? set ? = ?
  • DDL
  • create table ?
  • drop table ?
  • TCL
  • commit
  • rollback
  • DCL
  • grant

PL/SQL學(xué)習(xí)知識(shí)概要

定義變量結(jié)構(gòu)

  • ? 【constant】number 【not null】【:=?】

變量類型

  • 標(biāo)量類型
  • 組合類型
    RECORD
    TABLE
    CURSOR
  • 引用類型
  • 大類型

基本語(yǔ)法結(jié)構(gòu)

  • 語(yǔ)法結(jié)構(gòu)
    declare
    ??
    begin
    ??
    exception
    ??
    end;
  • 打印
    dbms_out_put.putline('Hello,World');
  • 執(zhí)行
    /

對(duì)SQL語(yǔ)句的使用

  • select into
  • 單個(gè)
  • RECORD
  • TABLE
  • CURSOR
  • DML
  • TCL
  • DDL
  • ddl的動(dòng)態(tài)SQL
  • using的動(dòng)態(tài)SQL

PL/SQL匿名函數(shù)(存儲(chǔ)函數(shù))

  • 語(yǔ)法格式
    create or replace procedure ?(?,?)
    is
    begin
    ??
    end;
  • 查看過(guò)程
    desc ?
  • 調(diào)用(無(wú)參)
    call ?
  • 調(diào)用(有參,out)
    declare
    ??
    begin
    ?(?)
    exception
    ??
    end;

PL/SQL匿名函數(shù)(存儲(chǔ)函數(shù))

  • 語(yǔ)法格式
    create or replace function ?(?,?)
    return ?
    is
    begin
    return ?
    end;
  • 刪除函數(shù)
    drop function ?
  • 調(diào)用函數(shù)
  • 語(yǔ)法結(jié)構(gòu)
    declare
    ??
    begin
    dbms_out_put.put_line(?(?,?));
    end;

創(chuàng)建數(shù)據(jù)庫(kù)
? create database 數(shù)據(jù)庫(kù)名[charset:字符編碼集]
? create database 數(shù)據(jù)庫(kù)名
? create database if not exites 數(shù)據(jù)庫(kù)名[charset:字符編碼集]
查看數(shù)據(jù)庫(kù)
? show databases
查看數(shù)據(jù)庫(kù)的創(chuàng)建SQL語(yǔ)句
? show create database 數(shù)據(jù)庫(kù)名
更新數(shù)據(jù)庫(kù)
? alter database 數(shù)據(jù)庫(kù)名 charset-字符編碼集
刪除數(shù)據(jù)庫(kù)
? drop database 數(shù)據(jù)庫(kù)名
? drop database if exites 數(shù)據(jù)庫(kù)名
使用數(shù)據(jù)庫(kù)
? use 數(shù)據(jù)庫(kù)名

數(shù)據(jù)庫(kù)的操作
創(chuàng)建表
? create table 表名(
? name varchar(10) not null,
? sex char(1) not null,
? id int auto_increment primary key,
? id varchar(40) default '地址不詳',
? score decimal(3,1)
? )
查看表
? show tables;
查看表的創(chuàng)建SQL語(yǔ)句
? show create table 表名 \G;
查看表結(jié)構(gòu)
? describe 表名;
刪除表
? drop table 表名;
如果數(shù)據(jù)庫(kù)不支持中文的編碼
? 刪除不支持的表
? 重新創(chuàng)建設(shè)置編碼集

數(shù)據(jù)的操作
插入數(shù)據(jù)
? insert into 表名 values (a,b,c);
? 自動(dòng)增長(zhǎng)可以寫null
? 默認(rèn)值可以寫default
修改數(shù)據(jù)
? update 表名 set 字段:值 where條件
刪除數(shù)據(jù)
? delete from 表名 where條件
查詢數(shù)據(jù)
? 分頁(yè)查詢:select * from emp limit(3,2);

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容