You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用sqlplus执行SQL脚本遇ORA-12154等错误,如何解决?

通过sqlplus命令行执行SQL脚本失败的排查

我尝试了两种通过sqlplus在命令行执行SQL脚本的方法,但均未成功,请问我哪里操作有误?我原本认为其中一种方法应该可行。

使用的命令

sqlplus username/password@database @create_table_drop_table.sql
sqlplus username/password@database < create_table_drop_table.sql

参考解决建议

正如Alex在评论中提到的,若遇到问题可尝试以下方法:打开您的tnsnames.ora文件,复制粘贴相应内容后使用以下命令:

sqlplus username/password@hostname:port/service_name @create_table_drop_table.sql
sqlplus username/password@hostname:port/service_name < create_table_drop_table.sql

SQL脚本内容(create_table_drop_table.sql)

create table tab_5(id number, col1 varchar2(50), col2 varchar2(50));
drop table tab_5;

错误信息

第一种命令执行错误

sqlplus username/password@database @create_table_drop_table.sql
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

第二种命令执行错误

sqlplus username/password@database < create_table_drop_table.sql
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified


SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM|SYSRAC}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]

内容的提问来源于stack exchange,提问作者noobprogrammer1987

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 12:42:43