本文目录一览:
- 1、php 链接oracle,插入数据的问题,用sql执行就可以,用php的oci插入就不行,但oci可以查询
- 2、php调用oracle存储过程与函数
- 3、如何在php中向oracle数据库插入日期时间型数据
- 4、php向oracle里写入中文记录
php 链接oracle,插入数据的问题,用sql执行就可以,用php的oci插入就不行,但oci可以查询
1.语句中不需要begin end
2.OCI 已经包含了,insert 本身会启动事务
3.oci_parse 不支持多条语句
php调用oracle存储过程与函数
对于存储过程的源代码,开始都需要先定义接受的参数,例如:
PROCEDURE edit_entry(
status_out OUT NUMBER,
status_msg_out OUT VARCHAR2,
id_inout IN OUT INTEGER,
title_in IN VARCHAR2,
text_out OUT CLOB,
categories_in IN list_of_numbers
);
从 PHP 中调用存储过程 对于要从 PHP 中执行以调用过程的 SQL 语句而言,您将通常在 Oracle BEGIN …END; 块(称作匿名块)中嵌入调用。例如:
?php
// etc.
//$sql = ‘BEGIN sayHello(:name, :message); END;’;
//然后,通过调用 oci_bind_by_name() 将参数绑定到 PHP 变量。 如果使用以下 DDL 语句定义了 sayHello
//:
//CREATE OR REPLACE PROCEDURE
//sayHello (name IN VARCHAR2, greeting OUT VARCHAR2)
//AS
//BEGIN
//greeting := ‘Hello ‘ || name;
//END;
//
//注意,您可以使用 SQL*Plus 命令行运行上面的语句。将该语句保存到文件 (SAYHELLO.SQL)。接下来,使用
//SQL*Plus 登录:
// $ sqlplus username@SID
// 然后,使用 START 命令创建该过程:
// SQL START /home/username/SAYHELLO.SQL
// 以下 PHP 脚本调用该过程:
$conn = oci_connect(‘SCOTT’,’TIGER’) or die;
$sql = ‘BEGIN sayHello(:name, :message); END;’;
$stmt = oci_parse($conn,$sql);
// Bind the input parameter
oci_bind_by_name($stmt,’:name’,$name,32);
// Bind the output parameter
oci_bind_by_name($stmt,’:message’,$message,32);
// Assign a value to the input
$name = ‘Harry’;
oci_execute($stmt);
// $message is now populated with the output value
print “$message\n”;
?
调用程序包中的过程时,将使用句号来分隔程序包名称与过程名称。 可以使用以下语句指定 blog 程序包:
CREATE OR REPLACE PACKAGE blog AS
TYPE cursorType IS REF CURSOR RETURN blogs%ROWTYPE;
/*
Fetch the latest num_entries_in from the blogs table, populating
entries_cursor_out with the result
*/
PROCEDURE latest(
num_entries_in IN NUMBER,
entries_cursor_out OUT cursorType
);
/*
Edit a blog entry.If id_inout is NULL, results in an INSERT, otherwise
attempts to UPDATE the existing blog entry. status_out will have the value
1 on success, otherwise a negative number on failure with status_msg_out
containing a description
categories_in is a collection where list_of_numbers is described by
TYPE list_of_numbers AS VARRAY(50) OF NUMBER;
*/
PROCEDURE edit_entry(
status_out OUT NUMBER,
status_msg_out OUT VARCHAR2,
id_inout IN OUT INTEGER,
title_in IN VARCHAR2,
text_out OUT CLOB,
categories_in IN list_of_numbers
);
END blog;
/
如何在php中向oracle数据库插入日期时间型数据
使用to_date函数
************to_date函数参数简介***********
******************************************
对于你的问题
‘1996-12-03’ 改为 to_date(‘1996-12-03′,’yyyy-mm-dd’)
‘1970-12-12’ 改为 to_date(‘1970-12-12′,’yyyy-mm-dd’)
’19-Dec-00′ 改为 to_date(’19-Dec-00′,’dd-mon-yy’)
’19-Oct-75′ 改为 to_date(’19-Oct-75′,’dd-mon-yy’)
之后直接插入即可。
**************oracle上的实验**************
SQL select to_char(sysdate,’yyyy-mm-dd’) from dual;
TO_CHAR(SY
———-
2009-04-17
SQL select to_char(sysdate,’dd-mon-yy’) from dual;
TO_CHAR(S
———
17-apr-09
******************************************
—-
以上,希望对你有所帮助。
php向oracle里写入中文记录
$name=str_replace(“‘”, “\\'”, $name);
$name=str_replace(“””, “\\””, $name);
把中文字符里面的引号替换一下试试看。,
原创文章,作者:FDZZ,如若转载,请注明出处:https://www.506064.com/n/131741.html