Select column based on values in another table names.
I would like to generate a sql statement based on the values in a table. For example, I would start "Select division from tableA".In the above example, 'division' would be a value of a column in TableB. Perhaps to looking like this.
Table B
The ColumnName of primary key
-----
-----
Division of 1234
Division of 3456
Department of 7890
I don't want back 'Division' of table B, based on the primary key = 1234 and then generate the SQL above.
Any ideas?
TIA
It can be done through a PL/SQL block or the stored procedure.
Below is a PL/SQL block to give you an idea:
declare NewColumnName varchar2(50); SqlString Varchar2(200);begin select ColumnName into NewColumnName from TableB where PrimaryKey = 1234; sqlString := 'select ' || NewColumnName || ' from TableA'; execute immediate sqlString;end;
Tags: Database
Similar Questions
-
Hello
I'm trying to achieve the following objectives:
1. in table A, select rows based on the values in column 2. something like SELECT * FROM TABLE A WHERE (COLUMN2 = 'X' or Column2 IS NULL)
2 and these values selected, I want to update Column3 from Table A if TableA.column1 = TableB.column1, but only if there is exactly one game. If there are multiple matches, column 3 of the table article updated.
That's what I've tried so far.
UPDATE TABLE_A
SET
TABLE_A.COLUMN3 = (SELECT COLUMN3 OF TABLE_B
WHERE ((TABLE_B.COLUMN1 = TABLE_A.COLUMN1) AND ( TABLE_B.COLUMN1 IN (SELECT Column1 FROM TABLE_B GROUP BY COLUMN1 , HAVING COUNT (*) = 1)))
WHERE EXISTS (SELECT * FROM TABLE_A)
WHERE ((TABLE_A.COLUMN2 = 'X' OU TABLE_A.COLUMN2 = 'Y') AND (TABLE_A.COLUMN4 IS NULL OR TABLE_A.COLUMN4 = ' ')));
More details on my DB environment:
Version Info:
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
PL/SQL Release 11.2.0.4.0 - Production
Toad, but, depending on whether the query updated all lines. I would really appreciate if someone could tell me how to fix my request.
Thanks in advance.
Exists it predicate in the block of update will be set to true if there is at least one row in table_a where column2 is X or Y and column4 is null or a space. You need to correlate exists it with the outer query query (I'm guessing on column1) to get the result I think you want. However, who would update all rows in table_a who meets the criteria, there is a corresponding row in table_b, affecting Column3 lines form null not matched or not. (Again), I'm guessing that's not your intention. If you only want to update the lines in table_a which have a corresponding line in table_b and meet the other predicate, then I think you want something more like:
Update table_a
Set table_a.column3 = (select column3 of table_b
where table_b.column1 = table_a.column1 and
Table_B.Column1 in (select column1 from table_b
Group by column1, having count (*) = 1))
where ((table_a.column2 = 'X' ou))
table_a.Column2 = 'Y') and
(table_a.column4 is null or)
table_a.column4 = ' ')) and
table_a.Column1 in (select column1 from table_b
Group by column1, having count (*) = 1)
John
-
Validation form column against the value of another Table
Hello
I'm new to this forum, so please bear with me a bit! I only have a small amount of writing PL/SQL experience, and I've never written Javascript or JQuery before. I am an Oracle DBA and I coding experience C and PERL, so I have a strong technical background. But I need some advice on the best way to approach a problem.
I have an application of data base in Oracle Apex (version 4.2) with a tabular form on a table: Let's say that #1 with the conditions of licence 1 a, 1 b, and1C. I have to make sure that the value entered in col B is not greater than the value of a column in another table (for example table #2 pass 2 (a). From a conceptual point of view, the amount of money available is in the #2 table, and my tabular form lines are an act of spending money (such as orders or invoices), so I have to make sure that we spend more that we have. Who is?
Does anyone have tips for the best way to do it? I'm figuring that the biggest problem here is perhaps to account for people who enter multiple lines in the form of tables at the same time, right? So, if a person is entered 3/invoices, I need a total to ensure that they do not have spend more than we have in the #2 table.
I really appreciate your help!
Best regards
Laurie Baublitz
Ah, I was not totally with you on this charge then. My validation works overall, but it totals the amount for each line, regardless of the task. Okay - who was not totally my solution but more a demonstration of the technique that you can use to validate your tabular presentation in this way.
You could solve this issue with a safe collection, or with a table plsql where you add an entry for each task name and keep the amount stored in there.
Anyway, it would be better for you to spend a little time on playback on the plsql collections or collections apex!
Remember, this is a sample and you will need to take stock of it. The best solutions are those where you need to experiment with 8)
DECLARE TYPE tt_taskamount IS TABLE OF NUMBER INDEX BY VARCHAR2(20); t_taskamount tt_taskamount; l_task VARCHAR2(20); l_amount NUMBER; l_max NUMBER; BEGIN -- F02 is the taskname -- F03 is the amount -- adapt to your situation! FOR i IN 1..apex_application.g_f02.count LOOP l_task := apex_application.g_f02(i); l_amount := apex_application.g_f03(i); IF NOT t_taskamount.exists(l_task) THEN t_taskamount(l_task) := l_amount; ELSE t_taskamount(l_task) := t_taskamount(l_task) + l_amount; END IF; -- it's not the best idea to perform a select each time and could be -- done better but for the sake of the example it's fine -- not too bad either if the rowcount is small. SELECT maxamount INTO l_max FROM table2 WHERE taskname = l_task; IF t_taskamount(l_task) > l_max THEN -- returning will stop further processing and throw an error message as soon as a budget has been overrun -- it might or might not be required behaviour but that's up to you RETURN 'The max amount ('||l_max||') for task ' || l_task ||' has been exceeded. Reduce the total amount on associated tasks!'; END IF; END LOOP; END;
-
update of several columns of values in another table
Hello
I have two tables in a database of 11 GR 2 that contain similar data. There is no FK relationship between the two tables, and for now, I need the data in MASTER to match what is in the SECONDARY. Table data types are the same with the same length.
Table 1 is called MASTER and columns are:
MTID
ADDRESS1
ADDRESS2
CITY
Table 2 is called SECONDARY and columns are:
SDID
ADDRESS1
ADDRESS2
CITY
MID and SID are the same on both, but the rest of the columns may be the same or in some cases are different.
I ran the following query that lets me know there are 20 k odd rows that have different data in these lines (I'm not at work at the mo so do not have the exact query I ran or table column names, but it's close enough).
I need to update the rows in the master of secondary school where these values are different. I tried a few different queries updated with no luck.select m.address1 as maddress1, s.address1 as saddress1, m.address2 as maddress2, s.address2 as saddress2, m.city as mcity, s.city as scity from master m, secondary s where m.mtid = s.sdid and m.address1 != s.address1 or m.address2 != s.address2 or m.city != s.city /
I want to do something like
But I want to update columns address1 and address2, city of master.update m.address1 set m.address1=s.address1 where m.address1 != s.address1 and m.mtid = s.stid;
Any ideas on how I can do this? After you run the update results of my select query should return no rows.
Thanks in advance and I hope that the question made sense.1008991 wrote:
I got a similar error as well:update master m set (sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde) = (select sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde from secondary s where s.sd_key = m.sm_key ) where exists ( select 1 from secondary s where s.sd_key = m.sm_key and (s.sm_user_addr_1 != m.sm_user_addr_1 or s.sm_user_addr_2 != m.sm_user_addr_2 or s.sm_user_city != m.sm_user_city or s.sm_user_postal_cde != m.sm_user_postal_cde)); ERROR at line 3: ORA-01427: single-row subquery returns more than one row
It simply means that you have several lines with the same sd_key for a given sm_key.
Is that you have secondaries for one master. You must choose only one line
If you need additional terms in your where clauseselect sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde from secondary s where s.sd_key = m.sm_key
-
Vs fusion - update to update a table based on values in another
Hello
I have two lets say tables TAB_A and TAB_B I have changed the table B to include a new column of table A
I wrote a merge statement to merge data
MERGE INTO TAB_A
WITH THE HELP OF TAB_B
ON (TAB_A.SECURITYPERSONKEY = TAB_B.SECURITYPERSONKEY)
WHEN MATCHED THEN
UPDATE TAB_A.PPYACCOUNT SET TAB_B.PPYACCOUNT =.
I know INSERT to insert new records
UPDATE to my knowledge is to modify existing records currently (in the broad sense)
FUSION is one I rarely used, until the present case.
The code works perfectly fine, but I was wondering how I could write an update statement? Or in this case can I still use an update statement?
If you like an editable view, then you must reference column aliases in the set, not the names of columns clause. More like:
Update (tab_a.ppyaccount select a_ppyaccount, tab_b.ppyaccount b_ppyaccount)
of tab_a
Join tab_b
We tab_a.securitypersonkey = tab_b.securitypersonkey)
Set b_ppyaccount = a_ppyaccount;
John
-
Add column if the value in another column
How can I add a column as column name 'YES_OR_NO.
SELECT VALUE_ID IN THE TABLE TABLE_NAME
VALUE_ID
---
1
2
3
4
5
Now, I want to create another column in the sql query called YES_OR_NO and that if there is a value in VALUE_ID then column YES_OR_NO must say 'YES' if there is no value in the column VALUE_ID of this line YES_OR_NO must say 'NO '.
or just a way for her also to work would be to show this new column or not if a value in another column of table_name_2 (this would be ideal)
If new column yes_or_no and fill by a Yes or a no if a value is found in another tableAssuming that you are on a version that supports the CASE expression:
SELECT VALUE_ID , case when VALUE_ID is null then 'NO' else 'YES' end as YES_NO FROM TABLE_NAME
-
How to insert duplicate values in another table.
angle of attack!
I created two tables a and b
create table one
(key primary code number);
create table b
(code number,
DAT date);
insert into the table of a (code)
values (1234);
insert into the table of a (code)
values (1235);
commit;
Select * from a;
one
-----
1234
1235
-----
insert into the table of a (code)
values (1234);
commit;
ERROR on line 1:
ORA-00001: unique constraint (GMS. SYS_C0030897) violated
{color: #ff0000} * I need, when the user inserts duplicate data, must be inserted into another table b.* {color}
How can I do in forms 6i? Help, please. Thanks in advance.
Hello
What is the relationship with the forms?
Anyway, you can create a trigger on table A that intercepts the error in an exception block, and then create a new row in table B.
If the error comes from a forms based block, intercept the error in a trigger insert.François
-
You will need to change based on values in another article LOV...
Hi all
I got a mudbrick THAT LOV based on a value in another column. Let me explain... Assume that A value in the column is A1 then column B should show A11, A12, A13 and if column A is the value C cloumn B should show C11, C12... etc. The LOV will be static with some pre defined values. So all the LOVs will be defined in the forms. We just need to show based on the value in column A.
Please suggest.
Thank you.
Published by: Amit1cs on April 18, 2013 19:40Amit1cs wrote:
Hi allI got a mudbrick THAT LOV based on a value in another column. Let me explain... Assume that A value in the column is A1 then column B should show A11, A12, A13 and if column A is the value C cloumn B should show C11, C12... etc. The LOV will be static with some pre defined values. So all the LOVs will be defined in the forms. We just need to show based on the value in column A.
Please suggest.
Hello Amit,
Up to now, I understand, you can create several record group for a single LOV. before you display the lov just to change or assign the appropriate record group. You can use pre-text-element column B trigger and set the record group to your LOV.Hope this helps
Hamid
-
Insert values from another table
Hello I have a table:
T1
---
ID
user
and another table:
T2
---
intellectual property
Mac
So I modified T1:
ALTER table T1 add ip number (20);
ALTER table T1 add mac number (20);
So I have:
T1
---
ID
user
intellectual property
Mac
T1 and T2 are the same number of lines.
Now, I want to insert the values of IP and mac of T2 in the fields ip address and mac of T1.
IP and mac of T2 fields can be "not null".
How can I do?
Thanks in advanceand what do you think about something like this:
UPDATE t1 SET t1.mac = (SELECT t2.mac FROM t2 WHERE t2.id = t1.id), t1.ip = (SELECT t2.ip FROM t2 WHERE t2.id = t1.id)
Give it a shot... validate the results before stolen.
HTH,
Thierry -
How can I update this table with values from another table?
Hello
I have a table 'governed '. I want to replace the values in the column "regies.agent" by the value of the column "regies_personnes.id."
As you can see the tables have a column of common values. IE regies.agent = regies_personnes.nom
Table 'governed ':
Insert into 'authorities' (AGENT) values ('Humberdot Alain");
Insert into 'authorities' (AGENT) values ("Danard Patrick");
Table 'regies_personnes ':
Insert into REGIES_PERSONNES (NAME, ID) values ("Humberdot Alain", 1);
Insert into REGIES_PERSONNES (NAME, ID) values ("Danard Patrick", 2);
Before having it
SQL > select agent of authorities;
Humberdot Alain
Patrick Danard
After the update, the result should be
SQL > select agent of authorities;
1
2
Thank you for your kind reply.You can
update regies r set agent = (select id from regies_persones p where r.agent = p.nom) where exists (select id from regies_persones p where r.agent = p.nom)
-
can I use: separation by a comma to compare the values with another table
Hi ALL, I am using oracle 10g, can someone help me with this query
I know I can't use t.valeur in TO would adopt. so I tried to use it in the paragraph, but it did not work.WITH t AS (SELECT 20 ID, 'ABC,DEF,GHI' VALUE FROM DUAL), x AS (SELECT 20 ID, 'ABC' VALUE FROM DUAL UNION ALL SELECT 20, 'DEF' FROM DUAL UNION ALL SELECT 20, 'GHI' FROM DUAL) SELECT x.ID, x.VALUE FROM x, t WHERE x.VALUE IN (t.value); o/p required ------------------- 20 ABC 20 DEF 20 GHI
''''|| Replace (T.valeur, ",", "", "') |" '
Published by: DeepakDevarapalli on December 15, 2009 19:27Hello
Here's a way to do it:
SELECT x.ID , x.VALUE FROM x JOIN t ON ',' || t.value || ',' LIKE '%,' || x.value || ',%' ;
Extra commas are necessary to avoid the problem of 'mother is in chemotherapy,' when a single value can be one substring of another. If this is impossible (as in your case, where all values are exactly 3 characters) then you don't have them.
-
How to recover new logical column based on values of table hint.
Hello
I have two tables in SPR
1. file table contains the coulmns-> date, numero_fichier, record_count, cldm_stg, cmsa_stg, archive_stg
2 rejection table columns are--> same as above
both have same common requirement of columns.my is to publish a dashboard as:
Date | County land_files | alnd_recordscount | County target_files | target_records County | Rejection filecount | number of records release
These report ineed recover from these two tables.based on countcomes values.taget flag when all values of ILI value = 'y '.
IE (cldm_stg = 'y' and cmsa_stg = 'y' and archive_stg = 'y') if not then it will be in the release file.
Please give solution how to achieve my output.
[nQSError: 14026] Impossible to navigate the requested term: Target_record: [DAggr (FILE_CONTROL. Target_record by [FILE_CONTROL. FILE_NAME, REJECTED_FILES. File_name, REJECTED_FILES.NO_OF_ROWS, File_landing.NO_OF_ROWS, File_landing. (FILE_LOAD_DATE] SB FILE_CONTROL)]. Correct metadata consistency warnings. (HY000)
Published by: user8767586 on January 12, 2010 04:29First answer the following questions:
What is your fact table?
What are your dimension tables? -
How to create a table with a column that is the value in another table?
Hi all,
It's my first post n I changed my ODI of DATASTAGE platform. Help me friends n I know basic steps in 11 ODI version which I was training in my company. I hope to have your support and can do everything an action ODI related documents.
My question is...
Table T1 > > > > > > > > > >
service id / / / attr.name / / / attr.value
S1 / / / product_code / / / P1
S1 / / / provider / / / pro1
S2 / / / product_code / / / P2
S3 / / / provider / / / pro3
Table T2 > > > > > > > > > > > > > > >
ID / / / product_code / / / provider
S1 / / / p1 / / / pro1
S2 / / / p2 / / / nullvalue
S3 / / / nullvalue / / / pro3
I have a table T1 since I should show the table T2 is released. Can we say everything on how to write a logic and steps to follow.
Thanks in advance.
Published by: 854662 on April 26, 2011 01:59Hello
U go.
1 the interface:
"Put a filter in your 1 on attr.name = array ' PRODUCT_CODE.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PRODUCT_CODE = TABLE1. ATTR_VALUEUse SQL IKM append control
Interface 2:
"Put a filter in your 1 on attr.name = array ' PROVIDER '.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PROVIDER = TABLE1. ATTR_VALUEDo SERVICE_ID as KEY (when you click the column target in properties, you can see KEY under properties of the target column) and use the incremental update of the IKM Oracle.
PS: I assume that Oracle as the source and target.
And you can refer to the documentation,
https://Apex.Oracle.com/pls/Apex/f?p=44785:24:4413167952886630:no:24:P24_CONTENT_ID, P24_PREV_PAGE:5185, 29
http://odiexperts.com/
And of course this OTN.
Thank you
Guru -
How to select the record in the mulitple rows based on values in another field?
Hello
Sorry for the bad title, really don't know how to explain it
Have the following data:
I need to return a list of cost (with its associated activity types) centers have no activity types of CLBR0 and CLBR1 and TLBR0 and TLBR1 and VEH01. So in the above data, cost center, 1005009401, and 1005009402 will be returned.Cost_center Activity_type 1005009401 CLBR0 1005009401 CLBR1 1005009401 TLBR0 1005009401 TLBR1 1005009401 VEH00 1005009402 CLBR3 1005009402 CLBR4 1005009402 TLBR5 1005009402 TLBR6 1005009402 VEH07 1005009901 CE000 1005009901 CLBR0 1005009901 CLBR1 1005009901 TLBR0 1005009901 TLBR1 1005009901 VEH01
Any thoughts?
Thank you.
Published by: dgouin on August 29, 2012 11:42 - added several examples of data.
Published by: dgouin on August 29, 2012 11:45
Published by: dgouin on August 29, 2012 11:49Sorta kludgey, but functional:
WITH ccs AS ( SELECT '1005009401' AS CC, 'CLBR0' AS activity_type FROM dual UNION ALL SELECT '1005009401' AS CC, 'CLBR1' AS activity_type FROM dual UNION ALL SELECT '1005009401' AS CC, 'TLBR0' AS activity_type FROM dual UNION ALL SELECT '1005009401' AS CC, 'TLBR1' AS activity_type FROM dual UNION ALL SELECT '1005009401' AS CC, 'VEH00' AS activity_type FROM dual UNION ALL SELECT '1005009901' AS CC, 'CE000' AS activity_type FROM dual UNION ALL SELECT '1005009901' AS CC, 'CLBR0' AS activity_type FROM dual UNION ALL SELECT '1005009901' AS CC, 'CLBR1' AS activity_type FROM dual UNION ALL SELECT '1005009901' AS CC, 'TLBR0' AS activity_type FROM dual UNION ALL SELECT '1005009901' AS CC, 'TLBR1' AS activity_type FROM dual UNION ALL SELECT '1005009901' AS CC, 'VEH01' AS activity_type FROM dual ) SELECT cc, activity_type FROM ccs c1 WHERE 5 != (SELECT COUNT(DISTINCT activity_type) FROM ccs c2 WHERE activity_type IN ('CLBR0','CLBR1','TLBR0','TLBR1','VEH01') AND c1.cc = c2.cc ); CC ACTIVITY_TYPE ---------- ------------- 1005009401 CLBR0 1005009401 CLBR1 1005009401 TLBR0 1005009401 TLBR1 1005009401 VEH00
-
Filter a column with the value of another
Hello. Hope someone can help with this... On my search page, I want to use the value of the first list/drop-down menu to filter the values of the second list/menu. I use PHP and DW 8.0.2.
Example: The first column has each of the 50 States. second column has 3 000 counties. If a user selects New Jersey, I want to just 21 NJ counties to appear as options in the second menu downwards rather than 3 000 counties.
First Recordset works very well for the States. But in my second recordset, I say 'select distinct County of the said County WHERE AS var1'... and var1 is $recordset1 [County]. But the 2 column is empty. How can I actively pass the value of the first column in the second while the user is still on the same page?
Sandman>>
Assuming that your table has a field named "State":
«select County of States WHERE state = "var1""
>>You can use this solution when the first menu page 1 and the second menu on page 2 (IE passing the value of a query on page 2), but as assumingly, you need to have this functionality within a single page, basic need based on a javascript solution 'drop-down menus of dynamic load' to load the menu2 - options "in situs.
There is an extension for Dreamweaver stand alone for this on the site of Tecnorama , that also wants to work without the relationships between the tables, in other words, with the data in a table, which matches your scenario.
Maybe you are looking for
-
Satellite L40-18 X - wireless switch does not work
Hello I installed Windows 7 on Satellite L40 - 18 x, PSL48E, the installation seems correct. After installation I noticed that the wireless switch on/off (power) switch does not. The wireless network is working except the functionality of switch. It
-
I would like to test some MySQL's stored procedures that have parameters OUT. In Toad for MySQL, I can write CALL CleverProcedure (42, @var); SELECT @var; And I'll get the @var out parameter value. If I try the same thing in my standard, simple 'RunS
-
Question about relaxing break: multiple triggersources
Hello I have two digital signals I want to use as the source for the start of the break. The outbreak of the break is done with a triggernode. The problem I have is that I can add two sources to the node, but it will not react on both, only one. So I
-
I was wondering if anyone has experience covering the X 10 CM15A, which is a transmitter USB for the X 10 home automation groups. I want to be able to control some of labview 110V devices using these devices, and what I found is the older CM11A which
-
Accept the end user license agreement
When you open a pdf file, I get the message "must accept the end user license agreement".