I am trying to self educate myself in SQL in order to better use databases at work. I am currently trying to code an SQL query in Oracle Application Express that will provide me with a report for management, however I am receiving the following error message:
ORA-01747: invalid user.table.column, table.column, or column specification
I have spent countless hours searching for the bug and doing research and I am getting nowhere, which is quite frustrating as I feel its probably something rather easy. My research has shown me that the probable cause of my error is that I have tried to reference a column name, but the column name used is a reserved word in Oracle. Unfortunately, I am having trouble pinpointing what exactly... Please see below for the code:
SELECT Channel.Channel_Number, Supplier.Supplier_Name, package.Package_Name, Program.Program_name, Rating.Rating_Code, Weekly_Guide.ShowTime
FROM Channel, Supplier, package, Program, Rating, weekly_guide, channel_package
Where weekly_guide.date = ''
AND channel.channel_number = weekly_guide.channel_number
AND weekly_guide.Program_ID = Program.Program_ID
AND channel.channel_number = channel_package.channel_number
AND channel_package.package_ID = package.package_ID
AND Program.rating_code = rating.rating_code
AND Program_list.Program_ID = Program.Program_ID
AND Program_list.list_ID = list.list_id
AND list.supplier_ID = Supplier.supplier_ID
It's most likely date from your Where clause. You'll need to wrap the reserved word in quotes. The name will then be case sensitive, so make sure you have the correct case for date in your query
SELECT Channel.Channel_Number, Supplier.Supplier_Name, package.Package_Name, Program.Program_name, Rating.Rating_Code, Weekly_Guide.ShowTime
FROM Channel, Supplier, package, Program, Rating, weekly_guide, channel_package
Where weekly_guide."date" = ''
AND channel.channel_number = weekly_guide.channel_number
AND weekly_guide.Program_ID = Program.Program_ID
AND channel.channel_number = channel_package.channel_number
AND channel_package.package_ID = package.package_ID
AND Program.rating_code = rating.rating_code
AND Program_list.Program_ID = Program.Program_ID
AND Program_list.list_ID = list.list_id
AND list.supplier_ID = Supplier.supplier_ID
Related
Every time I try to run this select statement I get told there is a syntax error. Can someone please help me figure out what the syntax error is?
SELECT
ZERO_SALES.STORE_NUMBER,
COUNT( * ) AS COLUMN0001,
ZERO_SALES.SKU_NUMBER
FROM
MM4R5LIB.ZERO_SALES ZERO_SALES,
MM4R5LIB.INVMST INVMST,
MM4R5LIB.OPORBK OPORBK,
MM4R5LIB.TBLSTT TBLSTT,
MM4R5LIB.TBLSTR TBLSTR
WHERE
ZERO_SALES.SKU_NUMBER = INVMST.INUMBR
AND INVMST.INUMBR = OPORBK.INUMBR
AND ZERO_SALES.STORE_NUMBER = OPORBK.ISTORE
AND OPORBK.ISTORE = TBLSTT.STRNUM
AND TBLSTT.STRNUM = TBLSTR.STRNUM
AND ZERO_SALES.STORE_NUMBER = 6009
AND ZERO_SALES.SKU_NUMBER =(233879, 659250, 240896)
GROUP BY
ZERO_SALES.STORE_NUMBER,
ZERO_SALES.SKU_NUMBER
I am trying to get a list of the number of occurrences for each SKU number for this particular store.
I transferred this code directly from SQL developer. Works perfectly in there.
SELECT
a.INCIDENT_NUMBER,
a.DETAILED_DESCRIPTION,
a.INCIDENT_ROOT_CAUSE
FROM
N_EVALUATION as a
INNER JOIN N_DISPOSITION as b
ON (a.INCIDENT_NUMBER = b.INCIDENT_NUMBER)
WHERE
b.DISPOSITION_LINE_NUM in (NULL, 1) AND
a.ACTIVE_FLAG = 'Y' AND
b.ACTIVE_FLAG = 'Y' AND
a.DETAILED_DESCRIPTION IS NOT NULL
However when I transfer the same exact code into Tableau to create a custom SQL query. It gives me an error;
An error occurred while communicating with the data source. Bad
Connection: Tableau could not connect to the data source. Oracle
database error 907: ORA-00907: missing right parenthesis
This has me completely stumped, not really sure what to do here. Any help or advice is much appreciated. I am more concerned regarding the missing right parenthesis rather than the bad connection.
Remove the AS from the FROM clause. Oracle does not recognize that.
In addition, this condition:
b.DISPOSITION_LINE_NUM in (NULL, 1)
Does not do what you expect. It never evaluates to true if b.DISPOSITION_LINE_NUM is NULL.
You should replace it with:
(b.DISPOSITION_LINE_NUM IS NULL OR b.DISPOSITION_LINE_NUM = 1)
Otherwise, your query looks like it has balanced parentheses, but you should write it as:
SELECT e.INCIDENT_NUMBER, e.DETAILED_DESCRIPTION, e.INCIDENT_ROOT_CAUSE
FROM N_EVALUATION e JOIN
N_DISPOSITION d
ON e.INCIDENT_NUMBER = d.INCIDENT_NUMBER
WHERE (d.DISPOSITION_LINE_NUM IS NULL OR d.DISPOSITION_LINE_NUM = 1) AND
e.ACTIVE_FLAG = 'Y' AND
d.ACTIVE_FLAG = 'Y' AND
e.DETAILED_DESCRIPTION IS NOT NULL;
Notes:
User meaningful table aliases rather than arbitrary letters (this uses abbreviations).
Do not use as in the FROM clause.
Be careful with NULL comparisons.
Finally, your original query is equivalent to:
SELECT e.INCIDENT_NUMBER, e.DETAILED_DESCRIPTION, e.INCIDENT_ROOT_CAUSE
FROM N_EVALUATION e JOIN
N_DISPOSITION d
ON e.INCIDENT_NUMBER = d.INCIDENT_NUMBER
WHERE d.DISPOSITION_LINE_NUM = 1 AND
e.ACTIVE_FLAG = 'Y' AND
d.ACTIVE_FLAG = 'Y' AND
e.DETAILED_DESCRIPTION IS NOT NULL;
This has no parentheses. So it cannot return that particular error.
I am using Oracle 8i. When I tried to run this below script I am getting the error ora-00923 from keyword not found where expected.
Please find the below query which I am using.
select i.siid,
sp.access_point_status,
csp.id_number,
act.entry_time,
act.addnl_info,
row_num() over (partition by i.siid order by act.entry_time desc) act_row
from table_Service_point sp,
table_case_to_service_point csp,
table_case cs,
table_act_entry act,
(select distinct siid,
iopt.installedopts2axspoint
from table_installed_options iopt,
tmp_efms_clarify inp
where iopt.siid = inp.service_instance
and iopt.siid = 'DSL580155-105-1') i
where sp.objid = csp.case2servicepoint
and csp.id_number = cs.id_number
and cs.objid = act.act_entry2case
and sp.objid = i.installedopts2axspoint
Try using row_number() instead of row_num().
Single quotes '' in oracle denote characters, not names.
Replace
iopt.siid='DSL580155-105-1'
with
iopt.siid="DSL580155-105-1"
I do think row_number() is the correct spelling, not row_num(). Google it for more on how it works. And also, just a reminder, is DSL580155-105-1 actually a column?
I want to update two columns of a table with reference of other tables. While executing the script its showing error.
Error: Error starting at line 1 in command:
UPDATE wb_costing_work_items,
sa_sales_documents,
sa_sales_document_items
SET cwi_price_per_hour = sdi_price,
cwi_amount = sdi_price * cwi_hours
WHERE cwi_lo_id = sad_lo_id
AND sdi_sad_id = sad_id
AND sdi_wit_id = cwi_wit_id
AND cwi_id = 1650833
Error at Command Line:1 Column:28 Error report: SQL Error: ORA-00971:
missing SET keyword
00971. 00000 - "missing SET keyword"
SQL STATEMENT
UPDATE wb_costing_work_items cwi,
sa_sales_documents sad,
sa_sales_document_items sdi
SET cwi.cwi_price_per_hour = sdi.sdi_price,
cwi.cwi_amount = sdi.sdi_price * cwi.cwi_hours
WHERE cwi.cwi_lo_id = sad.sad_lo_id
AND sdi.sdi_sad_id = sad.sad_id
AND sdi.sdi_wit_id = cwi.cwi_wit_id
AND cwi.cwi_id = 1650855
This should definitely work.
UPDATE (SELECT cwi_price_per_hour,
sdi_price,
cwi_amount,
sdi_price,
cwi_hours
FROM wb_costing_work_items,
sa_sales_documents,
sa_sales_document_items
WHERE cwi_lo_id = sad_lo_id
AND sdi_sad_id = sad_id
AND sdi_wit_id = cwi_wit_id
AND cwi_id = 1650833)
SET cwi_price_per_hour = sdi_price, cwi_amount = sdi_price * cwi_hours
Please alias the tables used and prefix columns so one can easily read your query.
Something like this maybe.
Note that I had to use some wild guesses about which column belongs to which table as you have not included any information about how your tables are define.
So most probably I didn't get it right and you will need to adjust the query to your actual table structure.
merge into wb_costing_work_items
using
(
select cwi.pk_column, -- don't know what the PK of the wb_costing_work_items is due to lack of information
sdi.sdi_price, -- don't know if this column really belong to this table
sdi.sdi_price * cwi.cwi_hours as total-- again unsure about column names due to lack of information
FROM wb_costing_work_items cwi
JOIN sa_sales_documents sad ON sad.sad_lo_id = cwi.cwi_lo_id -- not sure about these, due to lack of information
JOIN sa_sales_document_items sdi
ON sdi.sad_id = sad.sdi_sad_id -- not sure about these, due to lack of information
AND sdi.sdi_wit_id = cwi.cwi_wit_id -- not sure about these, due to lack of information
) t ON (t.pk_column = w.pk_column) -- not sure about this, due to lack of information
when matched then
update
set cwi_price_per_hour = t.sdi_price,
cwi_amount = t.total;
First of all, I'm new to the club and must say I find it a very interesting site, and it has really helped me a lot with my coding experiences in C#. Thanks for that.
On a total different note, I'm getting the follow error at one of our customers (we resell document management software). And I'm trying to determine if this error message as stated below can cause performance issues.
Google'ing this error message has already informed me that it can be caused when using Reserved Words as Column Names.
24-4-2012 11:16:49 [ERROR] :There was an error parsing the query. [
Token line number = 1,Token line offset = 77,Token in error = 66667 ]
UPDATE WS_LOCATION SET Frequency = #FreqParams, LUTime =
#LUTimeParams, Client = '', Matter = '' WHERE WSLoc_ID = '22' occured
on InsertIntoLocationTables.
I'm not very familiar with all of the Reserved Words in SQL, perhaps any of you can help me out with determining what is the cause of this error?
It's a local SQL Compact database bytheway (.sdf).
Enclosing your names with brackets will prevent the error of using T-SQL reserved words.
UPDATE [WS_LOCATION] SET
[Frequency] = #FreqParams,
[LUTime] = #LUTimeParams,
[Client] = '',
[Matter] = ''
WHERE [WSLoc_ID] = '22';
If you have a problem with reserved words, prefix your column names with the table name :
UPDATE WS_LOCATION
SET WS_LOCATION.Frequency = #FreqParams, WS_LOCATION.LUTime = #LUTimeParams, WS_LOCATION.Client = '', WS_LOCATION.Matter = ''
WHERE WS_LOCATION.WSLoc_ID = '22'