tags:

views:

114

answers:

3

Hi I am trying to get information on an Oracle package directly from PHP using OCI8:

$sql = 'DESC my_package';
$stmt = oci_parse($conn, $sql);
oci_execute($stmt);

this returns:

Warning: oci_execute() [function.oci-execute]: ORA-00900: invalid SQL statement in /oci8_test.php on line 16

I know the command works as I tried it in SQLPlus.

Does anyone know how to achieve this.

Thx

+1  A: 

Hi vinnybozz

DESC is a SQL*Plus command, it won't work out of SQL*Plus. You can write your own DESC by querying the data dictionnary from any tool:

SQL> SELECT column_name, data_type, data_length,
  2         data_precision, data_scale, nullable
  3    FROM all_tab_columns
  4   WHERE table_name = 'T';


COLUMN_NAME  DATA_TYPE  DATA_LENGTH DATA_PRECISION DATA_SCALE NULLABLE
------------ ---------- ----------- -------------- ---------- --------
COLUMN1      CHAR                 6                           Y
COLUMN2      CHAR                 6                           Y
Vincent Malgrat
+2  A: 

DESC is a SQL Plus command.

I have been away from Oracle for a few years now, but look into the data dictionary. For example for tables you could do below. There must be something for Packages as well. DESC MY_TABLE

is equivalent to

SELECT 
column_name "Name", 
nullable "Null?",
concat(concat(concat(data_type,'('),data_length),')') "Type"
FROM user_tab_columns
WHERE table_name='TABLE_NAME_TO_DESCRIBE';
StarShip3000
ya I've been looking through the Data Dictionary Views but have yet to find the one that would describe packages and procedures (ie: number of parameters and types). The 'user_procedures' view gives a list and name of procedures but not much more info.
vinnybozz
Try USER_SOURCE. But I think you may have to parse out the parameters and types, but maybe you can get those somewhere.
StarShip3000
+1  A: 

Thx for the replies, I think I have found my answer.

So for anyone who is interested, as Vincent said, I think to make it work you'll have to create your own 'DESC'. The Oracle View to use is 'user_arguments', you get the function/procedure names, argument names and types, argument position, etc...

Select * from user_arguments where package_name = 'my_package'
vinnybozz
now my problem is accessing that view from another schema !
vinnybozz
k just use 'all\_ARGUMENTS' instead of 'user\_ARGUMENTS'
vinnybozz
that's pretty standard in Oracle.
Stephanie Page