Recompile the invalid object for oracle.

本文介绍Oracle数据库中无效对象产生的原因及处理方法。包括使用内置脚本utlrp.sql重新编译无效对象,跟踪重新编译进度的方法,以及针对特定类型对象如函数、过程等的手动编译指令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. How does the invalid object come?

The Oracle database will invalidate objects if a dependent object is changed. If I rebuild a table, the indexes on that table will become invalid because they use the table'srowids and rebuilding the table changes a row's rowid. It is the same with objects like packages, procedures and functions. 

 

2.Build-in scripts to recompile the invalid objects.

We now have a supported script utlrp.sql located in the $ORACLE_HOME/rdbms/admin/utlrp.sql to do recompile for us.

Below code will list out all the current invalid object and run utlrp.sql to compile all of them.

COLUMN owner format a30
COLUMN object_name format a30 wrap
COLUMN object_type format a30 wrap

SET pages 56 lines 130 feedback off echo off
TTITLE "Report of Invalid Objects In Database" skip 2
SELECT owner, object_name, object_type
  FROM dba_objects
 WHERE status = 'INVALID';
PROMPT "Will now run utlrp.sql to try to recompile objects"
@?/rdbms/admin/utlrp.sql

The following PL/SQL block invokes UTL_RECOMP to recompile invalid objects in the database.
Recompilation time is proportional to the number of invalid objects in the database,
so this command may take a long time to execute on a database with a large number of invalid objects.

Use the following queries to track recompilation progress:

1. Query returning the number of invalid objects remaining. This number should decrease with time.
SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);

2. Query returning the number of objects compiled so far. This number should increase with time.
SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;

This script automatically chooses serial or parallel recompilation based on the number of CPUs
available (parameter cpu_count) multiplied by the number of threads per CPU (parameter parallel_threads_per_cpu).
On RAC, this number is added across all RAC nodes.

UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel recompilation. Jobs are created without instance
affinity so that they can migrate across RAC nodes. Use the following queries to verify
whether UTL_RECOMP jobs are being created and run correctly:

1. Query showing jobs created by UTL_RECOMP
SELECT job_name FROM dba_scheduler_jobs WHERE job_name like 'UTL_RECOMP_SLAVE_%';

2. Query showing UTL_RECOMP jobs that are running
SELECT job_name FROM dba_scheduler_running_jobs WHERE job_name like 'UTL_RECOMP_SLAVE_%';

Below is a sql with a good format to list all the invalid database object.
break on c1 skip 2
set pages 999
col c1 heading 'owner' format a15
col c2 heading 'name' format a40
col c3 heading 'type' format a10
ttitle 'Invalid|Objects'
select 
   owner       c1, 
   object_type c3,
   object_name c2
from 
   dba_objects 
where 
   status != 'VALID'
order by
   owner,
   object_type;

 

3. Recompile with UTL_RECOMP package

EXEC UTL_RECOMP.recomp_serial('schema name');

 

4. compile command for individual object.

For function:

alter function gpcomp1.fn_load_notes_from_jde compile;

For procedure:

alter procedure gpcomp1.updatetemplate compile;

For view

alter view gpcomp1.gamatchedcashapplied compile;

For public synonym, which can only be recompiled by sys

alter public synonym  gpcrfcode  compile

 

Here is a script to recompile invalid PL/SQL packages and package bodies. 

You may need to run it more than once for dependencies, if you get errors from the script.

Set heading off;
set feedback off;
set echo off;
Set lines 999;

Spool run_invalid.sql

select
   'ALTER ' || OBJECT_TYPE || ' ' ||
   OWNER || '.' || OBJECT_NAME || ' COMPILE;'
from
   dba_objects
where
   status = 'INVALID'
and
   object_type in ('PACKAGE','FUNCTION','PROCEDURE')
;
spool off;
set heading on;
set feedback on;
set echo on;
@run_invalid.sql

check the status of oracle component.

select comp_id,  comp_name,  version, status, namespace, schema from dba_registry;

