简体   繁体   English

表前缀的oracle sql替换变量

[英]oracle sql substitution variable for table prefix

I can't figure this out, I only want to substitute the &&QC_NUM portion, but I get prompted for a &&QC_NUM_Phase1 variable. 我无法弄清楚,我只想替换&& QC_NUM部分,但提示输入&& QC_NUM_Phase1变量。 I thought concating the sub-var with the rest of the string would fix it, but nope. 我认为将sub-var与字符串的其余部分一起使用将可以解决此问题,但不可以。

DECLARE
  c INT;
BEGIN
  SELECT COUNT(*)
  INTO c
  FROM user_tables
  WHERE table_name = upper('QC_'||&&QC_NUM||'_Phase1');
  IF c             = 1 THEN
    EXECUTE immediate 'drop table QC_'||&&QC_NUM||'_Phase1';
  END IF;
END;
/

I am not able to duplicate your error in Oracle 11g (SQL Plus or SQL Developer). 我无法在Oracle 11g(SQL Plus或SQL Developer)中重复您的错误。
I do receive these errors with you annnoymous block: 我确实收到这些错误提示与您有关:

Error report - ORA-06550: line 8, column 7: PL/SQL: ORA-00904: "BOB": invalid identifier ORA-06550: line 4, column 3: PL/SQL: SQL Statement ignored ORA-06550: line 11, column 41: PLS-00201: identifier 'BOB' must be declared ORA-06550: line 11, column 5: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\\n%s" *Cause: Usually a PL/SQL compilation error. 错误报告-ORA-06550:第8行,第7列:PL / SQL:ORA-00904:“ BOB”:无效标识符ORA-06550:第4行,第3列:PL / SQL:SQL语句被忽略ORA-06550:第11行,第41列:PLS-00201:必须声明标识符'BOB'ORA-06550:第11行,第5列:PL / SQL:语句忽略06550。00000-“%s行,%s列:\\ n%s” *原因:通常是PL / SQL编译错误。

When I surround your substitution variable with single quotations, then the substition variable is not interpreted as an identifier, but a string. 当我用单引号括住您的替代变量时,则替代变量将不解释为标识符,而是字符串。

DECLARE
  c INT;
BEGIN
  SELECT COUNT(*)
  INTO c
  FROM user_tables
  WHERE table_name = upper('QC_' ||'&&QC_NUM'||'_Phase1');
  IF c             = 1 THEN
    EXECUTE immediate 'drop table QC_'||'&&QC_NUM'||'_Phase1';
  END IF;
END; 

This executes properly. 这样可以正确执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM