View update raises ORA-01733 - sql

I created a view and then I want to update the cost and show the error. But it reterns that virtual column not allowed.
View:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
CONCERT.TYPE, TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
Below is the error:
Error starting at line 1 in command:
UPDATE CONCERT_EVENTS1
SET formated_cost = '300.00'
WHERE formated_cost = '200.00'
Error at Command Line:2 Column:5
Error report:
SQL Error: ORA-01733: virtual column not allowed here
01733. 00000 - "virtual column not allowed here"
*Cause:
*Action:
Thanks in advance

FORMATED_COST is probably a calculated field, or in any case the
database cannot infer what change is to be made to the tables
underlying the view based on the change you are requiring.

Include an extra column in your view on CONCERT.COST without the formatting. And update only that new column. The explanation of why this is needed is given by Vignesh Kumar.

Related

SQL redshift: Updating a column with data from another table but get an error, why?

I am using redshift and have followed this from an example. But I get the error:
[42601] ERROR: syntax error at or near "INNER" Position:
UPDATE podcast_platform_episode_level
INNER JOIN podcast_country_codes
ON podcast_platform_episode_level.country = podcast_country_codes.country
SET podcast_platform_episode_level.country_label = podcast_country_codes.country_label
Try this
UPDATE podcast_platform_episode_level
SET country_label = podcast_country_codes.country_label
FROM podcast_country_codes
WHERE podcast_platform_episode_level.country = podcast_country_codes.country
I renamed a column to country_code in podcast_platform_episode_level to help avoid confusion. But still surpised this code below works when the code above does not
-- adds country_label data
UPDATE podcast_platform_episode_level
SET country_label = c.country_label
FROM podcast_country_codes c
WHERE c.country = country_code;

Cannot run the query as it says "unable to execute query, invalid operation or syntax using multi-valued field" in Access

SELECT
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening AS NumberUniquePatientsWithDepressionScreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years,
[qry_numberofpatientsgreaterthan12withdepressionscreen]![numberofuniquepatientsagegreaterthan12withdepressionscreening] /
[qry_numberofuniquepersonsgreaterthan12years]![numberofuniquepersonsgreaterthan12years] AS PercentageOfPatientsGreaterThan12WithDepressionScreen
FROM
(
tbl_facilityinformation INNER JOIN qry_numberofpatientsgreaterthan12withdepressionscreen ON
tbl_facilityinformation.exportid = qry_numberofpatientsgreaterthan12withdepressionscreen.exportid
)
INNER JOIN qry_numberofuniquepersonsgreaterthan12years ON
tbl_facilityinformation.exportid = qry_numberofuniquepersonsgreaterthan12years.exportid
GROUP BY
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years;
I dont understand why I'm getting the error:
Unable to execute query, invalid operation or syntax using multi-valued field.
I have tried to look for syntax errors but could not find any.

Create a view error

Hello I am trying to create a view using the following:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
CONCERT.COST AS TO_CHAR(COST, 'L9,999.99')
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
Below is the error I'm receiving:
Error starting at line 1 in command:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
CONCERT.COST AS TO_CHAR(COST, 'L9,999.99')
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID
Error at Command Line:2 Column:113
Error report:
SQL Error: ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
What is the problem with my SQL?
The AS statement is incorrect. AS is used in selects to rename a column. So CONCERT.COST as CONCERT_COST would rename the column to CONCERT_COST in your view. If you want to format the column, that goes to the left of the as:
TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
if you still want to rename the column.
Your "AS TO_CHAR(COST, 'L9,999.99')" is not quite right. The "As" statement is used to alias a column, you don't want the column to be named "TO_CHAR(COST, 'L9,999.99')"
I believe what you want is:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
TO_CHAR(CONCERT.COST, 'L9,999.99') as 'ALIAS_HERE'
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
This message always indicates a syntax error in the query projection, the bit between the SELECT and the FROM keywords:
ORA-00923: FROM keyword not found where expected
You are still getting it because you have muffed the suggested fix for your original bloomer. Now you have two declarations for the COST column ....
CONCERT.COST TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
Syntax demands we put a comma between every column in the projection:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID
, EVENT.EVENT_ID
, CONCERT.NAME
, EVENT.DATE1
, CONCERT.DURATION
, CONCERT.COST
, TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
FROM EVENT INNER
JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID
Alternatively, if you don't want the numeric COST column in the view just drop it.
I know syntax errors are hard for beginners but you really need to learn to look at your own code with a cool eye. You can't come running to SO every time you've dropped a comma. Laying out your code in a proper fashion will help: code which is easier to read is easier to debug. For the same reason you should avoid putting all your code in UPPER CASE.

Oracle SQL Create View invalid identifier

I'm needing to create view where I basically have to combine three tables in order to see when a contact was last verified. This is the code I have so far:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW
LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE VERIFIED_ON IS NULL OR
VERIFIED_ON > SYSDATE-365
ORDER BY LASTNAME;
I keep getting this error and can't figure out why.
Error at Command Line:10 Column:7
Error report:
SQL Error: ORA-00904: "VERIFIED_ON": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
If anyone could help I would greatly appreciate it.
You are using verified_on in the where clause. I think you need last_date_verified instead:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT
OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE OC.LAST_DATE_VERIFIED IS NULL OR
OC.LAST_DATE_VERIFIED > SYSDATE-365
ORDER BY LASTNAME;
You can't use a column alias defined in the select clause in the where clause.

Problem with Oracle (Spatial Geometry) query

I'm trying to form a query that returns a list of entities within a given rectangle, using SDO_WITHIN_DISTANCE. The query I've made seems like it should work, but Oracle is giving me some strange errors. Here's the query:
SELECT *
FROM TBLENTITYLOCATION TL
INNER JOIN TBLENTITY TE
ON TE.ENTITYID=TL.ENTITYID
WHERE SDO_WITHIN_DISTANCE (TL.GEOLOCATION
, SDO_GEOMETRY (2003
, NULL
, NULL
, SDO_ELEM_INFO_ARRAY(1, 1003, 3)
, SDO_ORDINATE_ARRAY(41, -73, 36, -82)
), 'DISTANCE=10 UNIT=M'
) = 'TRUE'
AND TL.LOCATIONDATETIME= (select MAX(LOCATIONDATETIME)
FROM TBLENTITYLOCATION
WHERE ENTITYID = TE.ENTITYID)
The error is as follows:
ORA-29902: error in executing ODCIIndexStart() routine
ORA-13208: internal error while evaluating [window SRID does not match layer SRID] operator
ORA-06512: at MDSYS.SDO_INDEX_METHOD_10I", line 286
OERR says:
29902. 00000 - "error in executing ODCIIndexStart() routine"
*Cause: The execution of ODCIIndexStart routine caused an error.
*Action: Examine the error messages produced by the indextype code and take appropriate action.
Thanks for any help or ideas.
The ORA-13208 error is the prime one here.
The TL.GEOLOCATION needs a matching value in the SRID (second parameter of the SDO_GEOMETRY)
See if the response here helps you out.
Gary Myers provided correct answer, let me augment it. If you don't know which SRID is used by your table, do a query:
select SRID from USER_SDO_GEOM_METADATA where TABLE_NAME='TBLENTITYLOCATION' and COLUMN_NAME='TBLENTITYLOCATION'
Also, to query for objects which are within a rectangle, you don't need SDO_WITHIN_DISTANCE operator. Instead, use SDO_RELATE with mask=ANYINTERACT. See http://docs.oracle.com/cd/B12037_01/appdev.101/b10826/sdo_operat.htm#i78531 for more details.