简体   繁体   English

在oracle中创建表查询-ORA 00922

[英]create table query in oracle- ORA 00922

I am trying to create a table in oracle 11g, that should be created only the first time, as in if it doesn't exist. 我正在尝试在oracle 11g中创建一个表,该表应该仅在第一次创建,就好像它不存在一样。 If it exists it should not create the table. 如果存在,则不应创建该表。

create table IF NOT EXISTS sample_temp
(
    SFL_ID number(10) not null,
    STM_ID number(10) not null,
    FIL_ID number(10) not null,
    SYSTEM_GENERATED_FL char null    ,
    SFL_DELETE_FL char not null,
    SFL_VERSION_ID number(10) not null,
    PTN_ID number(10) not null); 

This gives an ORA- 00922 error, telling a syntax error near the words "if not". 这会产生ORA-00922错误,在单词“如果不是”附近告诉语法错误。 What am I doing wrong? 我究竟做错了什么? Is 'if not exists' not supported in Oracle? Oracle不支持“如果不存在”吗? then how should I go about doing it? 那我该怎么做呢? I am actually trying to create this via jdbc. 我实际上正在尝试通过jdbc创建它。

Oracle does not support the IF NOT EXISTS syntax. Oracle不支持IF NOT EXISTS语法。 The easiest solution would be to run another query to check whether table already exists in the schema of your database. 最简单的解决方案是运行另一个查询,以检查表是否已存在于数据库的架构中。

If you are connecting as a user orcl , and the table you are trying to create is going to be on the same schema, then you can do this 如果您以用户orcl身份进行连接,而您要创建的表将位于同一模式下,则可以执行此操作

 select count(*) from user_tables where table_name=upper('yourtable');

if the count returns 1, then you know that the table exists and you can skip the table creation process. 如果计数返回1,则说明该表存在,并且可以跳过表创建过程。 Otherwise go ahead and create the table. 否则,继续创建表。

You can't use "if not exists" command recheck if table already exists or not. 您不能使用“如果不存在”命令重新检查表是否已经存在。 You can do one thing : you can use query USER_TABLES or DBA_TABLES to check if your table exists or not .If it exists then do what you want to do and if it doesn't exists then you can create a new one . 您可以做一件事:您可以使用查询USER_TABLES或DBA_TABLES来检查您的表是否存在。如果存在,则执行您想做的事情,如果不存在,则可以创建一个新表。

You can simply send the CREATE TABLE statement to the Oracle engine. 您只需将CREATE TABLE语句发送到Oracle引擎即可。 If the table exists, this will return an error telling you the table already exists. 如果该表存在,则将返回一个错误,告诉您该表已存在。 If you need this for further processing in your code, you can just capture this error message. 如果需要在代码中进行进一步处理,则只需捕获此错误消息即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Apex Oracle SQL中创建表/序列/触发器-ORA-00922 / ORA-00907 / ORA-00922 - Create Table / Sequence / Trigger in Apex Oracle SQL - ORA-00922 / ORA-00907 / ORA-00922 创建表查询中的if语句-Oracle- - If statement inside create table query -Oracle- 我正在使用oracle 10g创建表,但在查询中显示“ ORA-00922:缺少或无效的选项” - Im using oracle 10g to create table but it is showing “ORA-00922: missing or invalid option” and in the query ORA-00922: 无法使用 ojdbc 在 oracle 中创建表 - ORA-00922 : Cannot Create table in oracle using ojdbc Oracle SQL“立即执行” ORA-00922 / 06512创建表 - Oracle SQL “EXECUTE IMMEDIATE” ORA-00922/06512 Create Table 尝试在Oracle中创建分区表时为什么会收到ORA-00922? - Why do I get an ORA-00922 when trying to create a partitioned table in Oracle? Oracle12c - 无法创建带有分区的表“ORA-00922:缺少或无效选项” - Oracle12c - Can't create a table with partitioning "ORA-00922: missing or invalid option" Oracle-创建一个临时结果集以供查询使用 - Oracle- create a temporary resultset for use in a query ORA-00922: 缺少或无效的选项 Oracle 表创建错误 - ORA-00922: missing or invalid option Error on Oracle table creation “ ORA-00922:缺少或无效的选项” SQL创建表错误 - “ORA-00922: missing or invalid option” SQL create table error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM