美文网首页
oracle 操作

oracle 操作

作者: hochoy | 来源:发表于2019-12-30 17:26 被阅读0次

    sqlplus /nolog

    conn username/password

    select table_name from user_tables; --查看当前登录的用户的表:

    SET LONG3000;

    SET PAGESIZE0;

    SELECT DBMS_METADATA.GET_DDL('TABLE','table_name')from dual; -- 查看表结构 ,table_name 换成对应表名

    -- 获取 HOCHOY_T_DYNAMIC_INFO 表字段:

    -- table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等

    SELECT * FROM USER_TAB_COLUMNSWHERE TABLE_NAME='HOCHOY_T_DYNAMIC_INFO';

    -- 获取 HOCHOY_T_DYNAMIC_INFO 表字段注释

    -- TABLE_NAME,COLUMN_NAME,COMMENTS

    SELECT * FROM USER_COL_COMMENTSWHERE TABLE_NAME ='HOCHOY_T_DYNAMIC_INFO';

    -- 获取 HOCHOY_T_DYNAMIC_INFO 表注释

    -- TABLE_NAME,TABLE_TYPE,COMMENTS

    SELECT * FROM USER_TAB_COMMENTSWHERE TABLE_NAME ='HOCHOY_T_DYNAMIC_INFO';

    -- <<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>

    -- <<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>

    -- <<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>

    -- ------------------------------------------------------------------Oracle 创建 tablespace / user / 授权 步骤 ---------------------------------------------------------------

    -- oracle查看表空间及相应文件所在路径,并创建表空间

    col file_namefor a60; -- 格式化 FILENAME 字段,只显示60个字符

    set linesize300;  -- 输出一行字符个数为100

    SELECT tablespace_name,file_id,file_name,round(bytes / (1024 *1024), 0) total_spaceFROM dba_data_files;

    create tablespace HOCHOY_T datafile'/home/oracle/app/oracle/oradata/orcl/HOCHOY_T01.dbf' size 300M autoextendon next 50M maxsize unlimited;

    -- 查看临时表空间及相应文件所在路径,并创建临时表空间

    select TABLESPACE_NAME,FILE_NAME, AUTOEXTENSIBLE,round(bytes / (1024 *1024), 0) total_space,round(MAXBYTES / (1024 *1024), 0) max_spacefrom dba_temp_files;

    create temporary tablespace TEMPORARY_HOCHOY_T tempfile'/home/oracle/app/oracle/oradata/orcl/HOCHOY_T_TEMP.dbf' size 300M autoextendon next 50M maxsize unlimited extent managementlocal;

    --创建用户 -- 用户名不区分大小写(Oracle 11g)

    create user HOCHOY_T identifiedby HOCHOY_T

    default tablespace HOCHOY_T

    temporary tablespace TEMPORARY_HOCHOY_T

    account unlock;

    -- 查看用户

    select USERNAME,USER_ID, ACCOUNT_STATUS, DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE,PASSWORD_VERSIONSFROM DBA_USERSWHERE ROWNUM =1 ORDER BY CREATEDDESC ; -- DESC DBA_USERS; 查看 DBA_USERS 表结构

    --赋予用户权限

    grant create session          to HOCHOY_T; -- 用户创建session的权限,即登陆权限,允许用户登录数据库

    grant connect,resourceto HOCHOY_T;

    grant create any sequenceto HOCHOY_T;

    grant create any table        to HOCHOY_T;

    grant delete any table        to HOCHOY_T;

    grant insert any table        to HOCHOY_T;

    grant select any table        to HOCHOY_T;

    grant unlimited tablespaceto HOCHOY_T; -- 授予zhangsan用户使用表空间的权限

    grant execute any procedure  to HOCHOY_T;

    grant update any table        to HOCHOY_T;

    grant create any view        to HOCHOY_T;

    grant dbato HOCHOY_T;

    -- 查看用户权限

    SELECT GRANTEE,PRIVILEGE,ADMIN_OPTIONFROM DBA_SYS_PRIVSWHERE GRANTEE ='HOCHOY_T';

    -- oracle查看表空间创建语句

    SELECT dbms_lob.substr(DBMS_METADATA.GET_DDL('TABLESPACE', TS.tablespace_name))FROM DBA_TABLESPACES TSwhere TS.TABLESPACE_NAME ='COBUB';

    desc DBA_TABLESPACES;  -- 可以查看 DBA_TABLESPACES 表结构

    -- Oracle 数据库导出

    exp minxing123/minxing123 file=/home/oracle/20191207/HOCHOY.dmp log=/home/oracle/20191207/HOCHOY_exp.logfull = y;

    -- Oracle 数据库导入

    imp HOCHOY_T/HOCHOY_T file=/home/oracle/20191107/HOCHOY.dmp ignore=yfull=y

    -- <<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>

    -- <<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>

    -- <<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>

    -- 设置sqlplus模式显示总行数(当前连接生效)

    set pagesize300;      -- 输出每页行数为300,缺省为24,为了避免分页,可设定为0

    show pagesize;          --查看目前的pagesize

    -- 设置sqlplus模式显示行宽度(当前连接生效):

    show linesize;          --查看当前的linesize宽度

    set linesize300;      --设置linesize宽度

    相关文章

      网友评论

          本文标题:oracle 操作

          本文链接:https://www.haomeiwen.com/subject/znvmoctx.html