写一个txt文件  是创建表的  执行这脚本文件时候 判断这个表是否存在 如果存在 就 不执行,不存在就创建 CREATE TABLE "NICK"."A" 
   ( "ID" VARCHAR2(10), 
"NAME" VARCHAR2(10)
   ) 麻烦大家给个sql 语句 谢谢

解决方案 »

  1.   

    Oracle中没有类似于sql server中的exists语句。
    如果要想实现,就必须写PL/SQL程序。
      

  2.   

    既然是创建表,那就前面加一个 drop table好了,大不了重建表。第一次执行,报错也可以无视。
      

  3.   


    表不存在 drop  就报错 提示表不存在
      

  4.   


    if exists(select 1 from user_tables where table_name='表名')
    ...?
      

  5.   

    oracle这样是不允许的。适合sql server
      

  6.   

    试了下,还真不行。会报ora-06550错误
    “函数或伪列exists只能在sql语句中使用”
      

  7.   

    你要是不嫌麻烦可以改成块的写法。
    declare
    n_cnt number;
    begin
    select count(*) into n_cnt from user_tables where table_name='A';
    if n_cnt>0 then
       execute immediate 'drop table "A"';
    end if;
    execute immediate 'CREATE TABLE "A"  
      ( "ID" VARCHAR2(10),  
    "NAME" VARCHAR2(10)
       )';
    end;
      

  8.   

     
    写在块里面 sqlplus  执行的时候 不能在一个脚本里面 执行 多个块 因为表有几百张  exists能用在建表时候判断是否 存在呢 要建几百张表 有没有其他的办法 先判断在执行 一定要用sqlplus 执行sql语句文件呢?谢谢
      

  9.   

    执行过程:
    Microsoft Windows [Version 5.2.3790]
    (C) Copyright 1985-2003 Microsoft Corp.C:\Documents and Settings\Administrator>sqlplus / as sysdbaSQL*Plus: Release 10.1.0.2.0 - Production on Thu Feb 9 11:25:59 2012Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining optionsSQL> @c:\aa.txt
    1PL/SQL procedure successfully completed.2PL/SQL procedure successfully completed.3PL/SQL procedure successfully completed.SQL>脚本内容:
    set serveroutput on declare
    n_cnt number;
    begin
    select count(*) into n_cnt from dual;
    dbms_output.put_line(1);
    end;
    /declare
    n_cnt number;
    begin
    select count(*) into n_cnt from dual;
    dbms_output.put_line(2);
    end;
    /declare
    n_cnt number;
    begin
    select count(*) into n_cnt from dual;
    dbms_output.put_line(3);
    end;
    /
      

  10.   

    可以用存储过程生成脚本,然后utl_file写到操作系统,然后调用执行
      

  11.   


    执行 效率那个好呢 块里面的 sql 存储过程里面都有  相比用存储过程建表 有什么好处吗
      

  12.   

    declare  在 plsql里面那个文件夹能看到呢 比如想继续改 继续写
      

  13.   

    declare
    begin
    exception
    end
    是最基本的plsql单元。
    像存储过程,包,函数,触发器等等都是基于这个最基础的单元的。
    只不过那些有名字。
      

  14.   

    这个需要些批处理文件来处理.
    从ALL_TABLE里面查找是否存在该名称的表格
      

  15.   

    使用数据字典,可以查到,user_tables.