I have an internal intranet made in PHP and we had the Oracle server here, but it has been moved to an cloud server. Since that I'm having an issue.
If I execute a simple query from PHP like "select * from empresas" it executes normal, but if I try a more complicated query, with some joins and where clause, it gives the error ORA-03113. Trying to execute from PL/SQL Developer, this specific query takes something like 5 seconds to execute, it returns something like 15 rows only.
I have no acces to the Oracle logs, because this cloud is just one instance to us.
I think that maybe is a PDO configuration or maybe version that I need to configure/check to solve this problem, just don't know how to start.
The old Oracle server was a Windows server and the Oracle version was 12. The cloud is Oracle 11 and is a Linux server.
Here is the query:
`SELECT distinct
ct.descricao MARCA,
e.nome EMPRESA,
vi.cod_item CODIGO,
i.descricao DESCRICAO,
igi.cod_grupo_interno CODTIPO,
igi.descricao TIPO,
ic.cod_curva CLASSEABC,
v.cod_cliente COD_CLIENTE,
cd.nome NOME_CLIENTE,
ci.descricao CID_CLIENTE,
ci.uf UF_CLIENTE,
CASE WHEN cd.cpf<>' ' THEN 'F' ELSE 'J' END TIPO_CLIENTE,
cl.descricao DESCTP_CLIENTE,
SUM(vi.qtde) QTDE,
vi.preco_unitario PPUBLICO,
SUM(vi.qtde * vi.preco_unitario) FAT_BRT,
SUM(vi.TOTAL_DESCONTOS) DESCONTO,
SUM(vi.preco_liquido_final) FAT_LIQ,
SUM(vi.qtde * vi.preco_contabil) CUSTO,
SUM(vi.base_icms) BASE_ICMS,
SUM(vi.valor_icms) VLR_ICMS,
'0' VLR_COP,
'0' ACRESCIMO,
SUM(vi.valor_pis + vi.valor_cofins) VLR_PCOF,
SUM(vi.valor_ipi) VLR_IPI,
NULL VLR_MARGEM,
v.controle|| '-' || v.serie NF,
TO_CHAR(v.emissao, 'DD/MM/YYYY') DTNF,
n.cod_natureza CODNATUREZA,
n.descricao NATUREZA,
eu.id_funcionario VENDEDOR,
eu.nome_completo FUNCIONARIO,
eu.nome LOGIN,
eu.cod_funcao TIPO_FUN,
'N' STATUS,
v.numero_os OS,
v.chassi_resumido VEICULO,
cd.bairro BAIRRO_CLIENTE,
v.controle|| '-' || v.serie NOTA,
pg.descricao CONDICAO_PG,
pg.cod_forma_pgto COD_CONDICAO,
os.tipo CD_TP_OS,
ost.descricao DS_TP_OS,
'0' PERCUSTOOPER,
ed.cod_empresa_departamento DEPARTAMENTO,
ic.custo_fornecedor VLRREPOSICAO
FROM vendas v
INNER JOIN venda_itens vi ON vi.cod_empresa = v.cod_empresa and vi.controle = v.controle
INNER JOIN itens_custos ic ON ic.cod_empresa = v.cod_empresa AND ic.cod_item = vi.cod_item AND ic.cod_fornecedor = vi.cod_fornecedor
INNER JOIN itens_fornecedor if ON if.cod_item = vi.cod_item AND if.cod_fornecedor = vi.cod_fornecedor
INNER JOIN fornecedor_estoque fe ON fe.cod_fornecedor = if.cod_fornecedor
INNER JOIN itens i ON i.cod_item = vi.cod_item
INNER JOIN itens_grupo_interno igi ON igi.cod_grupo_interno = i.cod_grupo_interno
INNER JOIN empresas e ON e.cod_empresa = v.cod_empresa
INNER JOIN empresas_usuarios eu ON eu.nome = v.vendedor
INNER JOIN empresas_funcoes ef ON ef.cod_funcao = eu.cod_funcao
INNER JOIN empresas_departamentos ed ON ed.cod_empresa = v.cod_empresa AND ed.cod_empresa_departamento = v.cod_empresa_departamento
INNER JOIN parm_sys p ON p.cod_empresa = v.cod_empresa
INNER JOIN concessionaria_tipo ct ON ct.cod_tipo_concessionaria = p.tipo_concessionaria
INNER JOIN cliente_diverso cd ON cd.cod_cliente = v.cod_cliente AND cd.cod_empresa = v.cod_empresa
INNER JOIN clientes_tipo cl ON cl.cod_tipo = cd.cod_tipo
INNER JOIN cidades ci ON ci.cod_cidades = cd.cod_cidades
LEFT JOIN pagamento_venda pv ON pv.controle = v.controle AND pv.serie = v.serie
LEFT JOIN forma_pgto pg ON pg.cod_forma_pgto = pv.cod_forma_pgto
LEFT JOIN os ON os.cod_empresa = v.cod_empresa and os.numero_os = v.numero_os
LEFT JOIN os_tipos ost ON ost.tipo = os.tipo
LEFT JOIN natureza n ON n.cod_natureza = vi.cod_natureza and n.grupo = vi.grupo
LEFT JOIN operacoes ops ON ops.cod_empresa = v.cod_empresa and ops.cod_operacao = v.cod_operacao
WHERE v.status <> '1' AND v.total_produtos > 0
AND (ops.grupo is null or ops.grupo = 2)
AND v.emissao >= to_date(SYSDATE-20)
AND i.COD_GRUPO_INTERNO <> 13
GROUP BY ct.descricao, e.nome, vi.cod_item, i.descricao, igi.cod_grupo_interno, igi.descricao, ic.cod_curva, v.cod_cliente,
cd.nome, ci.descricao, ci.uf, CASE WHEN cd.cpf<>' ' THEN 'F' ELSE 'J' END, cl.descricao, vi.preco_unitario, vi.preco_contabil,
v.margem, v.controle|| '-' || v.serie, TO_CHAR(v.emissao, 'DD/MM/YYYY'), n.cod_natureza, n.descricao, eu.id_funcionario,
eu.nome_completo, eu.nome, eu.cod_funcao, v.numero_os, v.chassi_resumido, cd.bairro, v.controle|| '-' || v.serie,
pg.descricao,pg.cod_forma_pgto, os.tipo, ost.descricao, ed.cod_empresa_departamento, ic.custo_fornecedor`
I asked the administers for Oracle logs, it gave me nothing, the administers saw that my query even got to there, then I tried a lot of things and finally my boss found an answer. He saw that the problem is the size of the package the PHP are sending through the VPN connection we have with the cloud. So the solution (at least for now) is add to PDO connection the size we need using: "(DESCRIPTION=(SDU=1400) ..." on the connection string.
I have a fairly complex query (to me) that returns duplicate results ONLY when the parameter passed results in 'dest_xdock: ' . $row['dest_xdock'] as a certain value. Can anyone identify why this is happening in the Query? I don't have duplicates of this in the table that I can see. Here is the query:
select
`orig_lookup`.`zipcode` AS `orig_zipcode`,
`orig_lookup`.`state` AS `orig_state`,
`orig_lookup`.`svcnotes` AS `orig_svcnotes`,
`orig_lookup`.`svcterms` AS `orig_svcterms`,
`orig_lookup`.`daysout` AS `orig_daysout`,
`orig_lookup`.`daysin` AS `orig_daysin`,
`orig_lookup`.`pcity` AS `orig_city`,
`orig_lookup`.`scac` AS `orig_scac`,
`orig_lookup`.`xdock` AS `orig_xdock`,
`orig_lookup`.`scac2` AS `orig_scac2`,
`orig_lookup`.`xdock2` AS `orig_xdock2`,
`orig_lookup`.`scac3` AS `orig_scac3`,
`orig_lookup`.`xdock3` AS `orig_xdock3`,
`orig_ssas`.`ssa` AS `orig_ssa`,
`orig_hcas`.`hca` AS `orig_hca`,
`dest_lookup`.`zipcode` AS `dest_zipcode`,
`dest_lookup`.`state` AS `dest_state`,
`dest_lookup`.`svcnotes` AS `dest_svcnotes`,
`dest_lookup`.`svcterms` AS `dest_svcterms`,
`dest_lookup`.`daysout` AS `dest_daysout`,
`dest_lookup`.`daysin` AS `dest_daysin`,
`dest_lookup`.`pcity` AS `dest_city`,
`dest_lookup`.`scac` AS `dest_scac`,
`dest_lookup`.`xdock` AS `dest_xdock`,
`dest_lookup`.`scac2` AS `dest_scac2`,
`dest_lookup`.`xdock2` AS `dest_xdock2`,
`dest_lookup`.`scac3` AS `dest_scac3`,
`dest_lookup`.`xdock3` AS `dest_xdock3`,
`dest_ssas`.`ssa` AS `dest_ssa`,
`dest_hcas`.`hca` AS `dest_hca`,
`tbl_matx_20160321`.`trmnljoin` AS `TrmnlMatx`,
`tbl_matx_20160321`.`trmnlsvcdays` AS `TrmnlSvcDays`,
`tbl_matx_20160321`.`trmnltranspts` AS `TrmnlTransPts`,
IF(ISNULL(`orig_lookup`.`daysin`+ `dest_lookup`.`daysout`+ `tbl_matx_20160321`.`trmnlsvcdays`), 'No Service',(`orig_lookup`.`daysin`+ `dest_lookup`.`daysout`+ `tbl_matx_20160321`.`trmnlsvcdays`)) AS `TotalSvcDays`
FROM ((`tbl_uscomp_20160321` AS `orig_lookup` LEFT JOIN `tbl_hcas_20160321` AS `orig_hcas` ON `orig_lookup`.`zipcode` = `orig_hcas`.`zipcode` LEFT JOIN `tbl_ssas_20160321` AS `orig_ssas` ON `orig_lookup`.`zipcode` = `orig_ssas`.`zipcode`)
INNER JOIN (`tbl_uscomp_20160321` AS `dest_lookup` LEFT JOIN `tbl_hcas_20160321` AS `dest_hcas` ON `dest_lookup`.`zipcode` = `dest_hcas`.`zipcode` LEFT JOIN `tbl_ssas_20160321` AS `dest_ssas` ON `dest_lookup`.`zipcode` = `dest_ssas`.`zipcode`)
INNER JOIN `tbl_matx_20160321` ON (`orig_lookup`.`xdock` = `tbl_matx_20160321`.`otrmnl` AND `dest_lookup`.`xdock` = `tbl_matx_20160321`.`dtrmnl`))
WHERE `orig_lookup`.`zipcode` = '$ziporig' AND `dest_lookup`.`zipcode` = '$zipdest'",
I have a simple JOIN query:
$lstCheck = $dbWHMCS->query('SELECT * FROM tblmonitorports mp
INNER JOIN tblmonitorhosts h ON h.hst_id = port_mon
INNER JOIN tblhosting ho ON ho.id = h.hst_serverid
INNER JOIN tblclients cl ON cl.id = ho.userid');
while ($data = $lstCheck->fetch())
{
$serveridx = $data['ho.id'];
$clientid = $data['cl.id'];
}
My problem is that I have an "id" column in both the tblhosting and tblclients tables, so my variables both have the same id. I tried to set it using an alias in the example above (ho. and cl.) but it doesn't work. How can I do this in the example above?
Thank you!
How about this? (a bit rusty on php details, but this should do it):
$lstCheck = $dbWHMCS->query('SELECT ho.id hid, cl.id cid FROM tblmonitorports mp
INNER JOIN tblmonitorhosts h ON h.hst_id = port_mon
INNER JOIN tblhosting ho ON ho.id = h.hst_serverid
INNER JOIN tblclients cl ON cl.id = ho.userid');
while ($data = $lstCheck->fetch())
{
$serveridx = $data['hid'];
$clientid = $data['cid'];
}
You are selecting the records, with a wild card *, so you can't select the fields like that.
As per your query h.hst_serverid & ho.userid have the exact same value as you want. SO simply do this
while ($data = $lstCheck->fetch())
{
$serveridx = $data['hst_serverid'];
$clientid = $data['userid'];
}
However, selecting specific rows might sound better too
$lstCheck = $dbWHMCS->query('SELECT ho.id hid, cl.id cid, ....');
while ($data = $lstCheck->fetch())
{
$serveridx = $data['hid'];
$clientid = $data['cid'];
}
What is incorrect?
I cant get any data...
SELECT
my_site_orders.order_id,
my_site_orders.order_orderer_id,
my_site_orders.order_ip,
my_site_orders.order_time,
my_site_orders.order_campaign_id,
my_site_orders.order_status,
my_site_orders.order_shipment_status,
my_site_orders.order_shipping_method,
my_site_orders.order1_id,
my_site_orders.order1_coupon_id,
my_site_orders.order1_amount,
my_site_orders.order1_price,
my_site_orders.order_cargo_name,
my_site_orders.order_cargo_surname,
my_site_orders.order_cargo_vatnumber,
my_site_orders.order_cargo_line1,
my_site_orders.order_cargo_line2,
my_site_orders.order_cargo_stateprovince,
my_site_orders.order_cargo_district,
my_site_orders.order_cargo_city,
my_site_orders.order_cargo_contactphone,
my_site_orders.order_invoice_name,
my_site_orders.order_invoice_surname,
my_site_orders.order_invoice_company,
my_site_orders.order_invoice_line1,
my_site_orders.order_invoice_line2,
my_site_orders.order_invoice_vatnumber,
my_site_orders.order_invoice_vat,
my_site_orders.order_invoice_stateprovince,
my_site_orders.order_invoice_district,
my_site_orders.order_invoice_city,
my_site_orders.order_invoice_contactphone,
my_site_orders.order_type,
my_site_orders.order_note,
my_site_orders.order_hash,
my_site_orders.order_bank_hash,
my_site_orders.order_phone_number,
my_site_orders.order_price,
my_site_orders.order_cc_name,
my_site_orders.order_instalment_amount,
my_site_orders.order_instalment_price,
my_site_users.user_name,
my_site_users.user_email,
my_site_orders.order1_type,
my_site_users.user_realname,
my_site_users.user_surname,
my_site_products.product_brand_id,
my_site_products.product_id,
my_site_products.product_cat_id,
my_site_products.product_title,
my_site_products.product_snippet,
my_site_products.product_description,
my_site_products.product_code,
my_site_products.product_normalprice,
my_site_products.product_price,
my_site_products.product_quantity,
my_site_products.product_image1,
my_site_products.product_image1_t1,
my_site_products.product_image4,
my_site_products.product_image4_t1,
my_site_products.product_image4_t2,
my_site_products.product_image_big4,
my_site_products.product_image5,
my_site_products.product_image5_t1,
my_site_products.product_image5_t2,
my_site_products.product_image_big5,
my_site_products.product_select_choice_title,
my_site_products.product_select_option_title,
my_site_products.product_select1,
my_site_products.product_select2,
my_site_products.product_select3,
my_site_products.product_select4,
my_site_products.product_select5,
my_site_products.product_select6,
my_site_products.product_select7,
my_site_products.product_select8,
my_site_products.product_select9,
my_site_products.product_select10,
my_site_brands.brand_name,
my_site_product_cats.product_cat_name
FROM
my_site_orders
INNER JOIN my_site_users ON (my_site_orders.order_orderer_id = my_site_users.user_id)
INNER JOIN my_site_products ON (my_site_orders.order1_id = my_site_products.product_id)
INNER JOIN my_site_brands ON (my_site_products.product_brand_id = my_site_brands.brand_id)
INNER JOIN my_site_product_cats ON (my_site_products.product_cat_id = my_site_product_cats.product_cat_id)
WHERE
my_site_orders.order1_type = my_site_products.product_select1
OR
my_site_orders.order1_type = my_site_products.product_select2
OR
my_site_orders.order1_type = my_site_products.product_select3
OR
my_site_orders.order1_type = my_site_products.product_select4
OR
my_site_orders.order1_type = my_site_products.product_select5
OR
my_site_orders.order1_type = my_site_products.product_select6
OR
my_site_orders.order1_type = my_site_products.product_select7
OR
my_site_orders.order1_type = my_site_products.product_select8
OR
my_site_orders.order1_type = my_site_products.product_select9
OR
my_site_orders.order1_type = my_site_products.product_select10
But i get the data with:
SELECT
my_site_orders.order_id,
my_site_orders.order_orderer_id,
my_site_orders.order_ip,
my_site_orders.order_time,
my_site_orders.order_campaign_id,
my_site_orders.order_status,
my_site_orders.order_shipment_status,
my_site_orders.order_shipping_method,
my_site_orders.order1_id,
my_site_orders.order1_coupon_id,
my_site_orders.order1_amount,
my_site_orders.order1_price,
my_site_orders.order_cargo_name,
my_site_orders.order_cargo_surname,
my_site_orders.order_cargo_vatnumber,
my_site_orders.order_cargo_line1,
my_site_orders.order_cargo_line2,
my_site_orders.order_cargo_stateprovince,
my_site_orders.order_cargo_district,
my_site_orders.order_cargo_city,
my_site_orders.order_cargo_contactphone,
my_site_orders.order_invoice_name,
my_site_orders.order_invoice_surname,
my_site_orders.order_invoice_company,
my_site_orders.order_invoice_line1,
my_site_orders.order_invoice_line2,
my_site_orders.order_invoice_vatnumber,
my_site_orders.order_invoice_vat,
my_site_orders.order_invoice_stateprovince,
my_site_orders.order_invoice_district,
my_site_orders.order_invoice_city,
my_site_orders.order_invoice_contactphone,
my_site_orders.order_type,
my_site_orders.order_note,
my_site_orders.order_hash,
my_site_orders.order_bank_hash,
my_site_orders.order_phone_number,
my_site_orders.order_price,
my_site_orders.order_cc_name,
my_site_orders.order_instalment_amount,
my_site_orders.order_instalment_price,
my_site_users.user_name,
my_site_users.user_email,
my_site_orders.order1_type,
my_site_users.user_realname,
my_site_users.user_surname,
my_site_products.product_brand_id,
my_site_products.product_id,
my_site_products.product_cat_id,
my_site_products.product_title,
my_site_products.product_snippet,
my_site_products.product_description,
my_site_products.product_code,
my_site_products.product_normalprice,
my_site_products.product_price,
my_site_products.product_quantity,
my_site_products.product_image1,
my_site_products.product_image1_t1,
my_site_products.product_image4,
my_site_products.product_image4_t1,
my_site_products.product_image4_t2,
my_site_products.product_image_big4,
my_site_products.product_image5,
my_site_products.product_image5_t1,
my_site_products.product_image5_t2,
my_site_products.product_image_big5,
my_site_products.product_select_choice_title,
my_site_products.product_select_option_title,
my_site_products.product_select1,
my_site_products.product_select2,
my_site_products.product_select3,
my_site_products.product_select4,
my_site_products.product_select5,
my_site_products.product_select6,
my_site_products.product_select7,
my_site_products.product_select8,
my_site_products.product_select9,
my_site_products.product_select10,
my_site_brands.brand_name,
my_site_product_cats.product_cat_name
FROM
my_site_orders
INNER JOIN my_site_users ON (my_site_orders.order_orderer_id = my_site_users.user_id)
INNER JOIN my_site_products ON (my_site_orders.order1_id = my_site_products.product_id)
INNER JOIN my_site_brands ON (my_site_products.product_brand_id = my_site_brands.brand_id)
INNER JOIN my_site_product_cats ON (my_site_products.product_cat_id = my_site_product_cats.product_cat_id)
First, you can use IN() instead of so many ORs. It will render your query shorter, and easier for reading. Next, obviously you have no orders with order1_type IN(product_select1,product_select2,product_select3,product_select4,product_select5,product_select6,product_select7,product_select8,product_select9,product_select10). Some sample data (from the first query) could help us to rewrite your query correctly