I have a piece of code that's driving me mad... any clues will be great..
I'm running a piece of code that looks like this.
select v.id,
v.registrationnumber,
v.dateofregistration,
vm.name,
vm.cc,
vm.doors,
vm.abicd,
vma.manufname,
vma.vmabicd,
m.transmission,
m2.transmission fueltype,
vm.doors,
v.numofseats
from vehicle v, vehiclemodel vm, vehiclemanufacturer vma,
mktlistitem m, mktlistitem m2, mktlistitem m3
where v.modelcd = vm.abicd
and vm.vehiclemanufid = vma.vmabicd
and (vm.transtypedc = m.abicd
and m.mktlistnameid = 49)
and (vm.fueltypedc = m2.abicd
and m2.mktlistnameid = 45)
/
and it works fine, however when I add another column and it's where clause I get the following error (bodytype column in the list and last where clause)
select v.id,
v.registrationnumber,
v.dateofregistration,
vm.name,
vm.cc,
vm.doors,
vm.abicd,
vma.manufname,
vma.vmabicd,
m.transmission,
m2.transmission fueltype,
m3.transmission bodytype
from vehicle v, vehiclemodel vm, vehiclemanufacturer vma,
mktlistitem m, mktlistitem m2, mktlistitem m3
where v.modelcd = vm.abicd
and vm.vehiclemanufid = vma.vmabicd
and (vm.transtypedc = m.abicd
and m.mktlistnameid = 49)
and (vm.fueltypedc = m2.abicd
and m2.mktlistnameid = 45)
and (vm.bodytypecd = m3.abicd
and m3.mktlistnameid = 55)
/and (vm.bodytypecd = m3.abicd
*
ERROR at line 21:
ORA-01722: invalid number
I've also added the desc of the 2 tables included in the join.
SQL> desc vehiclemodel
Name Null? Type
------------------------------- -------- ----
ID NUMBER(38)
NAME VARCHAR2(80)
CC NUMBER(38)
YEARFROM DATE
YEARTO DATE
BODYTYPECD NUMBER(38)
FUELTYPEDC NUMBER(38)
TRANSTYPEDC NUMBER(38)
DOORS NUMBER(38)
ABICD NUMBER(38)
VEHICLEMANUFID NUMBER(38)
STARTDATE DATE
EXPIRYDATE DATE
MARKERS NUMBER(38)
SQL> desc mktlistitem
Name Null? Type
------------------------------- -------- ----
ID NUMBER(38)
TRANSMISSION VARCHAR2(128)
ABICD VARCHAR2(16)
STARTDATE DATE
EXPIRYDATE DATE
MARKERS NUMBER(38)
MKTLISTNAMEID NUMBER(38)
PARENTLISTITEMID VARCHAR2(16)
you must look values in m3.abicd and not others, other values works probably because the m3.abicd for that value is number and the implicit to_number works
I've been doing some more work on this script, however during testing I've discovered that it's producing a cartasian merge join, any help or advice on how to tune - prevent this would be great - and yes I understand that there are no indexes, it's not the tuning for speed that I care about right now - just the sql working...
thanks v much.
SELECT v.id,
v.registrationnumber,
v.dateofregistration,
vm.name vehicle_model,
vm.abicd,
vma.manufname vehicle_manufacturer,
vma.vmabicd manufacturer_abi_code,
vm.cc engin_size,
m.transmission,
m2.transmission fueltype,
vm.doors,
v.numofseats,
m4.transmission paintworkcolour,
m3.transmission vehicle_body_style,
v.vinnumber,
m5.transmission overnight_parking_provision,
m6.transmission overnight_parking_location,
v.odometerreading,
v.dateofodometerreading,
(SELECT count(*) FROM vehiclemodifications vmof
WHERE vmof.vehicleid(+) = v.id) numofmodifications,
(SELECT count(*) FROM vehiclesecuritydevice vsd
WHERE vsd.vehicleid(+) = v.id) nomofsecuritydevices,
vu.annualdistancepleasure,
vu.annualdistancebusiness,
v.purchaseprice,
v.currentvalue,
a.addressline1,
a.addressline2,
a.addressline3,
a.addressline4,
a.postcode
FROM vehicle v,
vehiclemodel vm,
vehiclemanufacturer vma,
vehicleusage vu,
mktlistitem m,
mktlistitem m2,
mktlistitem m3,
mktlistitem m4,
mktlistitem m5,
mktlistitem m6,
address a
WHERE v.modelcd = vm.abicd
AND vm.vehiclemanufid = vma.vmabicd
AND v.vehicleusageid = vu.id
AND (vm.transtypedc = m.abicd
AND m.mktlistnameid = 49)
AND (vm.fueltypedc = m2.abicd
AND m2.mktlistnameid = 45)
AND (to_char(v.bodystylecd) = m3.abicd
AND m3.mktlistnameid = 55)
AND (v.paintworkcolourcd = m4.abicd
AND m4.mktlistnameid = 9)
AND (to_char(vu.overnightparkingprovisioncd) = m5.abicd
AND m5.mktlistnameid = 12)
AND (to_char(vu.overnightparkinglocationcd) = m6.abicd
AND m6.mktlistnameid = 1012)
AND a.id = vu.addressid;
Bookmarks