ORA-39700:DATABASE MUST BE OPENED WITH UPGRADE OPTION

本文详细介绍了使用Oracle数据库升级工具解决10.2版本数据库升级后无法正常打开的问题,包括使用catalog.sql和catproc.sql脚本更新数据字典、通过startup upgrade命令开启数据库、运行utlrp.sql脚本重新编译无效对象、使用migrate启动选项执行升级、以及使用Oracle Database Upgrade Assistant图形工具进行升级等方法。

ORA-01092:ORACLE INSTANCE TERMINATED DISCONNECTION

ORA-00740:BOOTSTRAP PROCESS FAILURE

ORA-39700:DATABASE MUST BE OPENED WITH UPGRADE OPTION



前几天把我的测试系统REDHAT LINUX AS4+ORACLE10.2.0.1用 oracle新发布的p6810189_10204_Linux-x86.zip升级到了10.2.0.4,然后打开数据库时打不开,并就错误:
alterlog有如下内容:
ORA-39700: database must be opened with UPGRADE option
Thu Feb 28 23:02:49 2008
Error 704 happened during db open, shutting down database
USER: terminating instance due to error 704
Instance terminated by USER, pid = 1635
ORA-1092 signalled during: ALTER DATABASE OPEN...

按照提示,SQL>startup update
数据库可以打开,操作也正常.

但是如果关闭数据库重起后还是报以上错误,还是要加update的参数才能打开.


方法一(很遗憾使用该方法执行完第一个SQL句后 没有返回来 假死在那了)

因为数据库升级以后数据字典的内容被修改了,需要运行catalog.sql和catproc.sql这两个脚本再更新数据字典。
处理方法如下:
SQL>startup upgrade;
SQL>@ORACLE_HOME\rdbms\admin\catupgrd.sql;
这个脚本会执行比较长时间,我在虚拟机上用了快22分钟.
Total Upgrade Time: 00:21:58
执行完成以后,关闭数据库,再使用正常模式启动数据库.
再运行一下utlrp.sql这个脚本来重新编译一下一些无效的对象
SQL>startup
SQL>@ORACLE_HOME\rdbms\admin\utlrp.sql;
...
OBJECTS WITH ERRORS
-------------------
                  0
...
ERRORS DURING RECOMPILATION


方法二   这里使用migrate 启动选项 并且执行最后一个SQL语句

升级分为2个步骤:安装升级包、升级数据库

升级数据库步骤:
1、sqlplus 登录 /as sysdba
2、确认版本:select * from v$version
3、shutdown immediate后再startup migrate(迁移模式)
4、运行DB补丁脚本升级DB:SQL> @$ORACLE_HOME/rdbms/admin/catpatch.sql


方法三 使用图形工具

.3.1 Upgrading a Release 10.2 Database using Oracle Database Upgrade Assistant

After you install the patch set, you must perform the following steps on every database associated with the upgraded Oracle home:


Note:

If you do not run the Oracle Database Upgrade Assistant as described in this section, then the following errors are displayed:

ORA-01092: ORACLE instance terminated.

ORA-39700: database must be opened with UPGRADE option.


  1. Log in as the Oracle software owner user.

  2. Set the values for the environment variables $ORACLE_HOME, $ORACLE_SID and $PATH.

  3. For single-instance installations, if you are using Automatic Storage Management, start the Automatic Storage Management instance.

  4. For Oracle single-instance installations, start the listener as follows:

    $ lsnrctl start
    
  5. Run Oracle Database Upgrade Assistant either in the interactive or noninteractive mode:

    Interactive mode:

    Enter the following command from the command prompt:

    $ dbua
    

    Complete the following steps displayed in the Oracle Database Upgrade Assistant screen:

    1. On the Welcome screen, click Next.

    2. On the Databases screen, select the name of the Oracle Database that you want to update, then click Next.


      Note:

      For Oracle RAC, enter the SYS password to do the upgrade.

    3. On the Recompile Invalid Objects screen, select the Recompile the invalid objects at the end of upgrade option, then click Next.

    4. If you have not taken the back up of the database earlier, on the Backup screen, select the I would like to take this tool to backup the database option, stipulate the Path, then click Next.

    5. On the Summary screen, check the summary, then click Finish.

    6. On the End of Database Upgrade Assistant's Upgrade Results screen, click Close to exit from Oracle Database Upgrade Assistant.


    Note:

    If you are upgrading a database having dbcontrol configured in non-secure mode, after upgrade dbconsole will run in secure mode.

    Noninteractive mode:

    Enter the following command to upgrade Oracle Database using Oracle Database Upgrade Assistant in noninteractive mode:

    $ dbua -silent -dbname $ORACLE_SID -oracleHome 
    $ORACLE_HOME -sysDBAUserName UserName -sysDBAPassword SYS_password 
    -recompile_invalid_objects true
    
  6. If you are using the Oracle Recovery Manager catalog, enter the following command:

    $ rman catalog username/password@alias
    RMAN> UPGRADE CATALOG;
    
  7. For Oracle RAC installations, start any database services that you want to use by entering the following command:

    $ srvctl start service -d db_name -s service_name
    


