[英]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.