Demo entry 6785685

蔡明恒

   

Submitted by anonymous on Mar 19, 2019 at 07:12
Language: SQL. Code size: 517 Bytes.

DECLARE V_COUNT NUMBER;-- 数量标志
BEGIN
	-- 查看表是否存在,存在删除
	SELECT
		COUNT( * ) INTO V_COUNT 
	FROM
		USER_TABLES UT 
	WHERE
		UT.TABLE_NAME = 'TEST_ONE';
	IF
		V_COUNT > 0 THEN
			EXECUTE IMMEDIATE 'DROP TABLE TEST_ONE';
	END IF;
	-- 建表
	EXECUTE IMMEDIATE '
	CREATE TABLE TEST_ONE (
	ID VARCHAR2(10),
	NAME VARCHAR2(30))';
		-- 建立索引
	EXECUTE IMMEDIATE 'CREATE INDEX TEST_ONE_INDEX1 ON TEST_ONE ( ID )';
	-- 添加主键约束
	EXECUTE IMMEDIATE 'ALTER TABLE TEST_ONE ADD CONSTRAINT PK_ID PRIMARY KEY (ID)';
END;

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).