Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Oracle Functions : ociresult

ociresult

Alias of oci_result (PHP 4, PHP 5, PECL oci8:1.0-1.2.4)


Code Examples / Notes » ociresult

maxwell_smart

On the column names needing to be all caps. Just a guess.
Oracle is case sensitive when columns are created with quotes around them. When they are created without quotes around them, they are case insensitive. However, Oracle will always display them as being all caps.
If PHP referes to a column, it probably gets the case from Oracle. Then since PHP is case sensitive, you have ot supply it in all caps.


dominic dot standage

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

erabbott

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,


dave dot greene

Managed to finally get the actual demo script working, by removeing the "<" and ">" as it was turning my table name's into tags.

gabi

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;


dwilson

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);


luismanuelp

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


steve dot hurst

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


rmanga

I am having problems using Column names, but I tried column number instead of name, it seems to work

jthome

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


shayman

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.


erabbott

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.


Change Language


Follow Navioo On Twitter
oci_bind_array_by_name
oci_bind_by_name
oci_cancel
oci_close
OCI-Collection->append
OCI-Collection->assign
OCI-Collection->assignElem
OCI-Collection->free
OCI-Collection->getElem
OCI-Collection->max
OCI-Collection->size
OCI-Collection->trim
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_statement
oci_internal_debug
OCI-Lob->append
OCI-Lob->close
oci_lob_copy
OCI-Lob->eof
OCI-Lob->erase
OCI-Lob->export
OCI-Lob->flush
OCI-Lob->free
OCI-Lob->getBuffering
OCI-Lob->import
oci_lob_is_equal
OCI-Lob->load
OCI-Lob->read
OCI-Lob->rewind
OCI-Lob->save
OCI-Lob->saveFile
OCI-Lob->seek
OCI-Lob->setBuffering
OCI-Lob->size
OCI-Lob->tell
OCI-Lob->truncate
OCI-Lob->write
OCI-Lob->writeTemporary
OCI-Lob->writeToFile
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_prefetch
oci_statement_type
ocibindbyname
ocicancel
ocicloselob
ocicollappend
ocicollassign
ocicollassignelem
ocicollgetelem
ocicollmax
ocicollsize
ocicolltrim
ocicolumnisnull
ocicolumnname
ocicolumnprecision
ocicolumnscale
ocicolumnsize
ocicolumntype
ocicolumntyperaw
ocicommit
ocidefinebyname
ocierror
ociexecute
ocifetch
ocifetchinto
ocifetchstatement
ocifreecollection
ocifreecursor
ocifreedesc
ocifreestatement
ociinternaldebug
ociloadlob
ocilogoff
ocilogon
ocinewcollection
ocinewcursor
ocinewdescriptor
ocinlogon
ocinumcols
ociparse
ociplogon
ociresult
ocirollback
ocirowcount
ocisavelob
ocisavelobfile
ociserverversion
ocisetprefetch
ocistatementtype
ociwritelobtofile
ociwritetemporarylob
eXTReMe Tracker