经典SQL(2)
1、经典的查询语句
2、经典的字定义函数
3、经典的与业务相关的存储过程
等等
1、 跟踪当前对话下用户的SQL脚本
select sql_text from v$sqltext_with_newlines where (hash_value,address)
in (select sql_hash_value,sql_address from v$session where sid=&sid)
order by address,piece;
SID
由这得到
select sid,machine from v$session;
======
desc table;检查表结构
select * from tab where tabtype='TABLE';显示当前用户下的所有表。
select count(*) from table;显示此表的数据行数;
spool c:\tony.txt;日记路径
spool off;关闭记录后可以看到日记文件里的内容。
alter table stu add(classid number(2));添加字段
alter table stu modify(xm varchar2(12));修改字段的长度
alter table stu drop column sal;
drop table stu;
rename student to stu;
alter table student drop column sal; alter table stu add(salary number(7,2));
insert into stu values('A001','张三','男','01-5月-05',10);
insert into stu(xh,xm,sex) values ('A003','JOHN','女');
insert into student(xh,xm,sex,birthday) values ('A004','MARTIN','男',null);
修改
update
update stu set sex='女' where xh='A001';
update student set sex='男',birthday='1980-04-01'where xh='A001';
update student set classid=20 where birthday is null;
delete from stu;drop table student;delete from stu where xh='A001';
truncate table stu;删除表中的所有记录,表结构还在不写日记无法找回记录
select * from stu;
select * from student where classid like '1%';
select * from student where xh like '%A%';
select * from student where xh like 'A%';
select * from student where xh like '%A';
select * from student where xh = 'A%';
select * from student order by birthday;
select * from student order by birthday desc,xh asc; --按birthday 降序 按xh升序(asc/默认)
select * from student where sex='女' or birthday='1999-02-01';
select * from student where sex='女' and birthday='1999-02-01';
select * from student where salary > 20 and xh <> 'B002'; (!=)
oracle
函数的学习
单行函数 返回值只有一个
分组
相关文档:
1 ,对于日期字段字段
access表示为:#1981-28-12#
SQLSERVER2000表示为:''1981-02-12''
2,SQL语句区别,select ,update 在对单表操作时都差不多,
但多表操作时update语句的区别ACCESS与SQLSERVER中的Update语句对比:
SQLSERVER中更新多表的Update语句:
Update Tab1
SET a.Name = b.Name
from Tab1 a,Tab2 b
Whe ......
如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......
先把程序打开,菜单上 Environment/Examples/Performance Examples 在空白处输入
要执行的程序,注意一定要正确,否则后果很严重,呵呵.
data: itab type table of TRDIR with header line.
select * from TRDIR into table itab
where NAME = 'ZHRRPT1011'.
read table itab with key name = 'ZHRRPT1011'.
......
//在应用程序Open 事件代码中
idle(600)
openbakflag=1
///////////////////////读取配置文件数据库连接设置///////////////////////
string server,datname,datuser,datpsw
server=ProfileString ( "yy.ini","yygl","server", "" )
datname=ProfileString ( "yy.ini","yygl","datname", "" )
datuser=ProfileStrin ......
select getdate()
是显示当前系统时间,输出的日期格式与本机日期格式有关,假入你想在什么情况下都显示成2006-12-15 10:37:00这种形式则需要转换一下
select convert(varchar(30),getdate(),20)
显示是星期几的语句是
select datename(weekday,getdate())
日期加星期的话直接加在一块就可以了
select convert(varcha ......