Read Oracle Table structure data

Source: Internet
Author: User

Title {font-weight:Bold;} td {Width:120px;padding-left:10px;} Table {Border: 0.5px Solid#778899;Border-collapse:collapse; Border-spacing:0;p Adding: 0; }</style><title>oracle database table structure </title>PHP///////////////////////////////////////////////////////////////////////////////////////////////////////////// Database Connection Configuration Information$ora _host= "";$ora _port="";$ora _sid= "";$ora _username= "";$ora _password= "";$charset= "UTF8";## # ZHS16GBK ###//connection string$ora _connstr= "(description= (address= (protocol=tcp) (host=".$ora _host.") (port= ".$ora _port.")) (Connect_data= (Service_name=".$ora _sid.")))";///////////////////////////////////////////////////////////////////////////////////////////////////////////// Test Connection$conn= Oci_connect ($ora _username,$ora _password,$ora _connstr, ' UTF8 ');if(!$conn) { $e=oci_error ();Print htmlentities($e[' Message ']);Exit; }Else{ Echo"Connect Oracle Successfully!" <br/> "; } Echo"User:".$ora _username. "Server:".$ora _host. "Database:".$ora _sid." <br/><br/> ";///////////////////////////////////////////////////////////////////////////////////////////////////////////// Query the number of tables under the user$sql _showtables= ' Select table_name from User_tables ';$stid= Oci_parse ($conn,$sql _showtables);//Configure SQL statements to prepare for executionif(!$stid) {$e= Oci_error ($conn);Print htmlentities($e[' Message ']);Exit;}$r= Oci_execute ($stid, Oci_default);//Execute SQL. Oci_default says no automatic commitif(!$r) {$e= Oci_error ($stid);Echo htmlentities($e[' Message ']);Exit;}///////////////////////////////////////////////////////////////////////////////////////////////////////////// Print execution Results while($row= Oci_fetch_row ($stid)) {$table _name=$row[0];Echo"<strong> Data Sheet Name:".$table _name." </strong> ";///////////////////////////////////////////////////////////////////////////////////////////////////////////// Query field Comments/*$col _comments= ' Select B.comments as note from user_col_comments b where b.table_name=upper (\ '. $table _name. ' \ ') '; $stid _col_comments = Oci_parse ($conn, $col _comments); Configure the SQL statement, prepare to execute if (! $col _comments) {$e = Oci_error ($conn);p rint htmlentities ($e [' message ']); exit;} $r _col_comments = Oci_execute ($stid _col_comments, Oci_default); Execute SQL. Oci_default means do not automatically commitif (! $r _col_comments) {$e = Oci_error ($stid _col_comments); Echo htmlentities ($e [' message ']); Exit;} while ($row _col_comments = Oci_fetch_row ($stid _col_comments)) {//print "<td> $row _col_comments[0]</td>"; print "</tr>";}*////////////////////////////////////////////////////////////////////////////////////////////////////////////// Query Table META$table _meta=Select A.column_name,a.data_type,a.data_length,a.nullablefrom user_tab_columns awhere a.TABLE_NAME=upper (\ ' ‘.$table _name.‘ \‘)‘;$stid _table_meta= Oci_parse ($conn,$table _meta);//Configure SQL statements to prepare for executionif(!$stid _table_meta) {$e= Oci_error ($conn);Print htmlentities($e[' Message ']);Exit;}$r _table_meta= Oci_execute ($stid _table_meta, Oci_default);//Execute SQL. Oci_default says no automatic commitif(!$r _table_meta) {$e= Oci_error ($stid _table_meta);Echo htmlentities($e[' Message ']);Exit;}///////////////////////////////////////////////////////////////////////////////////////////////////////////// Print data table structure tablePrint' <table border= ' 1 "> ';Print' <tr bgcolor= ' #6495ED ' class= ' title ' ><td> field name </td><td><p> data type </td><td> Data length </td><td> Whether it can be empty </td><td> comment </td></tr> '; while($row _table_meta= Oci_fetch_row ($stid _table_meta)) {//&& $row _col_comments = Oci_fetch_row ($stid _col_commentsPrint"<tr bgcolor=\" #F0FFFF \ "><td>$row _table_meta[0]</td> ";Print"<td>$row _table_meta[1]</td> ";Print"<td>$row _table_meta[2]</td> ";Print"<td>$row _table_meta[3]</td> ";////$col _comments= ' Select B.comments as comment from user_col_comments b where b.column_name=upper (\ '.$row _table_meta[0]. ' \ ') and b.table_name=upper (\ ').$table _name.‘ \‘)‘;$stid _col_comments= Oci_parse ($conn,$col _comments);//Configure SQL statements to prepare for executionif(!$col _comments) {$e= Oci_error ($conn);Print htmlentities($e[' Message ']);Exit;}$r _col_comments= Oci_execute ($stid _col_comments, Oci_default);//Execute SQL. Oci_default says no automatic commitif(!$r _col_comments) {$e= Oci_error ($stid _col_comments);Echo htmlentities($e[' Message ']);Exit;} while($row _col_comments= Oci_fetch_row ($stid _col_comments)) {//print "<td> $row _col_comments[0]</td>";Print"<td>$row _col_comments[0]</td> ";}//////print "<td> </td>";Print"</tr>";}///////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////Print"</table></br>"; }//Close ConnectionOci_close ($conn);?> </body>

Read Oracle Table structure data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.