急!在oracle7中的oci如何连接到另外一台机器的?例子好像都是连接到本机的? 如果你配置好了连接别的服务器的本地网络服务,那oci肯定是可以连接到别的服务器的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //例子如下,如何指连接到 oraclesid_192.168.0.1呢?#include <stdio.h>#include <oratypes.h>#include <ocidfn.h>#include <ocidem.h>Cda_Def cda;Lda_Def lda;/* set up the table */text *dt = (text *) "DROP TABLE part_nos";text *ct = (text *) "CREATE TABLE part_nos (partno NUMBER, description\ VARCHAR2(20))";text *cp = (text *) "\ CREATE OR REPLACE PACKAGE update_parts AS\n\ TYPE part_number IS TABLE OF part_nos.partno%TYPE\n\ INDEX BY BINARY_INTEGER;\n\ TYPE part_description IS TABLE OF part_nos.description%TYPE\n\ INDEX BY BINARY_INTEGER;\n\ PROCEDURE add_parts (n IN INTEGER,\n\ descrip IN part_description,\n\ partno IN part_number);\n\ END update_parts;";text *cb = (text *) "\ CREATE OR REPLACE PACKAGE BODY update_parts AS\n\ PROCEDURE add_parts (n IN INTEGER,\n\ descrip IN part_description,\n\ partno IN part_number) is\n\ BEGIN\n\ FOR i IN 1..n LOOP\n\ INSERT INTO part_nos\n\ VALUES (partno(i), descrip(i));\n\ END LOOP;\n\ END add_parts;\n\ END update_parts;";#define DESC_LEN 20#define MAX_TABLE_SIZE 1200text *pl_sql_block = (text *) "\ BEGIN\n\ update_parts.add_parts(3, :description, :partno);\n\ END;";text descrip[3][20] = {"Frammis", "Widget", "Thingie"};sword numbers[] = {12125, 23169, 12126};ub2 descrip_alen[3] = {DESC_LEN, DESC_LEN, DESC_LEN};ub2 descrip_rc[3];ub4 descrip_cs = (ub4) 3;ub2 descrip_indp[3];ub2 num_alen[3] = { (ub2) sizeof (sword), (ub2) sizeof (sword), (ub2) sizeof (sword) };ub2 num_rc[3];ub4 num_cs = (ub4) 3;ub2 num_indp[3];ub1 hda[256];main(){ printf("Connecting to Oracle..."); if (olog(&lda, hda, "scott/tiger", -1, 0, -1, 0, -1, OCI_LM_DEF)) { printf("Cannot logon as scott/tiger. Exiting...\n"); exit(1); } if (oopen(&cda, &lda, NULL, -1, -1, NULL, -1)) { printf("Cannot open cursor, exiting...\n"); exit(1); } /* Drop the table. */ printf("\nDropping table..."); if (oparse(&cda, dt, -1, 0, 2)) if (cda.rc != 942) oci_error(); printf("\nCreating table..."); if (oparse(&cda, ct, -1, 0, 2)) oci_error(); /* Parse and execute the create package statement. */ printf("\nCreating package..."); if (oparse(&cda, cp, -1, 0, 2)) oci_error(); if (oexec(&cda)) oci_error(); /* Parse and execute the create package body statement. */ printf("\nCreating package body..."); if (oparse(&cda, cb, -1, 0, 2)) oci_error(); if (oexec(&cda)) oci_error(); /* Parse the anonymous PL/SQL block that calls the stored procedure. */ printf("\nParsing PL/SQL block..."); if (oparse(&cda, pl_sql_block, -1, 0, 2)) oci_error(); /* Bind the C arrays to the PL/SQL tables. */ printf("\nBinding arrays..."); if (obndra(&cda, (text *) ":description", -1, (ub1 *) descrip, DESC_LEN, VARCHAR2_TYPE, -1, descrip_indp, descrip_alen, descrip_rc, (ub4) MAX_TABLE_SIZE, &descrip_cs, (text *) 0, -1, -1)) oci_error(); if (obndra(&cda, (text *) ":partno", -1, (ub1 *) numbers, (sword) sizeof (sword), INT_TYPE, -1, num_indp, num_alen, num_rc, (ub4) MAX_TABLE_SIZE, &num_cs, (text *) 0, -1, -1)) oci_error(); printf("\nExecuting block..."); if (oexec(&cda)) oci_error(); printf("\n"); if (oclose(&cda)) { printf("Error closing cursor!\n"); return -1; } if (ologof(&lda)) { printf("Error logging off!\n"); return -1; } exit(1);}oci_error(){ text msg[600]; sword rv; rv = oerhms(&lda, cda.rc, msg, 600); printf("\n\n%.*s", rv, msg); printf("Processing OCI function %s\n", oci_func_tab[cda.fc]); if (oclose(&cda)) printf("Error closing cursor!\n"); if (ologof(&lda)) printf("Error logging off!\n"); exit(1);} 安装oracle客户端,然后使用net8来配置一个服务命名,这个服务命名连接到你需要连接的远程数据库,然后你只需要连接到服务命名就可以了 创建一个db-link:remotedblinkselect * from remotedblink@sysobjects; OracleDBConsoleorcl与SQL developer的练接 如何查找oracle中用户自定义函数信息 Oracle的约束是否可以复用 一SELECT语句异惑??? 安装win32Oracle11g时报错 ORACLE普通表转换成分区表 帖子为什么看不了? 高手请进!急!!在线等待!系统正常使用中,突然ORACEL服务自动停止,贴出错误LOG,请教!! ORACLE。中如何生成SQL脚本? oracle 动态sql 请教各位高手 增加表字段该如何写语句?
#include <stdio.h>
#include <oratypes.h>
#include <ocidfn.h>
#include <ocidem.h>
Cda_Def cda;
Lda_Def lda;/* set up the table */
text *dt = (text *) "DROP TABLE part_nos";
text *ct = (text *) "CREATE TABLE part_nos (partno NUMBER, description\
VARCHAR2(20))";text *cp = (text *) "\
CREATE OR REPLACE PACKAGE update_parts AS\n\
TYPE part_number IS TABLE OF part_nos.partno%TYPE\n\
INDEX BY BINARY_INTEGER;\n\
TYPE part_description IS TABLE OF part_nos.description%TYPE\n\
INDEX BY BINARY_INTEGER;\n\
PROCEDURE add_parts (n IN INTEGER,\n\
descrip IN part_description,\n\
partno IN part_number);\n\
END update_parts;";text *cb = (text *) "\
CREATE OR REPLACE PACKAGE BODY update_parts AS\n\
PROCEDURE add_parts (n IN INTEGER,\n\
descrip IN part_description,\n\
partno IN part_number) is\n\
BEGIN\n\
FOR i IN 1..n LOOP\n\
INSERT INTO part_nos\n\
VALUES (partno(i), descrip(i));\n\
END LOOP;\n\
END add_parts;\n\
END update_parts;";
#define DESC_LEN 20
#define MAX_TABLE_SIZE 1200text *pl_sql_block = (text *) "\
BEGIN\n\
update_parts.add_parts(3, :description, :partno);\n\
END;";text descrip[3][20] = {"Frammis", "Widget", "Thingie"};
sword numbers[] = {12125, 23169, 12126};ub2 descrip_alen[3] = {DESC_LEN, DESC_LEN, DESC_LEN};
ub2 descrip_rc[3];
ub4 descrip_cs = (ub4) 3;
ub2 descrip_indp[3];ub2 num_alen[3] = {
(ub2) sizeof (sword),
(ub2) sizeof (sword),
(ub2) sizeof (sword) };
ub2 num_rc[3];
ub4 num_cs = (ub4) 3;
ub2 num_indp[3];
ub1 hda[256];main()
{
printf("Connecting to Oracle...");
if (olog(&lda, hda, "scott/tiger", -1, 0, -1, 0, -1,
OCI_LM_DEF)) {
printf("Cannot logon as scott/tiger. Exiting...\n");
exit(1);
} if (oopen(&cda, &lda, NULL, -1, -1, NULL, -1)) {
printf("Cannot open cursor, exiting...\n");
exit(1);
} /* Drop the table. */
printf("\nDropping table...");
if (oparse(&cda, dt, -1, 0, 2))
if (cda.rc != 942)
oci_error(); printf("\nCreating table...");
if (oparse(&cda, ct, -1, 0, 2))
oci_error(); /* Parse and execute the create package statement. */
printf("\nCreating package...");
if (oparse(&cda, cp, -1, 0, 2))
oci_error();
if (oexec(&cda))
oci_error(); /* Parse and execute the create package body statement. */
printf("\nCreating package body...");
if (oparse(&cda, cb, -1, 0, 2))
oci_error();
if (oexec(&cda))
oci_error();
/* Parse the anonymous PL/SQL block that calls the
stored procedure. */
printf("\nParsing PL/SQL block...");
if (oparse(&cda, pl_sql_block, -1, 0, 2))
oci_error(); /* Bind the C arrays to the PL/SQL tables. */
printf("\nBinding arrays...");
if (obndra(&cda, (text *) ":description", -1, (ub1 *) descrip,
DESC_LEN, VARCHAR2_TYPE, -1, descrip_indp, descrip_alen,
descrip_rc, (ub4) MAX_TABLE_SIZE, &descrip_cs, (text *) 0,
-1, -1))
oci_error(); if (obndra(&cda, (text *) ":partno", -1, (ub1 *) numbers,
(sword) sizeof (sword), INT_TYPE, -1, num_indp,
num_alen, num_rc, (ub4) MAX_TABLE_SIZE, &num_cs,
(text *) 0, -1, -1))
oci_error(); printf("\nExecuting block...");
if (oexec(&cda)) oci_error();
printf("\n");
if (oclose(&cda)) {
printf("Error closing cursor!\n");
return -1;
} if (ologof(&lda)) {
printf("Error logging off!\n");
return -1;
}
exit(1);
}oci_error()
{
text msg[600];
sword rv; rv = oerhms(&lda, cda.rc, msg, 600);
printf("\n\n%.*s", rv, msg);
printf("Processing OCI function %s\n", oci_func_tab[cda.fc]);
if (oclose(&cda))
printf("Error closing cursor!\n");
if (ologof(&lda))
printf("Error logging off!\n");
exit(1);
}
select * from remotedblink@sysobjects;