sql例子
A. sql常用语句格式及例子说明是什么呢
如下:
1、创建表:Create table 表名 ( s_id number(4) , s_name varchar2(10) , s_sex char(2) );
2、删除表:Drop table 表名;
3、重命名表名:Rename 旧表名 to 新表名 ;
4、添加列:Alter table 表名 add ( s_age number(3) );
5、删除列:Alter table 表名 drop( S_sex );
6、查询列表所有信息:Select * from 表名 ;
7、查询一个列表信息(加where条件):Select * from 表名 where s_id = 302。
sql创建后表的修改基础用法
添加列 :基本形式:alter table 表名 add 列名 列数据类型 [after 插入位置]。
1、在表的最后追加列 address: alter table students add address char(60); 2、在名为 age 的列后插入列 birthday: alter table students add birthday date after age;
修改列 :基本形式:alter table 表名 change 列名称 列新名称 新数据类型;
1、将表 tel 列改名为 telphone: alter table students change tel telphone char(13) default "-";
2、将 name 列的数据类型改为 char(16): alter table students change name name char(16) not nul。
B. sql查询语句大全
SELECT * FROM TWS2F14CCC260D71 WHERE 地类='1999资源清查有林地'
C. SQL存储过程实例
楼下的太麻烦了吧。emp员工表,输入任何部门号,返回部门的总工资,把总工资和部门好,分别放进emp2表里。
编写存储过程查询某部门员工的工资总和
create or replace procere my_text(v_deptno number)
is
cursor c is select* from emp;
v1 number:=0;
begin
for a in c loop
if(a.deptno=v_deptno) then
v1:=v1+a.sal;
end if;
end loop;
insert into emp2 values(v1,v_deptno);
end;
是不是很吊啊?楼主?
D. sql多表联查实例
sql多表联查实例
下面提供四款sql多表关联查询的实例,个个效率不一样。
select
*
from
order_info
as
a
,ivrlog4ivrdlvinst
as
b
where
(a.saleorder=b.ext1_skill
and
b.start_date=@date1
and
se_id='55'
and
b.ext1_skill!='')
and
convert(varchar(10),a.instime,112)=@date2
and
max(a.instime)
方法二
select
*
from
order_info
as
a
where
a.saleorder=(
select
b.ext1_skill
from
ivrlog4ivrdlvinst
as
b
where
b.start_date=@date1
and
se_id='55'
and
b.ext1_skill!='')
and
convert(varchar(10),max(a.instime),112)=@date2
方法三
declare
@date1
varchar(20),
@date2
varchar(20)
set
@date1='20100812'
set
@date2='2010-08-12'
select
*
from
order_info
as
a
where
a.saleorder=
(select
b.ext1_skill
from
ivrlog4ivrdlvinst
as
b
where
b.start_date=@date1
and
se_id='55'
and
b.ext1_skill!='')
and
convert(varchar(10),a.instime,112)=@date2
and
max(a.instime)
方法四
select
b.caller,
b.start_date,
b.start_time,
b.ext1_skill,
c.deliveryno,
c.destroyresult,
c.deliverydate,
c.deliverytime,
c.arrangetime,
c.driverphone,
c.drivermobile,
a.servicedate,
a.servicetime,
a.workertel
from
order_info
as
a
,ivrlog4ivrdlvinst
as
b
,delivery_info
as
c
where
a.saleorder
in
(select
b.ext1_skill
from
ivrlog4ivrdlvinst
where
b.start_date=@date1
and
b.se_id='55'
and
b.ext1_skill!='')
and
convert(varchar(10),a.instime,112)=@date2
order
by
b.start_date
desc,
b.start_time
desc