SQL平常使用(1)

2021-09-12 08:16:31 字數 2435 閱讀 6863

conn 連線

disc 斷開資料庫連線

passw 修改使用者密碼

exit 斷開資料庫連線並且退出黑框或者退出sqlplus

show user 顯示當前使用者

select a.* from student  a;
簡單的一條查詢語句就出現了。要習慣給表起別名。

select a.stu_no from student a;
0721001

0721002

0721003

0721004

0721005

select a.stu_no ,a.stu_name from student a;
stu_no stu_name

0721001 張三

0721002 李四

0721003 王五

0721004 趙四

0721005 錢六

select distinct a.stu_no from student a;
使用distinct關鍵字,它指示資料庫只返回不同的值。如果使用distinct關鍵字,它必須直接放在列名的前面。

警告:不能部分使用distinctdistinct關鍵字作用於所有的列,不僅僅是跟在其後的那一列。

例如,你指定 select distinct a.stu_no ,a.stu_name from student a;除非指定的兩列完全相同,否則所有的行都會被檢索出來

select a.stu_no ,a.stu_name from student a where rownum<=5;
只顯示檢索出的前5行

注釋使用–(兩個連字元)嵌在行內。–之後的文字就是注釋,

select distinct a.stu_no from student a; --這是一條注釋
注釋從/開始,到/結束,/和/之間的任何內容都是注釋。這種方式常用於給**加注釋。

select distinct a.stu_no from student a; /*這是一條注釋*/
檢索出的資料並不是隨機顯示的。如果不排序,資料一般將以它在底層表**現的順序顯示,這有可能是資料最初新增到表中的順序。但是,如果資料隨後進行過更新或刪除,那麼這個順序將會受到dbms重用**儲存空間的方式的影響。因此,如果不明確控制的話,則最終的結果不能(也不應該)依賴該排序順序。關聯式資料庫設計理論認為,如果不明確規定排序順序,則不應該假定檢索出的資料的順序有任何意義。

order by

select a.stu_no ,a.stu_name from student a order by  a.stu_name;
經常需要按不止乙個列進行資料排序。例如,如果要顯示雇員名單,可能希望按姓和名排序(首先按姓排序,然後在每個姓中再按名排序)。如果多個雇員有相同的姓,這樣做很有用

select prod_id,prod_price,prod_name 

from products

order by prod_price,prod_name;

重要的是理解在按多個列排序時,排序的順序完全按規定進行。換句話說,對於上述例子中的輸出,僅在多個行具有相同的prod_price值時才對產品按prod_name進行排序。如果prod_price列中所有的值都是唯一的,則不會按prod_name排序。

desc降序,asc公升序,預設公升序。

select  prod_id,prod_price,prod_name

from products

order by prod_price desc;

對多行進行排序

select  prod_id,prod_price,prod_name

from products

order by prod_price desc,prod_name asc;

學號為0721001的資訊

select a.* from student a where a.stu_no=0721001;
商品**小於10元(單位由設定的時候確定)

select  prod_id,prod_price,prod_name

from products

where prod_price<10;

操作符說明=

等於<

小於<=

小於等於

!=不等於

<>

不等於between and

在範圍內,包括邊界值

is null

等於空值

sql語句的使用1(oracle)

4.2 sqlplus pl sql中的sql語句使用 注意 以下帶 的語句都已經在sqlplus中經過測試。4.2.1 如何返回系統當前日期 當前連線使用者 select sysdate from dual 系統日期 select to char sysdate,yyyymmdd hh24 mi ...

SQL注入1

1 整型引數的判斷 當輸入的引數yy為整型時,通常abc.asp中sql語句原貌大致如下 select from 表名 where 字段 yy,所以可以用以下步驟測試sql注入是否存在。附加乙個單引號 此時abc.asp中的sql語句變成了 select from 表名 where 字段 yy ab...

多執行緒模版案例 可提供平常學習 業務使用

2 案例如下 已加入詳細備註 public static void main string args throws interruptedexception system.err.println 耗時 system.currenttimemillis start0 ms,index index ma...