【问题标题】:Trying to store a procedure in Oracle 11g to monitor tablespace storage试图在 Oracle 11g 中存储一个过程来监控表空间存储
【发布时间】:2016-06-03 18:18:50
【问题描述】:

我正在尝试将此代码存储在 Oracle 中,并且每次遇到编译错误。我搜索了没有参数的存储过程,但没有找到解决此问题的解决方案。 这是我要存储的过程:

    CREATE OR REPLACE PROCEDURE Espacio_libre
    BEGIN
    select df.tablespace_name "Tablespace",
    totalusedspace "MB Usados",
    (df.totalspace - tu.totalusedspace) "MB Libres",
    df.totalspace "MB Totales",
    round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))
    "Pct Libre"
    from
    (select tablespace_name,
    round(sum(bytes) / 1048576) TotalSpace
    from dba_data_files 
    group by tablespace_name) df,
    (select round(sum(bytes)/(1024*1024)) totalusedspace, tablespace_name
    from dba_segments 
    group by tablespace_name) tu
    where df.tablespace_name = tu.tablespace_name;
    END Espacio_libre;

/

谢谢大家。

【问题讨论】:

  • 正如“Walid El Oubaha”所说 - 如果没有 INTO 子句,您不能在 PL/SQL 块中使用 SELECT。

标签: sql oracle stored-procedures oracle11g


【解决方案1】:

创建一个视图,它会按照您对这个过程的期望进行。

您不能只在没有INTO 子句和变量的PL/SQL 块中使用select 语句。

您还可以将 Refcursor 创建为 OUT 参数

【讨论】:

    【解决方案2】:
     create GLOBAL TEMPORARY table test22jan16 (tablespace_name varchar2(100),MB_Libres varchar2(100),MB_Totales varchar2(100),Pct_Libre varchar2(100))
    ON COMMIT DELETE ROWS;
    
    insert into test22jan16 
        select df.tablespace_name ,
        (df.totalspace - tu.totalusedspace),
        df.totalspace,
        round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))
        from
        (select tablespace_name,
        round(sum(bytes) / 1048576) TotalSpace
        from dba_data_files 
        group by tablespace_name) df,
        (select round(sum(bytes)/(1024*1024)) totalusedspace, tablespace_name
        from dba_segments 
        group by tablespace_name) tu
        where df.tablespace_name = tu.tablespace_name;
    

    创建一个存储数据的全局临时表,然后使用上述查询将数据存储在此表中

    【讨论】:

    • 为什么 GTT 会有所帮助?这不会提供任何额外的东西。
    • 我以为他想存储数据并使用它提供报告。但是,这也可以在不使用 GTT 的情况下完成
    【解决方案3】:

    当您在 oracle 中创建存储过程时,您使用的是 PL/SQL 代码而不是 SQL。 pl/SQL中的表中没有选择列,[列] 您必须执行“从表中选择列到变量中”。 请参阅下面的文档以了解 PL/SQL 编程的基本知识。 [https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm][1]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多