科技资讯眺望|Oracle常用命令大全

1.create user username identified by password;// 建用户名和密码 oracle ,oracle
2.grant connect,resource,dba to username;// 授权 grant
connect,resource,dba,sysdba to username;
3.connect username/password// 进入 。
4.select table_name,column_name from user_tab_columns where
table_name='mview_log';// 查询表中的表名 , 字段名等等 。
5. 如何执行脚本 SQL 文件 ? SQL>@PATH/filename.sql;
6.Oracle oledb 提供者在 command 中执行多条 SQL 语句与 SQL SERVER 有少许差
别 ,SQL Server 只需使用 ";" 分割多条 SQL 语句 , 而 Oracle 需要遵守 ORACLE 调用规范 ,
即除分号分割外 , 还需以 begin /end; 包围语句体 .
使用 C# 描述应如下所示 :
this.oleDbCommand1.CommandText = "begin INSERT INTO GROUP_INFO
(GROUP_ID, GROUP_NAME) VALUES (1, \'2\'); INSERT INTO
GROUP_INFO(GROUP_ID, GROUP_NAME) VALUES (2, \'2\'); end;";
7. 查询用户下的所有表 select distinct table_name from user_tab_columns;
8. 如何搜索出前 N 条记录? Select a.*,rownum from (select * from cardkind order by
cardkind ) a where rownum 9. 查找用户下的所有表: select * from tab;
2 、显示当前连接用户
SQL> show user
3 、查看系统拥有哪些用户
SQL> select * from all_users;
4 、新建用户并授权
SQL> create user a identified by a;( 默认建在 SYSTEM 表空间下 )
SQL> grant connect,resource to a;
5 、连接到新用户
SQL> conn a/a
6 、查询当前用户下所有对象
SQL> select * from tab;
7 、建立第一个表
SQL> create table a(a number);
8 、查询表结构
SQL> desc a
9 、插入新记录
SQL> insert into a values(1);
10 、查询记录
SQL> select * from a;
11 、更改记录
SQL> update a set a=2;
12 、删除记录
SQL> delete from a;
13 、回滚
SQL> roll;
SQL> rollback;
14 、提交
SQL> commit;
select * from
(select t.*,dense_rank() over (order by cardkind) rank from cardkind t)
where rank = 2;
46. 如何在字符串里加回车 ?
select 'Welcome to visit'||chr(10)||'www.CSDN.NET' from dual ;
47. 中文是如何排序的?
Oracle9i 之前 , 中文是按照二进制编码进行排序的 。
在 oracle9i 中新增了按照拼音、部首、笔画排序功能 。 设置 NLS_SORT 值
SCHINESE_RADICAL_M 按照部首(第一顺序)、笔划(第二顺序)排序
SCHINESE_STROKE_M 按照笔划(第一顺序)、部首(第二顺序)排序
SCHINESE_PINYIN_M 按照拼音排序
48. Oracle8i 中对象名可以用中文吗?
可以
49. 如何改变 WIN 中 SQL*Plus 启动选项?
SQL*PLUS 自身的选项设置我们可以在 $ORACLE_HOME/sqlplus/admin/glogin.sql 中
设置 。
50. 怎样修改 oracel 数据库的默认日期 ?
alter session set nls_date_format='yyyymmddhh24miss';
OR
可以在 init.ora 中加上一行
nls_date_format='yyyymmddhh24miss'
51. 如何将小表放入 keep 池中 ?
alter table xxx storage(buffer_pool keep);
52. 如何检查是否安装了某个 patch?
check that oraInventory
53. 如何使 select 语句使查询结果自动生成序号 ?
select rownum,COL from table;
54. 如何知道数据库中某个表所在的 tablespace?
select tablespace_name from user_tables where table_name='TEST';