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
334k85 gold badges536 silver badges509 bronze badges
asked Nov 6, 2009 at 15:13

3 Answers 3

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';
answered Nov 6, 2009 at 15:27
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Try USER_SOURCE. But I think you may have to parse out the parameters and types, but maybe you can get those somewhere.
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'
answered Nov 6, 2009 at 15:44

2 Comments

k just use 'all_ARGUMENTS' instead of 'user_ARGUMENTS'
that's pretty standard in Oracle.
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
answered Nov 6, 2009 at 15:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.