Trying to make recordset from pl/sql oracle server

ClimoC

Well-known Member
Joined
Aug 21, 2009
Messages
584
Hello

Trying to get this to work, but get all manner of errors. As I'm doing this in VB, it won't bug on the line in question, but rather on the .Execute command.

Can anyone see why I am getting either 'ORA-00905: missing keyword' or 'SQL command not ended properly'?

I'm fairly good with VB, Can scrape basic SQL, but pl/sql on a massive multi-join is a step over my head, and I can't see what's wrong with my syntax. Table names etc are all correct, but either my syntax is incorrect or my delimiters are wrong/non-existent.

Code:
Dim var1 As String, var2 As String
var1 = ""
var1 = var1 & "SELECT c.channel_name, " & vbCrLf
var1 = var1 & "       Dstr(si.schedule_date) tx_date, " & vbCrLf
var1 = var1 & "       Tstr(si.start_time)    AS start_tm, " & vbCrLf
var1 = var1 & "       Tstr(si.duration)      AS slot_duration, " & vbCrLf
var1 = var1 & "       t.programme_name       AS title, " & vbCrLf
var1 = var1 & "       decode_tv_flag.table_description, " & vbCrLf
var1 = var1 & "       d.deal_name, " & vbCrLf
var1 = var1 & "       d.deal_code, " & vbCrLf
var1 = var1 & "       Tstr(d.deal_slot_duration) " & vbCrLf
var1 = var1 & "FROM   schedule_item si, channel c  " & vbCrLf
var1 = var1 & "       join channel c.channel_name " & vbCrLf
var1 = var1 & "         ON c.channel_code = si.channel_code  " & vbCrLf
var1 = var1 & "       join purchase p " & vbCrLf
var1 = var1 & "         ON p.purchase_id = si.purchase_id  " & vbCrLf
var1 = var1 & "       join title t " & vbCrLf
var1 = var1 & "         ON t.title_id = p.title_id " & vbCrLf
var1 = var1 & "       join deal d " & vbCrLf
var1 = var1 & "         ON d.deal_id = p.deal_id " & vbCrLf
'var1 = var1 & "       left join table_line decode_tv_flag " & vbCrLf
'var1 = var1 & "          " & vbCrLf
'var1 = var1 & "         ON decode_tv_flag.table_id = 'PROGPR' " & vbCrLf
'var1 = var1 & "            AND decode_tv_flag.table_code = p.tv_prem_live_none " & vbCrLf
var1 = var1 & "WHERE  c.channel_code = si.channel_code AND si.schedule_date BETWEEN '20110701' AND '20110705'  " & vbCrLf
var1 = var1 & "       AND p.tv_prem_live_none != 'R'  " & vbCrLf
var1 = var1 & "ORDER BY c.channel_name DESC"


'On Error Resume Next
    With cnImportConn
                    .CursorLocation = adUseClient
                    .Open strConn
                    .CommandTimeout = 0
                    Set RecSet = .Execute(var1, adOpenForwardOnly, adLockReadOnly)
    End With
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I would do adding the following line after your complete your construction of code:
Code:
MsgBox var1
and inspect it carefully to see if it looks like you wrote your code correctly.

You can also trying the code to an existing query to see if you can locate where the issue is. To do this, just create any dummy query and name it something like "QueryTest".

Then in your code, after you have created the SQL code, use this line to assign that SQL code to your dummy query:
Code:
CurrentDb.QueryDefs("QueryTest").SQL = var1
If you still cannot figure it out, try manually creating the query that does what you want. Then switch it to SQL View, and compare that SQL code to the code just above that you are building and look for differences.
 
Upvote 0
Is the db fussy about you correctly terminating with a ";"? You don't have one at the end of your SQL
 
Upvote 0
I would do adding the following line after your complete your construction of code:
Code:
MsgBox var1
and inspect it carefully to see if it looks like you wrote your code correctly.

You can also trying the code to an existing query to see if you can locate where the issue is. To do this, just create any dummy query and name it something like "QueryTest".

Then in your code, after you have created the SQL code, use this line to assign that SQL code to your dummy query:
Code:
CurrentDb.QueryDefs("QueryTest").SQL = var1
If you still cannot figure it out, try manually creating the query that does what you want. Then switch it to SQL View, and compare that SQL code to the code just above that you are building and look for differences.

Thanks Joe.