### 解决 Oracle 数据库中的 ORA-00998 和 ORA-06512 错误 在 Oracle 数据库中,当执行动态 SQL 时,若未为表达式提供列别名,可能会遇到 `ORA-00998: must name this expression with a column alias` 错误。此错误通常出现在使用 `PIVOT` 操作或子查询中未明确指定列别名的情况下。此外,`ORA-06512` 错误表示在 PL/SQL 过程中某一行发生异常,通常与前一个错误相关联,指示错误发生的行号[^1]。 例如,在使用 `PIVOT` 时,若查询中包含未命名的表达式,Oracle 会抛出 `ORA-00998` 错误: ```sql SELECT * FROM ( SELECT year, product_name, amount FROM sales_data ) PIVOT ( SUM(amount) FOR product_name IN (10 AS "Electronics", 20 AS "Clothing") ); ``` 在上述查询中,`IN` 子句中的 `10 AS "Electronics"` 和 `20 AS "Clothing"` 是合法的,因为它们为每个值提供了别名。但如果遗漏了 `AS` 子句,如 `FOR product_name IN (10, 20)`,Oracle 会抛出 `ORA-00998` 错误,因为它无法为这些值生成列名[^1]。 在 PL/SQL 块中,若使用 `EXECUTE IMMEDIATE` 执行动态 SQL 时未正确处理列别名,也可能触发 `ORA-06512` 错误。例如: ```plsql DECLARE v_sql VARCHAR2(4000); BEGIN v_sql := 'SELECT * FROM ( SELECT year, product_name, amount FROM sales_data ) PIVOT ( SUM(amount) FOR product_name IN (10, 20) )'; EXECUTE IMMEDIATE v_sql; END; ``` 上述代码会因 `IN` 子句中未指定列别名而抛出 `ORA-00998` 错误,并在 `EXECUTE IMMEDIATE` 所在行触发 `ORA-06512` 错误。为避免此类错误,必须确保所有 `PIVOT` 列都具有明确的列别名[^1]。 #### 正确的写法如下: ```plsql DECLARE v_sql VARCHAR2(4000); v_in_list VARCHAR2(1000) := ''; CURSOR c_products IS SELECT DISTINCT product_name FROM sales_data ORDER BY product_name; BEGIN FOR prod IN c_products LOOP v_in_list := v_in_list || '''' || prod.product_name || ''' AS "' || prod.product_name || '", '; END LOOP; IF LENGTH(v_in_list) > 0 THEN v_in_list := RTRIM(v_in_list, ', '); END IF; v_sql := 'SELECT * FROM ( SELECT year, product_name, amount FROM sales_data ) PIVOT ( SUM(amount) FOR product_name IN (' || v_in_list || ') ) ORDER BY year'; EXECUTE IMMEDIATE v_sql INTO ...; -- 正确处理结果集 END; ``` 在上述代码中,`v_in_list` 动态构建了 `PIVOT` 的 `IN` 子句,并为每个产品名称提供了列别名(如 `'Electronics' AS "Electronics"`),从而避免 `ORA-00998` 错误。此外,`EXECUTE IMMEDIATE` 正确地将结果存储到变量中,防止 `ORA-06512` 错误的发生。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值