我需要查询数据库以获得列名,不要与表中的数据混淆。例如,如果我有一个名为EVENT_LOG的表,其中包含eventID、eventType、eventDesc和eventTime,那么我将希望从查询中检索这些字段名,而不是其他内容。

我发现如何做到这一点:

Microsoft SQL Server MySQL PostgreSQL

但是我需要知道:如何在Oracle中做到这一点?


当前回答

select column_name,* from information_schema.columns
 where table_name = 'YourTableName'
order by ordinal_position

其他回答

对甲骨文

SELECT column_name FROM user_tab_cols WHERE table_name=UPPER('tableName');

对于MySQL,使用

SELECT column_name 
FROM information_schema.columns 
WHERE 
table_schema = 'Schema' AND table_name = 'Table_Name'
SELECT COLUMN_NAME 
FROM YourDatabase.INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'YourTableName'

试试这个

select * from sys.all_columns c join sys.objects o on c.object_id=o.object_id where o.name = 'TABLENAME' and c.name like '%COLUMN NAME%'

答案在这里:http://php.net/manual/en/function.mysql-list-fields.php 在你的情况下,我会使用以下代码:

$result = mysql_query("SHOW COLUMNS FROM sometable");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$fields = array();
if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
        $fields[] = $row['Field'];
    }
}