oracle 資料庫sql練習
--DDL,DML
create table student(
name varchar(20),
age number(3)
)
insert into student values('Tom',18)
drop table student
delete from student where age =20
--varchar 可以儲存空字串但是varchar2儲存空字串為null;
create table person(
name varchar2(20)
age number(3)
)
insert into person values('Tom');
drop table peson
delete from student where age =20;
----------------------------------------------------------
hibernate5 struts2 spring4
---------------------------------------------------
--更新資料 左閉右開
update student set adress = trunc(dbm_random.value(1,4)) where adress is null;
update student set adress = null;
update student set adress = '01';
where adress = '1'
--增加列
alert table add (telephone varchar2(16))
--註釋
comment on column student.telephone is '01 市電話 02 縣電話 03 所電話'
--字元函式
Select substr(’abcdefg’,1,3) substr,
Instr(‘abcdefg’,’c’) instr,
‘hello’ || ‘world’ concate
From table1
--數字函式
Select to_number(‘01234’) number1,
Trunc(to_number(‘0123.678’),2) number2,
To_number(1000,’xxxx’) number3
From table1
--distinct函式
Select count(distinct equiptype) from tables
Select count(1) from table1
--interval日期加減 next_day()函式
Select to_char(faulttime – interval ‘7’ month, ‘yyyy-mm-dd hh24:mi:ss’) intervalyear
From table1
Select faulttime today,next_day(faulttime,6) nextday from table1
--decode==case when 函式
Selct decode(position, ‘01’,’平原’,’02’,’林區’,’03’,’山區’) position
From table1
--儲存過程語法
Create or replace procedure SP_Updata_Age
(
uName in varchar,
Age int age
)
As
Begin
Update student set UserAge = UserAge + Age where username = uname
--commit
End SP_Updata_Age
--執行
Exec SP_Updata_Age(‘jack’,1)