常用命令
1.表空间
查看当前用户的表空间
select default_tablespace from dba_users where username=‘username’
2.触发器
查询当前用户下面所有触发器
select * from user_triggers
查看触发器的结构
select trigger_body from user_triggers where trigger_name=触发器名;
启动触发器
ALTER TRIGGER 触发器名 ENABLE ;
禁用触发器
ALTER TRIGGER 触发器名 DISABLE;
禁用某个表所有触发器
ALTER TABLE 表名 DISABLE TRIGGER all;
3.表信息
查询表所有信息
select * from user_tab_cols where table_name=‘表名’;查全部字段
select COLUMN_NAME,DATA_TYPE,DATA_LENGTH from user_tab_cols where table_name=‘表名’; 查部分字段
4.表字段修改
–修改表字段
–添加
alter table 表名 add (字段 NUMBER default 0 not null);
comment on column 表名.字段 is ‘是否重置密码 0否 1是’;
–修改类型
alter table 表名 modify (字段名 number(18,2));
5.获取uuid
select lower(sys_guid()) from dual;
6.视图
SELECT DBMS_METADATA.GET_DDL(‘VIEW’,‘视图名’) FROM DUAL; 查询视图的创建语句
7.取字符串长度length()
select length(‘1461’) from dual
8.字符串截取substr()
select substr(‘1461’,2) from dual
9.修改字段的默认值
alter table 表名 modify 字段名 default 默认值;
10.补位
select replace(lpad(‘1’,6),’ ',‘0’) from dual
11.获取指定字段中某个字符的下标(索引)–用于字符串截取
substr(url,INSTR(url, ‘http://’, 1, 1)+7,INSTR(url, ‘:’, -1, 1)-8)
《注意点:-1获取最后出现位置,1第一次出现位置》
12.查重复字段
select cfbh,count(1) from dim_hy_cfqkb group by cfbh having count(1)>1
13.字符串转数字 to_number()
14.查询视图结构
select text from user_views where view_name=‘DIY_VIEW’;
all_tab_cols / all_tab_columns 查看所有用户下的表及视图结构
user_tab_cols / user_tab_columns 查看当前用户下的表及视图结构
user_col_comments 查看当前用户下表及视图中字段名称及字段注释
all_col_comments 查看所以用户下表及视图中字段名称及字段注释
单个实例启动
遇到问题
**
ORA-12505, TNS:listener does not currently know of SID given in
connect descriptor
**
查看监听状态—注意:在oracle用户下执行
lsnrctl status
启动命令
0.su - oracle
1.export ORACLE_SID=testdb
2.sqlplus '/as sysdba'
3.startup
案例如下