Impossibile SELEZIONARE * (ORA-00932: tipi di dati incoerenti: il CHAR previsto ha ottenuto ADT)
Aggiornamento Aggiornamento: posso eseguire una query definendo il nome della colonna ... quindi il problema è con la query SELECT * ma ho quasi 100 colonne nella mia tabella .. Non voglio inserirle tutte e mantenere quell'elenco .. perché posso io uso SELECT *??
Sto semplicemente cercando di creare un pulsante; il front-end in cui l'utente può scegliere una delle tre tabelle da esportare come file .csv. Al clic di una scelta -> la scelta viene restituita al mio PHP tramite table:which;quindi la tabella specifica verrà interrogata nel database Oracle e scaricata nel browser. Di seguito è riportato il mio tentativo di restituire un errore.
chiamata front-end jQuery (clic sul pulsante di esportazione):
$('#export' + '.' + crnt).click(function(){
let which = crnt;
window.location.href = "export?table="+which;
});
PHP tramite percorso sottile:
<?php
$app->post('/export', function ($request, $response, $args) {
$which = $_POST['table'];
$config = parse_ini_file(__DIR__ . '/../../xx/xx.ini');
$dbuser = $config['dbuser'];
$dbpass = $config['dbpass'];
$dbhost = $config['dbhost'];
$dbname = $config['dbname'];
$constr = $dbhost.'/'.$dbname;
$conn = oci_pconnect($dbuser, $dbpass, $constr, 'XXX');
if ($which == 'table_1'){
$sql = 'SELECT * FROM app.table_1';
$columnsql = 'SELECT column_name FROM app.table_1';
} else if ($which == 'table_2'){
$sql = 'SELECT * FROM app.table_2';
$columnsql = 'SELECT column_name FROM app.table_2';
} else if ($which == 'table_3'){
$sql = 'SELECT * FROM app.table_3';
$columnsql = 'SELECT column_name FROM app.table_3';
}
$stmt = oci_parse($conn, $sql);
$columnstmt = oci_parse($conn, $columnsql);
oci_execute($stmt);
oci_execute($columnstmt);
$columnnames = oci_fetch_array($columnstmt, OCI_ASSOC);
$output = fopen("php://output", "w");
fputcsv($output, $columnnames);
while ($row = oci_fetch_array($stmt, OCI_ASSOC)) {
fputcsv($output, $row);
}
fclose($output);
header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=$which.csv");
if (!@oci_execute($stmt)) {
$error = oci_error($stmt);
throw new Exception($error['message']);
}
if (!@oci_execute($columnstmt)) {
$error = oci_error($columnstmt);
throw new Exception($error['message']);
}
});
Errore 500: quanto sopra restituisce l'errore seguente nella console di rete degli strumenti di sviluppo -> scheda di risposta in anteprima:
Aggiornare:
Ora ho aggiornato tutte le postistanze a -> quale metodo di postaget fisso non ha consentito il messaggio ma sto ancora ricevendo il ... è qualcosa che ha a che fare con il mio nel php? dove li ho inseriti? Devo specificare anche un tipo di dati nella mia chiamata? Come gestisco il potenziale tipo di dati?ORA inconsistent datatypes errorheadersajax*ADT*
Risposte
È una strana richiesta per la colonna di estrazione. Non è qualcosa di simile?
select column_name from all_tab_columns where table_name = 'table_1';
Tu usi OCI_ASSOC. E puoi salvare una richiesta con una funzione come
while ($row = oci_fetch_array($stmt, OCI_ASSOC)) {
write_head_column($output, $row);
fputcsv($output, $row);
}
function write_head_column(&$output, $row){
static $is_done;
if(empty($is_done)){
$head = key($row);
fputcsv($output, $head);
$is_done = true;
}
}
Sembra che una + di voi colonne sia oggetto, come SDO_GEOMETRYe questo tipo di colonna non può essere selezionato tramite *Dovresti usare qualcosa come
SELECT c.shape.Get_Dims()
FROM cola_markets c WHERE c.name = 'cola_b';
@vederehttps://docs.oracle.com/database/121/SPATL/sdo_geometry-methods.htm#SPATL498