oracle二次開發呼叫外部C函式。

2021-08-09 02:18:11 字數 3498 閱讀 1894

listener =

(description_list =

(description =

(address = (protocol = ipc)(key = extproc1521))

(address = (protocol = tcp)(host = localhost)(port = 1521)) ) )

oraclr_connection_data =

(description =

(address_list =

(address = (protocol = ipc)(key = extproc1521))

) (connect_data =

(sid = clrextproc)

(presentation = ro) ) )

orcl =

(description =

(address = (protocol = tcp)(host = localhost)(port = 1521))

(connect_data =

(server = dedicated)

(service_name = orcl) ) )

extproc_connection_data =

(description =

(address_list =

(address = (protocol = ipc)(key = extproc1521))

) (connect_data =

(sid = pl***tproc)

) )

若是沒有成功,注意兩檔案中內容格式,及等號兩邊的空格。(似乎oracle對這兩個檔案的格式要求特別嚴格)

重啟監聽, 可檢視新增的pl***tproc是否成功。

建立c的dll,

define ss_orcle_extend_api extern 「c」 __declspec(dllexport)

ss_orcle_extend_api int getmodelcount(ociloblocator *lob, short lbind, ociextproccontext *ctxt );

ss_orcle_extend_api char* getmodelname(ociloblocator *lob, short lbind, ociextproccontext *ctxt );

生成c的dll拷貝至安裝目錄的product\11.2.0\dbhome_1\bin資料夾下。

由於number varchar2等字段型別比較簡單,此處不做**樣例。而oracle的blob型別,需通過ociloblocator lob, short lbind 內容和長度引數傳遞。通過oci,轉為c的二進位制。unsigned char 和長度。

sword errnum = 0;

ocienv *envhp = null;

ocisvcctx *svchp = null;

ocierror *errhp = null;

/* * retrieve the environment, service context, and error handles

*/ if ((errnum = ociextprocgetenv(ctxt, &envhp, &svchp, &errhp)) != ociextproc_success)

ub1 csfrm;

ub4 amount;

int r;

r = ocilobopen( svchp, errhp, lob , (ub1)oci_file_readonly);

if (r != oci_success)

// read this from the database, don』t assume we know what it is set to

r = ocilobcharsetform(envhp, errhp, lob, &csfrm);

if (r != oci_success)

// get the length of the lob (this is in characters)

r = ocilobgetlength(svchp,errhp, lob, &amount);

if (r == oci_success)

} else

// resize the buffer to hold the lob contents

unsigned char* buf = new unsigned char[amount];

int sz = sizeof(char);

// read the lob into the buffer

r = ocilobread(svchp,

errhp,

lob,

&amount,

1, (void*)buf,

amount * sz, // this argument is in bytes, not characters

0, 0,

// extract the data from a clob in utf-16 (ie. what qstring uses internally)

sz == 1 ? ub2(0) : ub2(2002),

csfrm);

if (r != oci_success)

r = ocilobclose(svchp, errhp, lob);

if (r != oci_success)

即可對oracle的二進位制進行處理。

dll拷貝至bin目錄下後,建立oracle的library ,若當前使用者無建立許可權,需為此使用者分配建立library許可權。

建立oracle內部函式

create or replace function meshnum(a_lob blob ) return binary_integer as language c library meshtest name 「getmodelcount」 with context parameters(a_lob ociloblocator,a_lob indicator short,context,return int);

create or replace function meshname(a_lob blob ) return varchar2 as language c library meshtest name 「getmodelname」 with context parameters(a_lob ociloblocator,a_lob indicator short,context);

把二進位製入到oracle庫中的表blocks_3d_model_lt的filecontent欄位內。

利用sql語句測試select meshname(filecontent) from blocks_3d_model_lt 結果如下:

postek二次開發 POSTEK二次開發介面

例項簡介 例項截圖 核心 using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.text using ...

Arcengine二次開發gp呼叫

一 呼叫gp 以融合為例 public static void dissolve ifeatureclass in features,string out feature class,string field,string statistics fields,string multi part di...

mcms二次開發 YzmCMS二次開發手冊

摘要 yzmcms是採用mvc設計模式開發,基於模組和操作的方式進行訪問,採用單一入口模式進行專案部署和訪問,無論訪問任何乙個模組或者功能,只有一.yzmcms是採用mvc設計模式開發,基於模組和操作的方式進行訪問,採用單一入口模式進行專案部署和訪問,無論訪問任何乙個模組或者功能,只有乙個統一的入口...