欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 sword OCIEnvInit ( OCIEnv **envhpp, ub4 mode, size_t xtramemsz, dvoid **usrmempp ); 注: 在8i以后,可用OCIEnvCreate一个函数就可以初始化环境了,相当于OCIInitialize+ OCIEnvInit 2.申请/
欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入
sword OCIEnvInit (
OCIEnv **envhpp,
ub4 mode,
size_t xtramemsz,
dvoid **usrmempp
);
注:
在8i以后,可用OCIEnvCreate一个函数就可以初始化环境了,相当于OCIInitialize+ OCIEnvInit
2.申请/释放句柄
sword OCIHandleAlloc(
CONST dvoid *parenth, //新申请句柄的父句柄,一般为OCI环境句柄
Dvoid **hndlpp, //申请的新句柄
Ub4 type, type, //句柄类型
Size_t xtramem_sz, //申请的内存数
Dvoid **usrmempp //申请到的内存块指针
)
注:
一般需要申请的句柄有:
服务器句柄OCIServer, 句柄类型OCI_HTYPE_SERVER
错误句柄OCIError,用于捕获OCI错误信息, 句柄类型OCI_HTYPE_ERROR
事务句柄OCISession, 句柄类型OCI_HTYPE_SESSION
上下文句柄OCISvcCtx, 句柄类型OCI_HTYPE_SVCCTX
SQL语句句柄OCIStmt, 句柄类型OCI_HTYPE_STMT
eg: 申请一个错误句柄OCIError
swResult = OCIHandleAlloc(envhpp, (dvoid *)& errhp, OCI_HTYPE_ERROR, 0, NULL);
if(swResult != OCI_SUCCESS && swResult != OCI_SUCCESS_WITH_INFO)
{
return FALSE;
}
释放句柄
sword OCIHandleFree(
dvoid *hndlp, //要释放的句柄
ub4 type //句柄类型
)
eg:
OCIHandleFree(stmtp, OCI_HTYPE_STMT)
3.读取/设置句柄属性
sword OCIAttrSet(
dvoid *trgthndlp, //需设置的句柄名
ub4 trghndltyp, //句柄类型
dvoid *attributep, //设置的属性名
ub4 size, //属性值长度
ub4 attrtype, //属性类型
OCIError *errhp //错误句柄
)
注:一般要设置的属性有:
服务器实例:
句柄类型OCI_HTYPE_SVCCTX,属性类型OCI_ATTR_SERVER
连接数据的用户名:
句柄类型OCI_HTYPE_SESSION,属性类型OCI_ATTR_USERNAME
用户密码
句柄类型OCI_HTYPE_SESSION,属性类型OCI_ATTR_PASSWORD
事务:
句柄类型OCI_HTYPE_SVCCTX,属性类型OCI_ATTR_SESSION
eg:设置用户名和密码
char username[20],passwd[20];
strcpy(username,”tiger”)
strcpy(passwd,”cotton”)
swResult = OCIAttrSet(usrhp, OCI_HTYPE_SESSION, (text*) username, strlen(username),
OCI_ATTR_USERNAME, errhp);
if(swResult != OCI_SUCCESS && swResult != OCI_SUCCESS_WITH_INFO)
return FALSE;
swResult = OCIAttrSet(usrhp, OCI_HTYPE_SESSION, (text*) passwd, strlen(passwd),
OCI_ATTR_PASSWORD, errhp);
if(swResult != OCI_SUCCESS && swResult != OCI_SUCCESS_WITH_INFO)
return FALSE;
sword OCIAttrGet(
dvoid *trgthndlp, //需读取的句柄名
ub4 trghndltyp, //句柄类型
dvoid *attributep, //读取的属性名
ub4 *sizep, //属性值长度
ub4 attrtype, //属性类型
OCIError *errhp //错误句柄
)
4.连接/断开服务器
多用户方式连接:
sword OCIServerAttach(
OCIServer *srvhp,//未初始化的服务器句柄
OCIError *errhp,
CONST text *dblink,//服务器SID
sb4 dblink_len,
ub4 mode //=OCI_DEFAULT,系统环境将设为阻塞方式
);
sword OCIServerDetach (
OCIServer *srvhp,
OCIError *errhp,
ub4 mode //OCI_DEFAULT
);
单用户方式连接:
sword OCILogon (
OCIEnv *envhp,
OCIError *errhp,
OCISvcCtx **svchp,
CONST text *username,
ub4 uname_len,
CONST text *password,
ub4 passwd_len,
CONST text *dbname,
ub4 dbname_len
);
sword OCILogoff (
OCISvcCtx *svchp
OCIError *errhp
);
5.开始/结束一个会话
先认证用户再建立一个会话连接
sword OCISessionBegin (
OCISvcCtx *svchp, //服务环境句柄
OCIError *errhp,
OCISession *usrhp, //用户会话句柄
ub4 credt, //认证类型
ub4 mode //操作模式
);
*认证类型:
OCI_CRED_RDBMS:用数据库用户名和密码进行认证,则先要设置OCI_ATTR_USERNAME和OCI_ATTR_PASSWORD属性
OCI_CRED_EXT:外部认证,不需要设置用户和密码
OCI_DEFAULT:用户会话环境只能被指定的服务器环境句柄所设置
OCI_SYSDBA:用户要具有sysdba权限
OCI_SYSOPER:用户要具有sysoper权限
Eg:
swResult = OCISessionBegin(svchp, errh,usrhp, OCI_CRED_RDBMS, OCI_DEFAULT);
if(swResult != OCI_SUCCESS && swResult != OCI_SUCCESS_WITH_INFO)
return FALSE;
sword OCISessionEnd (
OCISvcCtx *svchp,
OCIError *errhp,
OCISession *usrhp,
ub4 mode );
6.读取错误信息
sword OCIErrorGet (
dvoid *hndlp, //错误句柄
ub4 recordno,//从那里读取错误记录,从1开始
text *sqlstate,//已取消,=NULL
sb4 *errcodep, //错误号
text *bufp, //错误内容
ub4 bufsiz, //bufp长度
ub4 type //传递的错误句柄类型
=OCI_HTYPE_ERROR:错误句柄
=OCI_HTYPE_ENV:环境句柄
);
eg:
ub4 ub4RecordNo = 1;
OCIError* hError
sb4 sb4ErrorCode;
char sErrorMsg[1024];
if (OCIErrorGet(hError, ub4RecordNo++, NULL, &sb4ErrorCode, (OraText*) sErrorMsg, sizeof(sErrorMsg), OCI_HTYPE_ERROR) == OCI_SUCCESS)
printf(“error msg:%s\n”, sErrorMsg);
[1] [2] [3] [4] [5]

