Hi i want to update a specific row of my oracle database via apex. So i need to reach/address the specific row via where clause.
example entries:
GATTUNG
ART
UNTERART
ABART
VARIETÄT
AAA
AAA
AAA
NULL
NULL
AAA
AAA
NULL
NULL
AAA
AAA
AAA
NULL
NULL
NULL
Now i have two approaches.
first:
UPDATE TBL_PFLANZE
SET NAMEN =:P1_NAMEN
WHERE (GATTUNG = :P1_GATTUNG AND ART = :P1_ART_KREUZUNG)
AND ((UNTERART=:P1_UNTERART OR :P1_UNTERART IS NULL) AND (VARIETÄT=:P1_VARIETAET OR :P1_VARIETAET IS NULL) AND (ABART=:P1_ABART OR :P1_ABART IS NULL));
second:
UPDATE TBL_PFLANZE
SET NAMEN ='&P1_NAMEN.'
WHERE (GATTUNG = '&P1_GATTUNG.' AND ART = '&P1_ART_KREUZUNG.')
AND (UNTERART &P1_WHERE_UNTERART. AND VARIETÄT &P1_WHERE_VARIETAET. AND ABART &P1_WHERE_ABART.);
the differences of both approaches are the P1_WHERE_...variables.
the first one use for example :P1_UNTERART and contains the whole value
the second one use for example &P1_WHERE_UNTERART. and contains = '&P1_UNTERART.' OR IS NULL
my problem is:
the first one updates all entries if i only set GATTUNG and ART (if i do not specify one of the other variables)
the second will work, but is not the right approach as I should be using binding variables instead of &VAR.
So my question is, how can i use the first approach which the desired result... :(
Does this do the trick ? It will update the rows if any of the columns have the same value as the corresponding page item or the database column and page item are both null:
UPDATE tbl_pflanze
SET
namen = :P1_NAMEN
WHERE
( gattung = :P1_GATTUNG AND art = :P1_ART_KREUZUNG)
AND
( ( NVL(unterart,'X') = NVL(:P1_UNTERART,'X')) AND
( NVL(varietät,'X') = NVL(:P1_VARIETAET,'X')) AND
( NVL(abart,'X') = NVL(:P1_ABART,'X')) );
The way I see it, the 1st query is correct while the 2nd is wrong.
Why is it wrong? Because you're using strings. This:
SET NAMEN ='&P1_NAMEN.'
WHERE (GATTUNG = '&P1_GATTUNG.'
would want to put litally &P1_NAMEN. string into the NAMEN column for all rows whose GATTUNG column contains literally &P1_GATTUNG. string in it (and there's most probably none, so the 2nd query won't do anything, ever).
So, what is your problem, exactly? Why do you think that the 1st query doesn't work? Did you run the page in debug mode and reviewed debug results? Could it be that P1 page's items aren't stored into session state so UPDATE statement doesn't see them?
Also, where do you execute that UPDATE? As a process which runs after button is pressed? Something else?
Related
I'm working with PeopleSoft Campus Solutions, and we need to update about 22,000 rows of data. This is data between the tables of ACAD_PLAN_VW and ACAD_PROG. Students are listed on both, so their IDs match between the two.
Basically what we are trying to do is say that when the ID, academic career, student career number, effective sequence, and effective date match, AND where the academic plan (their degree, as stored on the ACAD_PLAN_VW) is a specific value, update the ACAD_PROG on the ACAD_PROG table to X value.
I tried to do some very interesting combinations of FROM statements, constantly getting errors. After some researching, I found out that SQLTools doesn't really like FROM statements within UPDATE statements, so I rewrote it to just make the connections manually. I'm assuming I'm doing this right, unless I need to reword it.
The statement I have is:
UPDATE PS_ACAD_PROG SET PS_ACAD_PROG.ACAD_PROG = 'UGDS'
WHERE PS_ACAD_PLAN_VW.EMPLID = PS_ACAD_PROG.EMPLID
AND PS_ACAD_PLAN_VW.ACAD_CAREER = PS_ACAD_PROG.ACAD_CAREER
AND PS_ACAD_PLAN_VW.STDNT_CAR_NBR = PS_ACAD_PROG.STDNT_CAR_NBR
AND PS_ACAD_PLAN_VW.EFFSEQ = PS_ACAD_PROG.EFFSEQ
AND PS_ACAD_PLAN_VW.EFFDT = PS_ACAD_PROG.EFFDT
AND PS_ACAD_PLAN_VW.ACAD_PLAN = 'DSTDS'
Theoretically, I would assume that this would update any student who has those connections. However, the error that I'm currently getting is as follows:
ORA-00904: "PS_ACAD_PLAN_VW"."ACAD_PLAN": invalid identifier
I have, as of yet, been unable to figure out the issue. I do have the correct access to view and update those fields, and the field does indeed exist.
Oracle doesn't know it should use the PS_ACAD_PLAN_VW table. Somehow you should reference it.
For example can you try this way?
UPDATE (
select
PS_ACAD_PROG.ACAD_PROG,
PS_ACAD_PLAN_VW.ACAD_PLAN
from
PS_ACAD_PROG,
PS_ACAD_PLAN_VW
where
PS_ACAD_PLAN_VW.EMPLID = PS_ACAD_PROG.EMPLID
AND PS_ACAD_PLAN_VW.ACAD_CAREER = PS_ACAD_PROG.ACAD_CAREER
AND PS_ACAD_PLAN_VW.STDNT_CAR_NBR = PS_ACAD_PROG.STDNT_CAR_NBR
AND PS_ACAD_PLAN_VW.EFFSEQ = PS_ACAD_PROG.EFFSEQ
AND PS_ACAD_PLAN_VW.EFFDT = PS_ACAD_PROG.EFFDT
)
SET
ACAD_PROG = 'UGDS'
WHERE
ACAD_PLAN = 'DSTDS'
Try to use the table which is not getting identified,by keeping in where clause so that you can use the select statement.That will help identifying the tables.
The following implementation should work:
UPDATE PS_ACAD_PROG
SET ACAD_PROG = 'UGDS'
WHERE ROWID IN(SELECT PROG.ROWID
FROM PS_ACAD_PROG PROG
, PS_ACAD_PLAN_VW PLAN
WHERE PLAN.EMPLID = PROG.EMPLID
AND PLAN.ACAD_CAREER = PROG.ACAD_CAREER
AND PLAN.STDNT_CAR_NBR = PROG.STDNT_CAR_NBR
AND PLAN.EFFSEQ = PROG.EFFSEQ
AND PLAN.EFFDT = PROG.EFFDT
AND PLAN.ACAD_PLAN = 'DSTDS');
I am trying to create a filter with SQL queries but am having trouble with numeric values linking to other tables.
Every time I try to link to another table, it takes the same record and repeats it for every element in the other table.
For example, here is query:
SELECT ELEMENTS.RID,TAXONOMIES.SHORT_DESCRIPTION,[type],ELEMENT_NAME,ELEMENT_ID,SUBSTITUTION_GROUPS.DESCRIPTION,namespace_prefix,datatype_localname
FROM ELEMENTS,SUBSTITUTION_GROUPS,TAXONOMIES,SCHEMAS,DATA_TYPES
WHERE ELEMENTS.TAXONOMY_ID = TAXONOMIES.RID AND ELEMENTS.ELEMENT_SCHEMA_ID = SCHEMAS.RID AND
ELEMENTS.DATA_TYPE_ID = DATA_TYPES.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = 0
The last line is the actual filtering criteria.
Here is an example result:
There should only be ONE result (Item has an RID of 0). But it's repeating a copy of the one record for every result inside the substitution groups table (there's 4).
Here is my database schema for reference. The lines indicate relationships between tables and the circles indicate the values I want:
You're forgot to join between ELEMENTS and SUBSTITUTION_GROUPS in your query.
SELECT
ELEMENTS.RID,TAXONOMIES.SHORT_DESCRIPTION,[type],ELEMENT_NAME,ELEMENT_ID,SUBSTITUTION_GROUPS.DESCRIPTION,namespace_prefix,datatype_localname
FROM
ELEMENTS,SUBSTITUTION_GROUPS,TAXONOMIES,SCHEMAS,DATA_TYPES
WHERE
ELEMENTS.TAXONOMY_ID = TAXONOMIES.RID AND ELEMENTS.ELEMENT_SCHEMA_ID = SCHEMAS.RID
AND ELEMENTS.DATA_TYPE_ID = DATA_TYPES.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = SUBSTITUTION_GROUPS.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = 0
Whats the best way to do a query like this, which will update more than one row:
UPDATE B
SET col_a = 1
Where col_a = 0
I can load the entities then loop them to do the EntitySave for each one, however this seems like overkill. Should I use HQL to do the update? Can I use HQL to do the update?
You can absolutely run an update on more than one row using ORMExecuteQuery. This is an example of a project I worked on:
ORMExecuteQuery("UPDATE Part SET ReleaseDate = :ReleaseDate, ChangeNote = :ChangeNote WHERE ID IN (#Arguments.PartIDs#)", {ReleaseDate = Arguments.ReleaseDate, ChangeNote = Arguments.ChangeNote});
Easy as that... Notice that you specify the parameters as :VarName and feed them in as the second argument of the ORMExecuteQuery function.
I'm having some difficulty with an Update statement.
UPDATE DownPeriod
SET
DownPeriod.EquipmentID = ? ?? ?? ? ?? ?? ? ?,
DownPeriod.DownDate = Forms!Edit!EditDownDateBox,
DownPeriod.DownTime = Forms!Edit!EditDownTimeBox,
DownPeriod.[UpDate] = Forms!Edit!EditUpDateBox,
DownPeriod.UpTime = Forms!Edit!EditUpTimeBox,
DownPeriod.isScheduled = Forms!Edit!EditSchedCheck,
DownPeriod.isUnscheduled = Forms!Edit!EditUnschedCheck,
DownPeriod.Comments = Forms!Edit!EditCommentsDropDown
WHERE DownPeriod.DownPeriodID =Forms!Edit!RecordHistorySubform.Form!DownPeriodID;
Where the question marks are is where im having difficulty, and am not sure what to put.
Everything else about the update will work if I remove that statement so I know im on the right track. The difference with the EquipmentID is that I'm getting this value based on an input for another table entry. To elaborate the user chooses an Equipment Title, which is another field in my Equip Table that will relate to a unique ID.
So far I have tried DLOOKUP("[EquipmentID]", "Equipment", "[Title] = Forms!Edit!EditEquipmentDropDown")
Select statment and
using inner join
I'm at a loss and need help plz!
Thank you!
You say that the user is selecting the title from a dropdown. The dropdown should have a row source on these lines:
SELECT ID, Title FROM Equipment
With ID as a hidden column. Your update should then be:
DownPeriod.EquipmentID = Forms!Edit!EditTitleDropDown
As an aside, I suspect you are doing a lot more work that you need to do to make an MS Access form work.
If it is a new unique id you need an INSERT. If it already exists you should include it as part of your WHERE clause.
WHERE DownPeriod.DownPeriodID =Forms!Edit!RecordHistorySubform.Form!DownPeriodID
AND DownPeriod.EquipmentID = Forms!Edit!EditEquipmentDropDown;
The problem is: I have a list of objects, with some containing the same PlanId property value. I want to only grab the first occurrence of those and ignore the next object with that PlanId. The root problem is a View in the database, but it's tied in everywhere and I don't know if changing it will break a ton of stuff nearing a deadline, so I'm tossing in a hack for now.
So, if I have a list of PlanObjects like such.
Plan1.PlanId = 1
Plan2.PlanId = 1
Plan3.PlanId = 2
Plan4.PlanId = 3
Plan5.PlanId = 4
Plan6.PlanId = 4
I want to take a sub-list from that with LINQ (italics mean an item is not included)
Plan1.PlanId = 1
Plan2.PlanId = 1
Plan3.PlanId = 2
Plan4.PlanId = 3
Plan5.PlanId = 4
Plan6.PlanId = 4
For my needs, it doesn't matter which one is taken first. The Id is used to update a datbase record.
If I didn't explain that well enough, let me know and I'll edit the question. I think it makes sense though.
PlanObjects.GroupBy(p => p.PlanId).Select(r => r.First());
The other answer (and its comments) supplies the fluent interface solution. Here's the query syntax:
From p In PlanObjects Group By p.PlanId Into First Select First