oci_result
(PHP 5, PHP 7, PECL OCI8 >= 1.1.0)
oci_result — Возвращает значение поля из результата запроса
Описание
Возвращает данные поля field
текущей строки, возвращаемой
функцией oci_fetch().
За подробностями по операции отображения типов данных, осуществляемым расширением OCI8, обратитесь к типам данных, поддерживаемых драйвером
Список параметров
-
statement
-
-
field
-
Может быть задано номером поля (начиная с 1), либо по имени. Регистр имени поля должен быть таким же, как и у поля описанного в метаданных Oracle, которое всегда в верхнем регистре для полей, созданных регистронезависимыми.
Возвращаемые значения
Возвращает все значения в виде строки за исключением абстрактных типов
(ROWIDs, LOBs и FILEs). Возвращает FALSE
в случае ошибки.
Примеры
Пример #1 oci_fetch() с oci_result()
<?php
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$sql = 'SELECT location_id, city FROM locations WHERE location_id < 1200';
$stid = oci_parse($conn, $sql);
oci_execute($stid);
while (oci_fetch($stid)) {
echo oci_result($stid, 'LOCATION_ID') . " is ";
echo oci_result($stid, 'CITY') . "<br>\n";
}
// Выведет:
// 1000 is Roma
// 1100 is Venice
oci_free_statement($stid);
oci_close($conn);
?>
Примечания
Замечание:
В версиях PHP ниже 5.0.0 эта функция называлась ociresult(). В PHP 5.0.0 и выше ociresult() является алиасом oci_result() в целях обратной совместимости. Вы можете продолжать использовать это имя, однако это не рекомендуется.
Смотрите также
- oci_fetch_array() - Возвращает следующую строку из результата запроса в виде ассоциативного или нумерованного массива
- oci_fetch_assoc() - Возвращает следующую строку из результата запроса в виде ассоциативного массива
- oci_fetch_object() - Возвращает следующую строку из результата запроса в виде объекта
- oci_fetch_row() - Возвращает следующую строку из результата запроса в виде нумерованного массива
- oci_fetch_all() - Выбирает все строки из результата запроса в двумерный массив
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- Oracle OCI8
- oci_bind_array_by_name
- oci_bind_by_name
- oci_cancel
- oci_client_version
- oci_close
- oci_commit
- oci_connect
- oci_define_by_name
- oci_error
- oci_execute
- oci_fetch_all
- oci_fetch_array
- oci_fetch_assoc
- oci_fetch_object
- oci_fetch_row
- oci_fetch
- oci_field_is_null
- oci_field_name
- oci_field_precision
- oci_field_scale
- oci_field_size
- oci_field_type_raw
- oci_field_type
- oci_free_descriptor
- oci_free_statement
- oci_get_implicit_resultset
- oci_internal_debug
- oci_lob_copy
- oci_lob_is_equal
- oci_new_collection
- oci_new_connect
- oci_new_cursor
- oci_new_descriptor
- oci_num_fields
- oci_num_rows
- oci_parse
- oci_password_change
- oci_pconnect
- oci_result
- oci_rollback
- oci_server_version
- oci_set_action
- oci_set_client_identifier
- oci_set_client_info
- oci_set_edition
- oci_set_module_name
- oci_set_prefetch
- oci_statement_type
Коментарии
OCIResult() requires the column name to be written in capitals, so OCIResult($stmt,"column") won't work, but OCIResult($stmt,"COLUMN") works fine. Hope that helps somebody out
As this function gets a 'mixed' variable type for the column index, you may use an integer to represent the column number. In this case, the count is starting from 1 and not from zero.
I am not sure, but I think this method is a bit faster than using the column name.
For an example, see the OCINumCols first example.
I complained that I couldn't get the time from an Oracle date field. Joe Brown said:
This is not a PHP bug.
Consider setting NLS_DATE_FORMAT.
The manual states OCIResult() returns everything as a string.
NLS_DATE_FORMAT may not be appropriate for your needs.
There are quite a few places you can set NLS_DATE_FORMAT.
* Environment variables (or windows registry on win32)
* orclSID.ora
* on a per session basis; execute this statement after logon:
$cursor=OCIParse($connection,
"ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
OCIExecute($cursor);
OCIFreeCursor($cursor);
I am trying to get a list of the first character of a character string.
SELECT distinct substr(version,1,1) as COL1 FROM SPHVVERS where Version is not null order by 1
This was working and then failed recently. I think it is because some of the strings now added contain a number as the first character.
I found to get it to work I had to use decode statement. (To_Char did not work )
SELECT distinct decode (substr(version,1,1),'1','?','0','!',substr(version,1,1)) as COL1 FROM SPHVVERS where Version is not null order by 1
Note that if you are making multiple table selects, you must specify an alias to each column.
This wont work:
----------------------------------------
$qry = "SELECT A.COL_ONE, B.COL_ONE FROM TABLE1 A, TABLE2 B";
$stmt = OCIParse($conn, $qry);
while(OCIFetch($stmt))
{
$a = OCIResult($stmt, "A.COL_ONE");
...
----------------------------------------
But this will:
----------------------------------------
$qry = "SELECT A.COL_ONE AS X, B.COL_ONE AS Y FROM TABLE1 A, TABLE2 B";
$stmt = OCIParse($conn, $qry);
while(OCIFetch($stmt))
{
$a = OCIResult($stmt, "X");
...
----------------------------------------
Regards,
As in my previous post, the same thing applies when using conversion functions in CLOB columns.
Probably the same thing will occur to any conversion function that you use.
So, this wont work
SELECT ... TO_CHAR(MY_CLOB) ...
$my_clob = OCIResult($stmt,"MY_CLOB");
But this will:
SELECT ... TO_CHAR(MY_CLOB) AS MYC ...
$my_clob = OCIResult($stmt,"MYC");
Best regards.
FYI--
In order to modify Oracle dates (using NLS_DATE_FORMAT...), you must set $ORACLE_HOME first. This environmental variable is best set in the server startup script (i.e., ./apachectl)
--
Jim
if you want to join two tables having both the same column (e.g. 'id') but you don't want to (or cannot) specify all the other fields in these two tables (like erabbott mentioned), you can use:
SELECT t1.*, t2.*, t1.id AS id1, t2.id AS id2
FROM table1 t1, table2 t2;
Note that this does _not_ work:
SELECT *,t1.id AS id1, t2.id AS id2
FROM table1 t1, table2 t2;
I am trying to get a list of the first character of a character string.
SELECT distinct substr(version,1,1) as COL1 FROM SPHVVERS where Version is not null order by 1
This was working and then failed recently. I think it is because some of the strings now added contain a number as the first character.
I found to get it to work I had to use decode statement. (To_Char did not work )
SELECT distinct decode (substr(version,1,1),'1','?','0','!',substr(version,1,1)) as COL1 FROM SPHVVERS where Version is not null order by 1