我正在尝试确定列是否是oracle数据库中的主键。
我有以下sql:
SELECT cols.column_name
FROM all_constraints as cons, all_cons_columns as cols
WHERE (cols.table_name = 'TABLE_NAME'
AND cols.columnName= 'SRC_CODE'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cons.status = 'ENABLED'
AND lower(cons.owner)='resmaid')
ORDER BY cols.table_name
我收到以下错误:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:852)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1153)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1275)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1477)
at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:392)
有一段时间这个sql可能有用,不能记得什么时候(大约2年前)。
这很紧急,因为我需要连接到这个数据库并进行一些数据插入。
提前致谢
答案 0 :(得分:5)
我修好了。
两件事。 1.删除表名称别名中使用的“AS” 2. column_name在where子句
中拼写错误请参阅下文
SELECT cols.column_name
FROM all_constraints cons,
all_cons_columns cols
WHERE (cols.table_name = 'TABLE_NAME'
AND cols.column_Name = 'SRC_CODE'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cons.status = 'ENABLED'
AND lower(cons.owner) = 'resmaid')
ORDER BY cols.table_name;
答案 1 :(得分:0)
SELECT cols.column_name
--modify FROM all_constraints as cons, all_cons_columns as cols
FROM all_constraints cons, all_cons_columns cols
WHERE (cols.table_name = 'TABLE_NAME'
--modify AND cols.columnName= 'SRC_CODE'
AND cols.column_name= 'SRC_CODE'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cons.status = 'ENABLED'
AND lower(cons.owner)='resmaid')
ORDER BY cols.table_name