<think>我们正在解决Unity中DLL文件的架构不匹配问题(x86与x64)。用户遇到错误,需要重新编译插件以匹配目标平台。根据用户问题,错误信息通常为:“DllNotFoundException”或“BadImageFormatException”,这通常是因为DLL的架构与Unity项目的目标平台不匹配(例如,在64位环境中使用了32位的DLL,反之亦然)。解决方案的核心是重新编译DLL以匹配目标平台。以下是具体步骤:1.**确认Unity项目的目标平台**:在Unity编辑器中,打开“File>BuildSettings”,查看当前选择的平台(例如,PC平台下是x86还是x64)。2.**获取DLL的源代码**:由于需要重新编译,我们必须有DLL的源代码。如果没有,可能需要联系DLL的提供者获取对应架构的版本。3.**使用匹配的架构重新编译DLL**:-如果目标平台是64位(x64),则编译64位的DLL。-如果目标平台是32位(x86),则编译32位的DLL。4.**在VisualStudio中设置目标平台**:打开DLL的源代码项目,在解决方案配置管理器中,选择对应的平台(如x64或x86)进行编译。5.**替换Unity项目中的DLL**:将新编译的DLL文件(通常为`.dll`文件)放入Unity项目的`Assets`文件夹下的`Plugins`文件夹中(如果没有则创建)。注意:根据平台可能需要放在`Plugins/x86`或`Plugins/x86_64`子文件夹中。6.**设置Unity中DLL的平台兼容性**:在Unity编辑器中,选中DLL文件,在Inspector窗口中设置平台兼容性(例如,勾选对应的平台,并选择CPU架构)。7.**重新加载并测试**:重新启动Unity并运行项目,检查错误是否解决。注意:如果DLL是第三方提供的,且没有源代码,则需要联系供应商获取匹配架构的DLL版本。另外,有时在Unity中,我们也可以尝试通过设置PlayerSettings中的目标架构来匹配现有的DLL。例如,如果DLL是32位的,那么将PlayerSettings中的目标架构设置为x86(32位)可能可以解决问题。但这种方法不适用于64位系统上运行64位程序的情况,因此重新编译为正确架构是更彻底的解决方案。引用说明:虽然提供的引用内容是关于Unreal引擎的修复和优化(如枚举编译问题、蓝图崩溃修复、内部数据重构等),但这些引用与当前问题无关。因此,我们忽略这些引用,专注于UnityDLL架构问题的解决方案。生成相关问题:1.如何检查一个DLL文件是32位还是64位?2.在Unity中如何为不同平台(如Android、iOS)编译原生插件?3.当无法获取DLL源代码时,如何解决架构不匹配问题?</think>### 解决Unity中DLL的x86/x64架构不匹配问题 当Unity项目中遇到`DllNotFoundException`或`BadImageFormatException`错误时,通常是由于原生插件DLL的架构(x86/x64)与Unity构建目标不匹配导致。以下是系统化的解决方案: #### 🔧 核心解决步骤 1. **确认DLL架构** 使用工具检查DLL的架构类型: - Windows:通过 **Dependency Walker** 或 `dumpbin /headers YourDLL.dll | findstr "machine"` - `x86`输出:`8664 machine (x64)` - `x64`输出:`14C machine (x86)` - macOS:`lipo -info YourDLL.bundle` - Unity编辑器日志会明确显示加载失败的原因 2. **统一构建目标** - **Unity设置**: ```text File > Build Settings > Player Settings > - PC端:Target Architecture 勾选 x86 或 x64 - Android:Target Architectures 选择 ARMv7 或 ARM64 ``` - **DLL放置路径**: ```text Assets/ └── Plugins/ ├── x86/ → 32位DLL ├── x86_64/ → 64位DLL └── Android/ ├── armv7/ → ARMv7 DLL └── arm64/ → ARM64 DLL ``` 3. **重新编译DLL(必要操作)** - **Visual Studio 设置**: ```csharp 解决方案资源管理器 > 右键项目 > 属性 → 配置管理器:新建 x86 或 x64 平台 → C/C++ > 代码生成:Runtime Library 必须匹配Unity(通常为 /MD) ``` - **关键编译参数**: - Windows x86:`/platform:x86` - Windows x64:`/platform:x64` - Android ARMv7:`-march=armv7-a` - Android ARM64:`-march=armv8-a` 4. **Unity编辑器特殊处理** - 如果编辑器是64位(默认)但DLL是32位: - 临时方案:启动Unity时添加命令行参数`-force-glcore` - 永久方案:重新编译DLL为x64版本[^3] #### ⚠️ 常见陷阱 1. **混合架构依赖链** - 当主DLL依赖其他x86库时,整个链需统一架构 - 解决方案:用`dumpbin /dependents YourDLL.dll`检查依赖 2. **.NET版本冲突** - Unity 2020+默认使用`.NET Standard 2.1` - 编译DLL时需指定:`<TargetFramework>netstandard2.1</TargetFramework>` 3. **托管桥接层错误** ```csharp // C#声明必须完全匹配DLL导出 [DllImport("YourPlugin")] private static extern int Init(IntPtr config); // 参数类型需精确匹配 ``` #### ✅ 验证流程 1. 在Unity编辑器日志中搜索`Plugin loaded`确认加载成功 2. 空场景调用`DLL`基础函数测试 3. 构建最小可执行程序测试目标平台 > 对于第三方闭源DLL:联系供应商索要多架构版本,或使用进程间通信(如gRPC)隔离架构差异[^2]。 --- ### 📚 相关问题 1. **如何为Android/iOS交叉编译Unity原生插件?** 2. **Unity中如何处理不同平台(Windows/macOS/Linux)的DLL兼容性?** 3. **当DLL依赖特定运行时库(如VC++ Redist)时如何打包部署?** 4. **如何调试Unity中崩溃的原生插件?** [^1]: 编译过程需严格匹配目标平台架构 [^2]: 架构隔离方案可避免重新编译闭源组件 [^3]: Unity编辑器架构需与插件一致
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值