read in select data from another table
Hello world.
IM Oracle11GR2 database.
I m facing the following problem:
I have 2 tables.
In the first picture, I have a few articles and 3 of these items then come.
(A) point Varchar2
(B) Item Varchar2.
(C) point digital and this point is the id of a record in the other table.
If the digital point > 0 then points A and B must be read in the second table
In the second table, I have 3 Articles.
(A) the id of the record.
B & C point are also point varchar2 and must be read in the first table, point C is > 0.
I'm looking for the way that when I write a normal selection in the first picture he gives me the point B & C of the second table if C point in the first table is > 0.
I thought to solve this problem with a trigger or something similar.
Any idea is welcome.
Regards to everyone.
You don't need a trigger for this. A simple select statement should do. Something like that? I got your if condition perfectly.
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
Look at the following example. Check if it fills your scenario.
-BEGINNING OF THE SAMPLE DATA
WITH T1 AS)
SELECT 'A' A, 'B' B, 1 C OF DOUBLE UNION ALL
SELECT 'C', ', 2 DOUBLE UNION ALL
SELECT 'DF', 'G', THE DOUBLE 0),
() AS T2
SELECT 1, 'X' B 'Y' C DOUBLE UNION ALL
SELECT 2, 'Z', 'BB' OF THE DOUBLE)
-END OF THE SAMPLE DATA
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
OUTPUT:
A B C
-- -- ----------
X Y 1 - since c > 0 A and B values in table 2 are replaced
Z BB 2 - since c > 0 A and B values in table 2 are replaced
DF G 0 - since c = 0, there is even value in table 1
Post edited by: Parth272025
Tags: Database
Similar Questions
-
How can I insert data from another table into a table containing a timestamp column
How you insert data from another table in a table if the target table contains a timestamp column. I tried to set the default value of GETDATE() column in the target table, but it does not work.
I use MS SQLSorry, I managed to get around this by inserting null as the value
-
update of data from another table
Hi, I would like to help. I Don t know how I can start doing:
I have a table with a column with numbers (primary key) and I need to create another column with the same values,
I want to change a table that has only numeric values (PK) to another
value, so I disable the constraints of linked tables
then I create another column that I called the "d" column and copy the values
from column A to column D
For example.
TABLE XYZ
COLUMN A: COLUMN D: (NEW)
00001 00001
00002-00002
00003-00003
00004 00004
Can I change the values in column A and D of the column will be kept
TABLE XYZ
COLUMN A: COLUMN D:
00001 99901
99902 00002
99903 00003
99904-00004
As the tables that must "point" to the column, I change the values with the new numbering
TABLE ZZZZ
COLUMN B: (the values of the column before the change)
00001
00002
00003
00004
...
I want it like this:
99901
99902
99903
99903
99904
...
In other words, I find the current value in column D of the XYZ table for the new value that is in column a.
I appreciate the help! :)Try this
Here you will find a record in test1 for a record for each line of teste2 in teste2 joined the condition t1.numer_documento2 = t2.numero_documento.This is called as subquery related Co. What you were doing was under queries that and not to join the top request.
UPDATE teste2 t2 SET NUMERO_DOCUMENTO = (SELECT T1.NUMERO_DOCUMENTO FROM teste1 t1 WHERE t1.numer_documento2 = t2.numero_documento and ROWNUM = 1 ) -- "Check/Select your data before you commit "
SS
-
update of column based on the sum of the data from another table
I have two tables:
Table1 (col1, col2, col3, col4, val1, status) Table2 (col1, col2, col3, col4, val2)
For Table1 and Table2, column (col1, col2, col3, col4) are the primary key of composit.
Table2 could have duplicated lines, that's why I want to group by (col1, col2, col3, col4) and sum (val2)
After that, I want to update Table1.val1 with the value of sum (Table1.val2) where Table1.col1 = Table2.col1 and Table1.col2 = Table2.col2 and Table1.col3 = Table2.col3 and Table1.col4 = Table2.col4 and status = 'V '.
I did something like this:
UPDATE Table1 SET val1 = (
WHERE Table1.col1 = t_sommevbrute.col1 and Table1.col2 = t_sommevbrute.col2 and Table1.col3 = t_sommevbrute.col3 and Table1.col4 = t_sommevbrute.col4)
Could someone help me please? Thank you
merge into table1 t1
using (select col1, col2, col3, col4, sum (val2) val2
from table2
Group
by col1, col2, col3, col4) t2
on (t1.col1 = t2.col1 t1.col2 = t2.col2 and t1.col3 = t2.col3 and t1.col4 = t2.col4 and)
When matched then
update set t1.val1 = t2.val2;
-
How to insert point decimal all by selecting data from a table
Hi all
My select requirement says, if the value received with no decimal place then insert decimals before last 2 bytes. I need to recover the data with this condition.
May help people how I can achieve this?
Thanks in advance,
Yvan997936 wrote:
This will not work if the values are of 5 bytes.It should work for any number of digits...
select 1234567/100 from dual;
SELECT DECODE (INSTR (1234567, '.'), 0, 1234567 / 100, 1234567) FROM DUAL;
Output:
12345,67
See you soon,.
Manik.Published by: Marty on April 4, 2013 08:53
-
on average + get data from another table
Hello..
I have two tables:
user_table: contains (user_id, username)
rating_table: contains (rating_id, side, user_id)
I am trying to create a view of the note for users...
the notice must contain:
the id, user_name, the average of the coast
I created the following script:
Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group;
but I got the following error message:
ORA-00979: not a GROUP BY expression
any help is appreciated...
Kind regards...10 x 2 wrote:
Hello..I have two tables:
user_table: contains (user_id, username)
rating_table: contains (rating_id, side, user_id)I am trying to create a view of the note for users...
the notice must contain:
the id, user_name, the average of the coastI created the following script:
Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group;but I got the following error message:
ORA-00979: not a GROUP BY expressionany help is appreciated...
Kind regards...Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group, b.username; -
Inserting data from one table to another table
Hello
I have the following SQL where I am updating a table by adding new data from another table, but without success.
INSERT INTO
() TOP_PROSPECTS
COMMON_ID
DATE_ADDED
REVIEW_RANK
EVAL_DATE
PM_ASSIGN
WHY_NOTES)
SELECT
t.COMMON_ID
t.DATE_ADDED
t.REVIEW_RANK
t.EVAL_DATE
t.PM_ASSIGN
t.WHY_NOTES
Of
TEMP_IVAN_MARY t
WHERE
COMMON_ID <>t.COMMON_ID
Any suggestions?
Thank you.
Published by: user13822709 on August 14, 2012 09:14
Published by: user13822709 on August 14, 2012 09:15Is that what you're trying to do with the insert. I think there may be a sign {noformat}<{noformat}{noformat}>{noformat} missing in the where clause. This site eat those, so you need to use the equivalent! = post here.
If I'm wrong about the missing trader, then it looks like you want to insert rows in temp_ivan_mary that are not already in top_prospects. If Yes, then you need something like:
insert into top_prospects (common_id, date_added, review_rank, eval_date, pm_assign, why_notes) select t.common_id, t.date_added, t.review_rank, t.eval_date, t.pm_assign, t.why_notes from temp_ivan_mary t where t.common_id not in (select common_id from top_prospects where common_id is not null)
Function index and data available volumnes etc. then a mergr can be more effective. Something like:
merge into top_prospects p using (select common_id, date_added, review_rank, eval_date, pm_assign, why_notes from temp_ivan_mary) t on (p.common_id = t.common_id) when not matched then insert (common_id, date_added, review_rank, eval_date, pm_assign, why_notes) values (t.common_id, t.date_added, t.review_rank, t.eval_date, t.pm_assign, t.why_notes) from temp_ivan_mary t
John
{noformat}{noformat}> -
Select table data in another table
Hello
I want to select data from A table, which is not in table B.
Currently I am doing:
Select
smofnut,
nameA,
dobA
a.
If smofnut not in
(select A snoB, B).
where smofnut = snoB
and nameA = Name)
But above all it is very slow.
I can do something like:
Select
smofnut,
nameA,
dobA
of A, B
where
EXCLUDE (smofnut = snoB and nameA = Name)
Please note that I need the place where the condition on the two columns.
any help will be appreciated.
-HarveyWhat are approximate data to A and B?
What is 'very slow '?
What version of Oracle?
What is the query plan?Without knowing anything about your system, my first thought would be to see if a NOT EXISTS happened to be faster for your data
SELECT snoA, nameA, dobA FROM a WHERE NOT EXISTS ( SELECT 1 FROM b WHERE a.snoA = b.snoB AND a.nameA = b.nameB )
Of course, I don't know why you want to join A & B in your NOT IN subquery. It would seem that you would need just a subquery correlated, i.e.
SELECT snoA, nameA, dobA FROM a WHERE snoA NOT IN ( SELECT snoB FROM b WHERE a.snoA = b.snoB AND a.nameA = b.nameB )
This should be more efficient than the original request. The NOT EXISTS version may or may not be more effective than NOT IN according to data volumes.
Justin
-
Create the form for selecting data in multiple tables
Hello
I'm getting APEX for the first time and I just read 2 days dev Application Express guide
I tried to play and I can't create a report with the form that select data from several tables
What I want to achieve is a report we'll say 'USERS' makes MANAGER_ID ID, NAME, with a form that allows me to create, delete, change users
The problem is that, once the report with the form created, if I click on create (to create a user) it will ask me for id, name, and manager_id
I need a water drop down which allows me to select managers in the table manager instead of manually insert Director id
How do I do that?
Thank you!
HI Chris,
LOV will use this magic.
Search:
Kind regards
BEnjamin
-
Migration of data from a table to another table
have a table1 that includes the existing data in the format.
~@!%~X1~@!%~Y1 in three different coulmns
creates a new empty table and the need to migrate the data above, which is present in 3 different columns in a column in the new table, as shown in the example below.
table 1 existing data (| separator of columns for formatting)
------------------------------------------------------------------------------------------------------------------------------------
ID name1 | Name2. Name3
123 ~@!%~X1~@!%~Y1 | ~@!%~X2~@!%~Y2 | ~@!%~X3~@!%~Y3
234 ~@!%~X4~@!%~Y4 | ~@!%~X5~@!%~Y5 | ~@!%~X6~@!%~Y6
456 ~@!%~X7~@!%~Y7 | ~@!%~X8~@!%~Y8 | ~@!%~X9~@!%~Y9
Table 2, which will initially be empty and after migration, it should look as follows.
ID name1
----------------------------------------------------------------------------------------------------------------------------
123 ~@!%~X1~@!%~Y1 & & ~@!%~X2~@!%~Y2 & & ~@!%~X2~@!%~Y2
234 ~@!%~X4~@!%~Y4 & & ~@!%~X5~@!%~Y5 & & ~@!%~X6~@!%~Y6
456 ~@!%~X7~@!%~Y7 & & ~@!%~X7~@!%~Y7 & & ~@!%~X7~@!%~Y7
as shown in the example above
Name1 column has ~@!%~X1~@!%~Y1
Column name2 has ~@!%~X2~@!%~Y2
Name3 column has ~@!%~X3~@!%~Y3
Once the data is migrating from table 1 for id - 123 looks like below, before joining data from 3 tables, I need apopend & & for each for the token I read of the tabl1 of name1 to end ii should be added "& &" also when I read the name2 I add "& &" at the end of the string before the concatination.
Here's the sample that deals with data for id - 123 with & & (only & & other symbols are part of the data)
~@!%~X1~@!%~Y1 & & ~@!%~X2~@!%~Y2 & & ~@!%~X2~@!%~Y2
need help in writing a note of migate
Published by: [email protected] on April 2, 2010 15:42Hello
You are looking for something like this
CREATE TABLE table_new AS (SELECT id, name1 || '&&' || name2 || '&&' || name3 name1 FROM table1);
or if you have the table ready
INSERT INTO table_new (SELECT id, name1 || '&&' || name2 || '&&' || name3 name1 FROM table1);
Thank you
Alen
-
How to select data from a remote database table?
Hi friends,
I think I've seen before a sqlplus program that can select data from a remote database table?
Witnessed: IP, SID, PORT
The following is correct?
(I am connected to a local database)
SELECT COUNT (*) IN THE EMP@IP:SID/PORT;
Thank you very much
Ms. KSalvation;
I think, that you can create dblink wihtout any problem yet, it's a PROD. After your selection, you can drop dblink
Respect of
HELIOS -
How to export select data from table in the file?
Hello..
Here's my query to select data in 2 tables and I join help call_id column: -.
Select n.nbr_calling, n.nbr_called, c.tec, n.conversation_duration
of albn_ngnsm_280110 n, albc_ngnsm_280110 c
where c.call_id = n.call_id
and c.route_to_arbor = 1;
The problem is what is the query to export all the output in text files?
Thank you
BalleurHello
set echo off set heading off set pagesize 0 set linesize 150 spool D:\file.csv SELECT Query spool off
Thank you
Ankur -
extract data from a table to a text file
I need to extract data from a table to a text file, I twist my output is the following...
bash-3. $00 vi tap3roamercosts_20110915144318.txt
lines of 'tap3roamercosts_20110915144318.txt' 393948, 23464348 characters
^ LAFGTD | N | 2011090203000001 | 13242514000064 | 1. 0 | 20. 41220 | 02-SEVEN.-11. 01-SEPT.-11. 0 | 13244
755. 64. 70. 0093794428588 | 0093796234547 | 0 | S2 | E | 412200306902634 | 8. 1. 61500 | 16081 |
| HW | Call to the Roamer. 0 | I have | Roaming billing Inroamer Plan | 1_0_1 | LKA | N_I_Independent
the time of day. Rate of Roamer SMST systems | AFGTD20110902030000010001013242514000064 |
|||||||||||||||||||||
AFGTD | N | 2011090203000001 | 13242612000044 | 1. 0 | 20. 41220 | 02-SEVEN.-11. 01-SEPT.-11. 0 | 13244
853. 44. 70. 234. 0093793252818 | 0 | S2 | E | 412200303198150 | 8. 1. 61000 | 12403 | HW | -Ro
bitter call | 0 | I have | Roaming billing Inroamer Plan | 1_0_1 | N_I_Independent time of Da
There | Rate of Roamer SMST systems | AFGTD20110902030000010001013242612000044 |
||||||||
AFGTD | N | 2011090203000001 | 13242612000047 | 1. 0 | 20. 41220 | 02-SEVEN.-11. 01-SEPT.-11. 0 | 13244
853. 47. 70. 234. 0093793252818 | 0 | S2 | E | 412200303198150 | 8. 1. 61000 | 12403 | HW | -Ro
bitter call | 0 | I have | Roaming billing Inroamer Plan | 1_0_1 | N_I_Independent time of Da
There | Rate of Roamer SMST systems | AFGTD20110902030000010001013242612000047 |
||||||||
.
.
.
.
.
Please help me how to format my output each record in simple lines in oracle sqlplus. Here are the settings I used...
TERMOUT OFF SET;
SET ECHO OFF;
SET LINESIZE 100000;
THE VALUE OF NEWPAGE 0;
SET SPACE 0;
SET PAGESIZE 50000;
SET FEEDBACK OFF;
SET THE OFF POSITION;
SET TRIMSPOOL
SET THE TABAnd what was wrong with the answers that you have on your previous thread?
How to extract data in a text file
Please do not ask the same question again. If there is a problem with the answers provided, then continue on the same thread that tell people what is the problem.
Saying that, this is another possibility for you...
As user sys:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles' / GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser /
As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2 ,p_dir IN VARCHAR2 ,p_header_file IN VARCHAR2 ,p_data_file IN VARCHAR2 := NULL) IS v_finaltxt VARCHAR2(4000); v_v_val VARCHAR2(4000); v_n_val NUMBER; v_d_val DATE; v_ret NUMBER; c NUMBER; d NUMBER; col_cnt INTEGER; f BOOLEAN; rec_tab DBMS_SQL.DESC_TAB; col_num NUMBER; v_fh UTL_FILE.FILE_TYPE; v_samefile BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file); BEGIN c := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE); d := DBMS_SQL.EXECUTE(c); DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab); FOR j in 1..col_cnt LOOP CASE rec_tab(j).col_type WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val); WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val); ELSE DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); END CASE; END LOOP; -- This part outputs the HEADER v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767); FOR j in 1..col_cnt LOOP v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),','); END LOOP; -- DBMS_OUTPUT.PUT_LINE(v_finaltxt); UTL_FILE.PUT_LINE(v_fh, v_finaltxt); IF NOT v_samefile THEN UTL_FILE.FCLOSE(v_fh); END IF; -- -- This part outputs the DATA IF NOT v_samefile THEN v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767); END IF; LOOP v_ret := DBMS_SQL.FETCH_ROWS(c); EXIT WHEN v_ret = 0; v_finaltxt := NULL; FOR j in 1..col_cnt LOOP CASE rec_tab(j).col_type WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val); v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',','); WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val); v_finaltxt := ltrim(v_finaltxt||','||v_n_val,','); WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val); v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),','); ELSE v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',','); END CASE; END LOOP; -- DBMS_OUTPUT.PUT_LINE(v_finaltxt); UTL_FILE.PUT_LINE(v_fh, v_finaltxt); END LOOP; UTL_FILE.FCLOSE(v_fh); DBMS_SQL.CLOSE_CURSOR(c); END;
This allows the header line and the data to write into files separate if necessary.
for example
SQL> exec run_query('select * from emp','TEST_DIR','output.txt'); PL/SQL procedure successfully completed.
Output.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno 7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20 7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30 7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30 7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20 7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30 7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30 7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10 7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20 7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10 7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30 7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20 7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30 7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20 7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.
Adapt to the exit of styles and different types of data are needed.
-
I followed the instructions of Firefox to import bookmarks/favorites to Internet Explorer. It does not work because the import data from another browser is not active in the import tab and backup in the history. The instructions read to use this tab, but does not work because it cannot be selected.
Make sure that you are not Firefox running in permanent private browsing mode.
To view the history settings and cookies, choose: Tools > Options > privacy, choose the setting Firefox will: use the custom settings for the story of
- Uncheck the box: [] "always use the navigation mode private.
-
Populating one table from another table
Hi Forum...
I'm trying to populate a table from another table using CFQUERY... I have no problem with the selection of data from the original table, but need help to get the data into the new table. I use MX 6.1 and access as the database server.
The two arrays have domain names identical to the same place, and I don't want to have to code all the column names in the selection and insert command. for example
< cfquery name = "GetData" datasource = 'somename' >
SELECT * FROM AssetTable1 WHERE BarCode = "123456".
< / cfquery >
< cfloop query = "GetData" >
< cfquery name = "InsData" datasource = 'somename' >
INSERT INTO AssetTable2 (xxxx...)
VALUES ("#xxxx... #'")
< / cfquery >
< / cfloop >
I hope this makes sense
Thanks in advance
DaveIf your tables are identical structures and their columns are of the same type and position, and both tables are in the same database, then put everything in a single query.
INSERT INTO AssetTable2
SELECT *.
OF AssetTable1
WHERE bar code = "123456".
If the columns were in different positions, then you should be listed explicitly in the INSERT and SELECT the parts, but you get the idea.
INSERT INTO table1 (col1, col2)
SELECT col1, col2
FROM table2
WHERE all that...Phil
Maybe you are looking for
-
On every page of my site dominicrouse.com , I have a menu designed using Sothink DHTML Menu 9.10 javascript Using IE and other browsers the subtleties that I integrated display perfectly but in FF, they are lost. I'm talking specifically a slow fade
-
I was handed an encoder that hit around, and the memory is to integrate into a new benchmark of multi-turn. The problem is that it is only a unique feature of the tower. Has anyone written a reliable code snaps the tour on a single turn encoder accou
-
How can I change my administrative password
I'm having trouble finding information on how to do it. Thank you.
-
Video Mode problems XP ' Safe Mode'
After you install a new motherboard, I have a problem with Safe Mode. The PC has 2 hard drives, one with XP Home, & the other with XP Pro. One can be selected at boot time. I have no problem with XP Home, so I know that the material is not at fault.
-
Lap top repsonsive one very, very, very slowly.
Now its going as of 10/27/11, my other laptop started running very, very slow. One of the children's pc off by on/off switch and not closed it down well this could be the cause. Here's what turn on pc starts (slower than usual) ok, loads up the scree