Problem is, whilst I can 'say' it looks right, that's based ony my limited exposure to this stuff. Like I said, I can form a basic OLEDB/JET connection to an Access or text file and pull stuff with basic SQL, joining tables etc I'm a bit new to (used to only 2d arrays)

But the error messages I keep getting aren't specific, they're more about 'incorrect syntax', 'missing keyword', 'missing character', 'not ended properly' etc
 
Upvote 0
Is the db fussy about you correctly terminating with a ";"? You don't have one at the end of your SQL

Yeah that was my first thought Kyle. Doesn't seem to make a difference (even when I can get it to the point where the error it 'not ended properly', I append the semicolon, no difference. Have tried semicolon, semicolon then CrLf then forward slash, without forward slash, END, END; etc etc) - I've tried every google-able approach I can.
 
Upvote 0
Ok, think I've found some dodgy syntax, bear in mind im only MSSQL though not oracle ;)

this
Code:
join channel c.channel_name  ON c.channel_code = si.channel_code
I think should be
Code:
join channel  C ON c.channel_code = si.channel_code

So you get:
<font face="Courier New" size="2">
<font color = "blue">SELECT</font> <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_name</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Dstr</b></font><font color = "maroon">(</font><font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">schedule_date</font><font color = "maroon">)</font> <font color = "maroon">tx_date</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Tstr</b></font><font color = "maroon">(</font><font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">start_time</font><font color = "maroon">)</font>    <font color = "blue">AS</font> <font color = "maroon">start_tm</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Tstr</b></font><font color = "maroon">(</font><font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">duration</font><font color = "maroon">)</font>      <font color = "blue">AS</font> <font color = "maroon">slot_duration</font><font color = "silver">,</font>
<br/>       <font color = "maroon">t</font><font color = "silver">.</font><font color = "maroon">programme_name</font>       <font color = "blue">AS</font> <font color = "maroon">title</font><font color = "silver">,</font>
<br/>       <font color = "maroon">decode_tv_flag</font><font color = "silver">.</font><font color = "maroon">table_description</font><font color = "silver">,</font>
<br/>       <font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_name</font><font color = "silver">,</font>
<br/>       <font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_code</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Tstr</b></font><font color = "maroon">(</font><font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_slot_duration</font><font color = "maroon">)</font>
<br/><font color = "blue">FROM</font>   <font color = "maroon">schedule_item</font> <font color = "maroon">si</font><font color = "silver">,</font>
<br/>       <font color = "maroon">channel</font> <font color = "maroon">c</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">channel</font> <font color = "maroon">C</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_code</font> <font color = "silver">=</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">channel_code</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">purchase</font> <font color = "maroon">p</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">purchase_id</font> <font color = "silver">=</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">purchase_id</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">title</font> <font color = "maroon">t</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">t</font><font color = "silver">.</font><font color = "maroon">title_id</font> <font color = "silver">=</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">title_id</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">deal</font> <font color = "maroon">d</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_id</font> <font color = "silver">=</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">deal_id</font>
<br/>       <font color = "maroon">left</font> <font color = "maroon">join</font> <font color = "maroon">table_line</font> <font color = "maroon">decode_tv_flag</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">decode_tv_flag</font><font color = "silver">.</font><font color = "maroon">table_id</font> <font color = "silver">=</font> <font color = "red">'PROGPR'</font>
<br/>            <font color = "blue">AND</font> <font color = "maroon">decode_tv_flag</font><font color = "silver">.</font><font color = "maroon">table_code</font> <font color = "silver">=</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">tv_prem_live_none</font>
<br/><font color = "blue">WHERE</font>  <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_code</font> <font color = "silver">=</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">channel_code</font>
<br/>       <font color = "blue">AND</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">schedule_date</font> <font color = "blue">BETWEEN</font> <font color = "red">'20110701'</font> <font color = "blue">AND</font> <font color = "red">'20110705'</font>
<br/>       <font color = "blue">AND</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">tv_prem_live_none</font> <font color = "silver">!=</font> <font color = "red">'R'</font>
<br/><font color = "blue">ORDER</font>  <font color = "blue">BY</font> <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_name</font> <font color = "blue">DESC</font> 
</font>
 
Last edited:
Upvote 0
Actually I think you can exclude the "channel c" in your FROM statement as you're joining it anyway.

Revised:


<font face="Courier New" size="2">
<font color = "blue">SELECT</font> <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_name</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Dstr</b></font><font color = "maroon">(</font><font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">schedule_date</font><font color = "maroon">)</font> <font color = "maroon">tx_date</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Tstr</b></font><font color = "maroon">(</font><font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">start_time</font><font color = "maroon">)</font>    <font color = "blue">AS</font> <font color = "maroon">start_tm</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Tstr</b></font><font color = "maroon">(</font><font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">duration</font><font color = "maroon">)</font>      <font color = "blue">AS</font> <font color = "maroon">slot_duration</font><font color = "silver">,</font>
<br/>       <font color = "maroon">t</font><font color = "silver">.</font><font color = "maroon">programme_name</font>       <font color = "blue">AS</font> <font color = "maroon">title</font><font color = "silver">,</font>
<br/>       <font color = "maroon">decode_tv_flag</font><font color = "silver">.</font><font color = "maroon">table_description</font><font color = "silver">,</font>
<br/>       <font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_name</font><font color = "silver">,</font>
<br/>       <font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_code</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>Tstr</b></font><font color = "maroon">(</font><font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_slot_duration</font><font color = "maroon">)</font>
<br/><font color = "blue">FROM</font>   <font color = "maroon">schedule_item</font> <font color = "maroon">si</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">channel</font> <font color = "maroon">C</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_code</font> <font color = "silver">=</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">channel_code</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">purchase</font> <font color = "maroon">p</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">purchase_id</font> <font color = "silver">=</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">purchase_id</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">title</font> <font color = "maroon">t</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">t</font><font color = "silver">.</font><font color = "maroon">title_id</font> <font color = "silver">=</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">title_id</font>
<br/>       <font color = "maroon">join</font> <font color = "maroon">deal</font> <font color = "maroon">d</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">d</font><font color = "silver">.</font><font color = "maroon">deal_id</font> <font color = "silver">=</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">deal_id</font>
<br/>       <font color = "maroon">left</font> <font color = "maroon">join</font> <font color = "maroon">table_line</font> <font color = "maroon">decode_tv_flag</font>
<br/>         <font color = "blue">ON</font> <font color = "maroon">decode_tv_flag</font><font color = "silver">.</font><font color = "maroon">table_id</font> <font color = "silver">=</font> <font color = "red">'PROGPR'</font>
<br/>            <font color = "blue">AND</font> <font color = "maroon">decode_tv_flag</font><font color = "silver">.</font><font color = "maroon">table_code</font> <font color = "silver">=</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">tv_prem_live_none</font>
<br/><font color = "blue">WHERE</font>  <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_code</font> <font color = "silver">=</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">channel_code</font>
<br/>       <font color = "blue">AND</font> <font color = "maroon">si</font><font color = "silver">.</font><font color = "maroon">schedule_date</font> <font color = "blue">BETWEEN</font> <font color = "red">'20110701'</font> <font color = "blue">AND</font> <font color = "red">'20110705'</font>
<br/>       <font color = "blue">AND</font> <font color = "maroon">p</font><font color = "silver">.</font><font color = "maroon">tv_prem_live_none</font> <font color = "silver">!=</font> <font color = "red">'R'</font>
<br/><font color = "blue">ORDER</font>  <font color = "blue">BY</font> <font color = "maroon">c</font><font color = "silver">.</font><font color = "maroon">channel_name</font> <font color = "blue">DESC</font> 
</font>
 
Upvote 0
Well at least now I get "SI"."CHANNEL_CODE": invalid identifier

Had this before... should it not be

Code:
join channel c on c.channel_code = si.channel_code

? Shooting in the dark here :P
 
Upvote 0
Well at least now I get "SI"."CHANNEL_CODE": invalid identifier

Had this before... should it not be

Code:
join channel c on c.channel_code = si.channel_code

? Shooting in the dark here :P

Doing so, (changing to as above), I get 'column ambiguously defined' - which I think is why I tried it the way I originally had it, because it stopped that error coming up.

This is the problem with trying to just 'figure it out'. I can tweak and tweak to try and knock off each individual error as it comes up, but without knowing what my tweaks do to the rest, I'm possibly just going round in circles. In fact I think I might be
 
Upvote 0
I think that's what I changed it to?

channel_code is definitely a field name right? I think the syntax is right - Well at least SQL server says it is when I remove the function names, I'd double check the field names
 
Upvote 0

Forum statistics

Threads
1,216,165
Messages
6,129,246
Members
449,497
Latest member
The Wamp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top