0

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

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
drenocartero
  • 4,941
  • 7
  • 26
  • 26

3 Answers3

3

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';
Kuberchaun
  • 29,160
  • 7
  • 51
  • 59
  • 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. – drenocartero Nov 06 '09 at 15:37
  • Try USER_SOURCE. But I think you may have to parse out the parameters and types, but maybe you can get those somewhere. – Kuberchaun Nov 06 '09 at 15:42
2

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'
drenocartero
  • 4,941
  • 7
  • 26
  • 26
1

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
  • 66,725
  • 9
  • 119
  • 171