方法:1、利用“select*from user_indexes where table_name=表名”语句查询表中索引;2、利用“select*from all_indexes where table_name=表名”语句查询所有索引。

oracle asm指的是“自动存储管理”,是一种卷管理器,可自动管理磁盘组并提供有效的数据冗余功能;它是做为单独的Oracle实例实施和部署。asm的优势:1、配置简单、可最大化推动数据库合并的存储资源利用;2、支持BIGFILE文件等。

在oracle中,可以利用“TO_SINGLE_BYTE(String)”将全角转换为半角;“TO_SINGLE_BYTE”函数可以将参数中所有多字节字符都替换为等价的单字节字符,只有当数据库字符集同时包含多字节和单字节字符的时候有效。

在Oracle中,可利用lsnrctl命令查询端口号,该命令是Oracle的监听命令;在启动、关闭或重启oracle监听器之前可使用该命令检查oracle监听器的状态,语法为“lsnrctl status”,结果PORT后的内容就是端口号。

在oracle中,可以利用“drop sequence sequence名”来删除sequence;sequence是自动增加数字序列的意思,也就是序列号,序列号自动增加不能重置,因此需要利用drop sequence语句来删除序列。

在oracle中,可以利用“select ... From all_tab_columns where table_name=upper('表名') AND owner=upper('数据库登录用户名');”语句查询数据库表的数据类型。

方法:1、利用“LOWER(字段值)”将字段转为小写,或者利用“UPPER(字段值)”将字段转为大写;2、利用“REGEXP_LIKE(字符串,正则表达式,'i')”,当参数设置为“i”时,说明进行匹配不区分大小写。

方法:1、利用“alter system set sessions=修改后的数值 scope=spfile”语句修改session参数;2、修改参数之后利用“shutdown immediate – startup”语句重启服务器即可生效。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
