【问题标题】:How to assign result of a select into sqlplus variable如何将选择的结果分配给 sqlplus 变量
【发布时间】:2019-04-14 11:11:01
【问题描述】:

我正在为创建我的表空间的向导编写一个批处理文件。 几天后,我对这个向导的结果是下面的代码。

我创建了一个名为“路径”的变量。 然后我选择我的数据文件位置并将其存储到“路径”中。

因为我不能在我们的创建语句中使用“路径”,所以我在 sqlplus 中定义了一个名为“Loc”的变量,并将“路径”的值传递给“Loc”。

这是我的脚本:

sqlplus >var path varchar2(100) 
sqlplus >exec select substr(name, 1, instr(name, 'USER') - 1) || 'test.ora' into :path from v$datafile where name like '%USER%'; 

sqlplus >def loc=:path

sqlplus >CREATE TABLESPACE test
1 > LOGGING 
2 >     BLOCKSIZE 16384  DATAFILE '&loc' SIZE 100M REUSE
3 > AUTOEXTEND
4 >     ON NEXT  50M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL 
5 > SEGMENT SPACE MANAGEMENT AUTO;

我的脚本的结果是:

SQL> CREATE TABLESPACE test
  2  LOGGING
  3  BLOCKSIZE 16384  DATAFILE '&loc' SIZE 100M REUSE
  4   AUTOEXTEND
  5   ON NEXT  50M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL
  6   SEGMENT SPACE MANAGEMENT AUTO;
old   3: BLOCKSIZE 16384  DATAFILE '&loc' SIZE 100M REUSE
new   3: BLOCKSIZE 16384  DATAFILE ':path' SIZE 100M REUSE
CREATE TABLESPACE test
*
ERROR at line 1:
ORA-01119: error in creating database file ':path'
ORA-27040: file create error, unable to create file
OSD-04002: unable to open file
O/S-Error: (OS 123) The filename, directory name, or volume label syntax is
incorrect.

【问题讨论】:

    标签: oracle cmd sqlplus


    【解决方案1】:

    绑定变量在 DDL、静态或其他方面都无济于事。坚持使用替换变量:

    column loc new_value loc
    
    select substr(name, 1, instr(name, 'USER') - 1) || 'test.ora' as loc
    from   v$datafile where name like '%USER%';
    
    create tablespace test
    logging
    blocksize 16384
    datafile '&loc' size 100m reuse
    autoextend on next 50m maxsize unlimited
    extent management local
    segment space management auto;
    

    【讨论】:

      猜你喜欢
      • 2010-10-22
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      相关资源
      最近更新 更多