频道栏目
首页 > 资讯 > 其他综合 > 正文

数据库存储过程

17-10-18        来源:[db:作者]  
收藏   我要投稿

spool elb.log

set sqlblanklines on

set feedback off

set define off

set serveroutput on

-- ---------------------------------------- USER_T ----------------------------------------

prompt create table USER_T ...

-- If the table is exists,drop it ...

DECLARE

v_table_exists number := 0;

BEGIN

select count(1) into v_table_exists

from user_tables t

where t.TABLE_NAME = 'USER_T';

dbms_output.put_line('USER_T v_table_exists: ' || v_table_exists);

if(v_table_exists > 0) then

execute immediate 'drop table USER_T';

end if;

END;

/

-- If the primary key is exists,drop it ...

DECLARE

v_pk_exists number := 0;

BEGIN

select count(1) into v_pk_exists

from USER_CONSTRAINTS t

where t.TABLE_NAME = 'USER_T' and t.CONSTRAINT_NAME = 'USER_PK';

dbms_output.put_line('USER_T v_pk_exists: ' || v_pk_exists);

if(v_pk_exists > 0) then

execute immediate 'alter table USER_T drop constraint USER_PK';

end if;

END;

/

-- Create table

create table USER_T

(

id VARCHAR2(100) not null,

username VARCHAR2(2000),

age VARCHAR2(100),

gender VARCHAR2(255),

address VARCHAR2(100)

)

tablespace TS_NAME

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 16K

next 8K

minextents 1

maxextents unlimited

);

-- Create/Recreate primary, unique and foreign key constraints

alter table USER_T

add constraint USER_PK primary key (ID)

using index

tablespace TS_NAME

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

相关TAG标签
上一篇:Hadoop解除安全模式的两种方法
下一篇:SQL必知必会知识点
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站