我试图在我的一个pl/sql脚本中使用来自oracle的connect命令。
我想要实现的是能够切换到脚本内部的不同上下文(例如,以用户身份登录,然后在某个点切换到sys dba)。
我目前的做法如下:
sqlplus user/password@/数据库:1521/[email protected]
complete.sql的内容

DECLARE
     -- declare
     v_scriptInserted varchar2(1);
     v_booleanFalse varchar2(1) := '0';
BEGIN
    SELECT CASE WHEN COUNT(*) >= 1 THEN 1 ELSE 0 END INTO v_scriptInserted FROM SCHEMA_HISTORY WHERE SCRIPT = '&v_SCRIPTNAME';
       IF v_scriptInserted = booleanFalse THEN
       -- do Stuff with user privilidges and after this is done switch to sysdba
       CONNECT sys/oracle@database:1521/orcl AS SYSDBA
       -- do magic here with sysdba
       -- SWITCH CONTEXT BACK TO User
       DISCONNECT;
    END IF;
END;
/

但是,无论我如何尝试脱离连接序列,part:1521都会被误解为bind varible(sp2-0552)。
我已经在stack overflow周围搜索了一下,找到了相关的文章:
-How to escape ":" in Oracle dynamic SQL and also have bind variables?
-Oracle PL/SQL - How to escape colon (:), being misinterpreted for bind variable
不管我怎么努力,似乎都没用。
我目前的做法是:
CONNECT sys/oracle@database:1521/orcl AS SYSDBA
CONNECT sys/oracle@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=database)(PORT=1521))(CONNECT_DATA=(SID=orcl)) AS SYSDBA
CONNECT sys/oracle@database\:1521/orcl AS SYSDBA
SELECT 'sys/oracle@database' || ':' || '1521/orcl AS SYSDBA' INTO v_dest_connstring FROM DUAL;CONNECT 'v_dest_connstring'
CONNECT 'sys/oracle@database:1521/orcl AS SYSDBA'
CONNECT ''sys/oracle@database:1521/orcl AS SYSDBA''
CONNECT '''sys/oracle@database:1521/orcl AS SYSDBA'''
CONNECT "sys/oracle@database:1521/orcl AS SYSDBA"
CONNECT ""sys/oracle@database:1521/orcl AS SYSDBA""
CONNECT """sys/oracle@database:1521/orcl AS SYSDBA"""
任何帮助都是非常感谢的。
谢谢,
==============================================
编辑:
1)具有CONNECT sys/oracle@"database:1521/orcl"的想法
1.1)带“
`CONNECT sys/oracle@"database:1521/orcl" AS SYSDBA
    *
FEHLER in Zeile 16:
ORA-06550: Zeile 16, Spalte 5:
PLS-00103: Encountered the symbol "CONNECT"`

1.2)与'
CONNECT sys/oracle@'database:1521/orcl' AS SYSDBA
    *
FEHLER in Zeile 17:
ORA-06550: Zeile 17, Spalte 5:
PLS-00103: Encountered the symbol "CONNECT" when expecting one of the
following

2)由于1521是默认端口,因此将端口保留为可选端口:
CONNECT sys/oracle@database/orcl AS SYSDBA
    *
FEHLER in Zeile 17:
ORA-06550: Zeile 17, Spalte 5:
PLS-00103: Encountered the symbol "CONNECT" when expecting one of the
following

3)缺少最后一个括号,@(description=(address=(protocol=tcp)(host=database)(port=1521))(conne ct_data=(sid=orcl))作为sysdba
CONNECT sys/oracle@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=database)(PORT=1521))(CONNE‌​CT_DATA=(SID=orcl))) AS SYSDBA
    *
FEHLER in Zeile 17:
ORA-06550: Zeile 17, Spalte 5:
PLS-00103: Encountered the symbol "CONNECT" when expecting one of the
following

最佳答案

CONNECT是一个sqlplus命令,不可能在pl\sql块中使用它。您必须将其从块中取出,并将其单独放入sqlplus脚本文件中(如果需要)。

关于database - Oracle PL/SQL-如何转义冒号(:),因为Connect中的绑定(bind)变量被误解,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34943299/

10-16 17:20