oracle中的增删改查和一些常用的sql语句
2017-02-10 14:31
495 查看
对于oracle工作当中的操作觉得看了我的博客基本就没什么问题了。通俗易懂
oracle当中的修改密码问题
1. 管理员登录
*. sqlplus sys/密码 as sysdba
*. sqlplus / as sysdba
2. 解锁
alter user scott account unlock;
3. 修改密码
alter user scott identified by 新密码;
基本的select语句
select *from tablename;
select[distinct] column1,column2 from tablename;
distinct是去掉重复的关键字
使用别名
select column1 col1,column2 col2 from tablebname;
col1和col2就是别名
显示表结构:describe tablename;
过滤和排序:使用的where
是用以下表做示范:
city表:cid(number(10)) cname (varchar2(20)) country(varchar2(20)
1 北京 中国
2 首尔 韩国
3 伦敦 英国
4 东京 日本
5 旧金山 美国
6 莫思科 俄罗斯
7 孟买 印度
8 台湾 null
country:表
id (number(10)) dname(varchar2(20)) ranking(number(10)) code varchar2(20) money(number(20))
1 中国 1 zhongguo 9999999
2 美国 3 meiguo 6383838
3 俄罗斯 2 eluosi 3897262
4 印度 5 yindu 4447474
5 日本 4 riben 7474747
6 韩国 7 hanguo 2121212
7 英国 6 meiguo 3232323
select*from city where cid=1;
这就查询出中国来了
between ...and 在两个值之间
in (set) 等于两值中的一个
like 模糊查询
is null 叛断空值
模糊查询
select country from city where counry like '国%'
这样就可以查询出含有国字的country
判断空
select cname , country from city where country is null;
这样就可以查到台湾
排序:order by asc(升序)desc(降序)
select id ,dname, ranking from country order by ranking ;
函数:
单行函数:
大小写控制函数:lower ,upper。
select id ,dname, ranking , code from country
where upper(code) ='zhonguo';
这样中国的拼音就是大写的。小写同理;
字符控制函数:
函数 结果
concat('hello','world') helloword
substr (‘helloworld’,1,5) hello
length ('helloworld') 10
instr ('helloworld',w) 6
lpad (id,5,'*') ****1
rpad (id,5,'*') 1****
trim ('h' from 'hellorold) elloworld
replace ('abcd' ,'b','m') amcd
数字函数:
round 四舍五入
trunc 截断
mod 求余
日期函数: 描述:
months_between 两个日期相差的月数
add_months 向指定日期中加上若干月数
next_day 指定日期的下一个日期
last_day 本月最后的一天
round 日期四舍五入
trunc 日期截断
转换函数
to_date
to_char
to_number
等等:其他在日常开发中不是数据库专员可以了解就可以了
分组:group by用法
select dname ,avg(money) from country group by money;
多列分组
select id,dname, sum(money) form country group by dname,id;
group by 只能在having中使用筛选
select id ,max(money) from country group by id; having max(money) >400000;
多表查询:
select table1.column,table2.coulumn from table1,table2 where table1.coumb1=table2.column2;
子查询:
select dname from where money>(select money from country where danme=‘中国’)
多行使用and连接;
向表中插入数据;
insert into tablename(column) values (columnvalues,)
insert into city(cid,cname,country) values(9,’曼谷’,‘泰国’);
列的内容要和值的类容一致 如有空值这使用‘null’
修改表中的数据
pudate table set column=value[,column=value...]
update city set name='曼谷1’ where country='泰国';
如果没有where则所有的name都改变了
删除表中的数据
delete from tablename where tiaojian
delete from city where cid=9;
如果没有where条件那么表中所有数据都被删除
事务提交和回滚
commit rollback
savapoint 保存回滚点;savapoint name .回滚到回滚点:rollback to name;
create table tablename(
Column daetype yuesu
....
)
country 表结构为 cid , cname.
1 中国
cites表结构为 mid, mname, coutryid;
1 北京 1
他们的关系就是一个国家对应几个城市。所以他们的countryid是和cid是相等的。
select cid,cname,mid,mname from cites, country where cid=coutryid and cid=1;
通过上面的数据我们查询结果为 1, 中国, 1,北京。
以下就是创建表格了:
create table tabname(
列名 数据结构 约束,
列名 数据结构 约束
)
示范一个简单的表
create table login(
id number (10) primarykey not null,
name varchar2(20) not null,
password number(20) not null
)
这个就是最基本的表格;同时我们可以加上主外键红色的类容是加上主键:
然后就是复制其他表的结构创建表:
还是以我上面的两个表(country和cites)演示:
create table newcountry
as
select cid,cname from country;
这样就ok了!
然后就是表的一些操作了(所谓的增删改查了)
这次是使用cites表做演示;
追加一个照片列:alter table cites add (image blob);
图片的数据类型是blob 这个要了解哈!
这样cites 表格的数据结构为:cid, cname, country , image了
然后就是修改列了:这个使用login表做示范以为他有数据类型
alter table login modify (id number(15)) ;
这样就把login 表中的id 的number长度改为了15了
然后就是删除列了:使用cites表做示范我们把刚才添加的image列给删掉
alter table cites drop column image;
然后就是重命名的操作我们使用 login表做演示;把name 重命名为username
alter bable login rename column name to username;
然后就是删除表了;
drop table login;
这样login表就删除了;
插入数据大家应该都会吧!我还是谢谢
insert into tabname (column)values(columnvalues)
接下来就是创建试图使用login表做演示
creaet view loginwiew
as select id , name,passworld from loginn where id=?
oracle当中的修改密码问题
1. 管理员登录
*. sqlplus sys/密码 as sysdba
*. sqlplus / as sysdba
2. 解锁
alter user scott account unlock;
3. 修改密码
alter user scott identified by 新密码;
基本的select语句
select *from tablename;
select[distinct] column1,column2 from tablename;
distinct是去掉重复的关键字
使用别名
select column1 col1,column2 col2 from tablebname;
col1和col2就是别名
显示表结构:describe tablename;
过滤和排序:使用的where
是用以下表做示范:
city表:cid(number(10)) cname (varchar2(20)) country(varchar2(20)
1 北京 中国
2 首尔 韩国
3 伦敦 英国
4 东京 日本
5 旧金山 美国
6 莫思科 俄罗斯
7 孟买 印度
8 台湾 null
country:表
id (number(10)) dname(varchar2(20)) ranking(number(10)) code varchar2(20) money(number(20))
1 中国 1 zhongguo 9999999
2 美国 3 meiguo 6383838
3 俄罗斯 2 eluosi 3897262
4 印度 5 yindu 4447474
5 日本 4 riben 7474747
6 韩国 7 hanguo 2121212
7 英国 6 meiguo 3232323
select*from city where cid=1;
这就查询出中国来了
between ...and 在两个值之间
in (set) 等于两值中的一个
like 模糊查询
is null 叛断空值
模糊查询
select country from city where counry like '国%'
这样就可以查询出含有国字的country
判断空
select cname , country from city where country is null;
这样就可以查到台湾
排序:order by asc(升序)desc(降序)
select id ,dname, ranking from country order by ranking ;
函数:
单行函数:
大小写控制函数:lower ,upper。
select id ,dname, ranking , code from country
where upper(code) ='zhonguo';
这样中国的拼音就是大写的。小写同理;
字符控制函数:
函数 结果
concat('hello','world') helloword
substr (‘helloworld’,1,5) hello
length ('helloworld') 10
instr ('helloworld',w) 6
lpad (id,5,'*') ****1
rpad (id,5,'*') 1****
trim ('h' from 'hellorold) elloworld
replace ('abcd' ,'b','m') amcd
数字函数:
round 四舍五入
trunc 截断
mod 求余
日期函数: 描述:
months_between 两个日期相差的月数
add_months 向指定日期中加上若干月数
next_day 指定日期的下一个日期
last_day 本月最后的一天
round 日期四舍五入
trunc 日期截断
转换函数
to_date
to_char
to_number
等等:其他在日常开发中不是数据库专员可以了解就可以了
分组:group by用法
select dname ,avg(money) from country group by money;
多列分组
select id,dname, sum(money) form country group by dname,id;
group by 只能在having中使用筛选
select id ,max(money) from country group by id; having max(money) >400000;
多表查询:
select table1.column,table2.coulumn from table1,table2 where table1.coumb1=table2.column2;
子查询:
select dname from where money>(select money from country where danme=‘中国’)
多行使用and连接;
向表中插入数据;
insert into tablename(column) values (columnvalues,)
insert into city(cid,cname,country) values(9,’曼谷’,‘泰国’);
列的内容要和值的类容一致 如有空值这使用‘null’
修改表中的数据
pudate table set column=value[,column=value...]
update city set name='曼谷1’ where country='泰国';
如果没有where则所有的name都改变了
删除表中的数据
delete from tablename where tiaojian
delete from city where cid=9;
如果没有where条件那么表中所有数据都被删除
事务提交和回滚
commit rollback
savapoint 保存回滚点;savapoint name .回滚到回滚点:rollback to name;
create table tablename(
Column daetype yuesu
....
)
country 表结构为 cid , cname.
1 中国
cites表结构为 mid, mname, coutryid;
1 北京 1
他们的关系就是一个国家对应几个城市。所以他们的countryid是和cid是相等的。
select cid,cname,mid,mname from cites, country where cid=coutryid and cid=1;
通过上面的数据我们查询结果为 1, 中国, 1,北京。
以下就是创建表格了:
create table tabname(
列名 数据结构 约束,
列名 数据结构 约束
)
示范一个简单的表
create table login(
id number (10) primarykey not null,
name varchar2(20) not null,
password number(20) not null
)
这个就是最基本的表格;同时我们可以加上主外键红色的类容是加上主键:
然后就是复制其他表的结构创建表:
还是以我上面的两个表(country和cites)演示:
create table newcountry
as
select cid,cname from country;
这样就ok了!
然后就是表的一些操作了(所谓的增删改查了)
这次是使用cites表做演示;
追加一个照片列:alter table cites add (image blob);
图片的数据类型是blob 这个要了解哈!
这样cites 表格的数据结构为:cid, cname, country , image了
然后就是修改列了:这个使用login表做示范以为他有数据类型
alter table login modify (id number(15)) ;
这样就把login 表中的id 的number长度改为了15了
然后就是删除列了:使用cites表做示范我们把刚才添加的image列给删掉
alter table cites drop column image;
然后就是重命名的操作我们使用 login表做演示;把name 重命名为username
alter bable login rename column name to username;
然后就是删除表了;
drop table login;
这样login表就删除了;
插入数据大家应该都会吧!我还是谢谢
insert into tabname (column)values(columnvalues)
接下来就是创建试图使用login表做演示
creaet view loginwiew
as select id , name,passworld from loginn where id=?
相关文章推荐
- SqlServer和Oracle中一些常用的sql语句6 存储过程
- SqlServer和Oracle中一些常用的sql语句1
- SqlServer和Oracle中一些常用的sql语句9 SQL优化
- SqlServer和Oracle中一些常用的sql语句10 特殊应用
- SqlServer和Oracle中一些常用的sql语句9 SQL优化
- SqlServer和Oracle中一些常用的sql语句9 SQL优化
- SqlServer和Oracle中一些常用的sql语句3 行列转换
- SqlServer和Oracle中一些常用的sql语句5 流程控制语句
- SqlServer和Oracle中一些常用的sql语句4 局部/全局变量
- SqlServer和Oracle中一些常用的sql语句7 游标
- SqlServer和Oracle中一些常用的sql语句6 存储过程
- Oracle一些常用SQL语句
- SqlServer和Oracle中一些常用的sql语句10 特殊应用
- SqlServer和Oracle中一些常用的sql语句6 存储过程
- SqlServer和Oracle中一些常用的sql语句8 触发器和事务
- oracle的一些常用的查询的sql语句
- oracle中SQL语句的一些有效常用用法
- SqlServer和Oracle中一些常用的sql语句4 局部/全局变量
- SqlServer和Oracle中一些常用的sql语句3 行列转换
- SqlServer和Oracle中一些常用的sql语句2