How to check the existence of a value in a table before copying the data?
Experts,I have a requirement in which I need to copy data (4 columns) table A to table B (4 columns)
Table A (entry)
PART_ID PART_NAME PART_OPT_CD ENGG_OPT_CD
1 "AAA" 10 100
2 'BBB' 20 200
3 'CCC' 30 300
4 'DDD' 40 400
5 'EEE' 50 500
I have a table named OPTIONS with a single column. This is a table of reference of business which has the master list of option codes.
OPT_CD
10
20
30
50
60
100
200
400
500
I need to copy Table A to Table B, but in doing so, I need to check the values of columns 3 and 4 in the OPTIONS array.
If there is copy the folder B. Otherwise error in the log in a file/table and continue with the next copy
TABLE B (exit)
PART_ID PART_NAME PART_OPT_CD ENGG_OPT_CD
1 "AAA" 10 100
2 'BBB' 20 200
5 'EEE' 50 500
WARNING file or a table should have the details below.
300 ENGG_OPT_CD does not exist in the table OPTIONS, so part_id 3 have not migrated
40 PART_OPT_CD does not exist in the table OPTIONS, then part_id 4 have not migrated
Company don't bother about the format of error, we need this information to correct the OPT_CD in the OPTIONS table.
Can anyone suggest a better way to do this. Thank you for your help in advance
Hello
Its very similar to your previous post.
Re: PL/SQL help
The only difference being that you have to outer join to your superimposed master table, since your search in two columns values occur only in a single column on your Master table.
Something like that;
create table a (part_id number, part_name varchar2(10),part_opt_cd number,engg_opt_cd number);
insert into a
(select 1 Part_ID, 'AAA' Part_Name, 10 Part_Opt_CD, 100 ENGG_Opt_CD from dual union all
select 2, 'BBB', 20, 200 from dual union all
select 3, 'CCC', 30, 300 from dual union all
select 4, 'DDD', 40, 400 from dual union all
select 5, 'EEE', 50, 500 from dual union all
select 6, 'FFF', 60, 500 from dual
)
/
create table b (part_id number, part_name varchar2(10),part_opt_cd number,engg_opt_cd number);
insert into b
(select 1 Part_ID, 'AAA' Part_Name, 10 Part_Opt_CD, 100 ENGG_Opt_CD from dual union all
select 2, 'BBB', 20, 200 from dual union all
select 5, 'EEE', 50, 500 from dual
)
/
Create table master (OPT_CD number);
insert into master (
select 10 opt_cd from dual union all
select 20 from dual union all
select 30 from dual union all
select 50 from dual union all
select 60 from dual union all
select 100 from dual union all
select 200 from dual union all
select 400 from dual union all
select 500 from dual
)
/
create table log_msg
(msg varchar2(100)
,t timestamp default current_timestamp)
/
SQL> insert all
2 when Master1_ID is not null and
3 Master2_ID is not null then
4 into b (Part_ID, Part_Name, Part_Opt_CD, ENGG_Opt_CD)
5 values (Part_ID, Part_Name, Part_Opt_CD, ENGG_Opt_CD)
6 when Master1_ID is null or
7 Master2_ID is null then
8 into log_msg (msg) values (Part_Opt_CD || ' ' || ENGG_Opt_CD || ' does not exist on the Master table')
9 select m1.Opt_CD as Master1_ID
10 ,m2.Opt_CD as master2_ID
11 ,a.Part_ID as Part_ID
12 ,a.Part_Name as Part_Name
13 ,a.Part_Opt_CD as Part_Opt_CD
14 ,a.ENGG_Opt_CD as ENGG_Opt_CD
15 from (
16 select a.Part_ID, a.Part_Name, a.Part_Opt_CD, a.ENGG_Opt_CD
17 from a
18 left outer join b on a.Part_ID = b.Part_ID
19 where b.Part_ID is null
20 ) a
21 left outer join master m1 on a.Part_Opt_CD = m1.Opt_CD
22 left outer join master m2 on a.ENGG_Opt_CD = m2.Opt_CD
23 /
3 rows created.
SQL> select * from log_msg;
MSG T
------------------------------------------- -------------------------
40 400 does not exist on the Master table 05-OCT-11 09.44.17.621000
30 300 does not exist on the Master table 05-OCT-11 09.44.17.621000
SQL> select * from b;
PART_ID PART_NAME PART_OPT_CD ENGG_OPT_CD
---------- ---------- ----------- -----------
1 AAA 10 100
2 BBB 20 200
5 EEE 50 500
6 FFF 60 500
Note, I have included an additional line in table A in order to prove that the INSERTION will occur in table B. Errors, as you can see have been inserted in the table LOG_MSG.
Published by: bluefrog October 5, 2011 09:48
Tags: Database
Similar Questions
-
Anyone know how to check the date of warranty until when?
Anyone know how to check the date of warranty until when?
-
How to check the data file is set to unlimilted autoextend
S/N,
Oracle version: 10.2.0.4
OS: linux
could someone tell me how can I check the data file are set to unlimited autoextend?
Thank you
Bahadur.Salvation;
Pelase see:
How to check the CanGrow data files the value of Maxsize unlimited [ID 468096.1]Respect of
HELIOS -
How to check the date valid?
Hello
I have a stored procedure that has a parameter of type varchar data entry. This parameter is actually a date, now I want to check whether this parameter is a valid date. My version of oracle's 10g. I tried ISDATE() built-in but my version of oracle does not support.
Can ppl help please how?
Concerning
FrébaultHello Marie Lise.
Here is the code example that you can do to check the Date. Create a function for this, hope this helpsCREATE OR REPLACE FUNCTION F_DATE(v_date IN VARCHAR2) RETURN NUMBER IS v_date1 DATE; BEGIN select to_date(v_date) into v_date1 from dual; RETURN 1; Exception WHEN Others THEN RETURN 0; END; ---------------------------------------------- SELECT F_DATE('01-JAN-09') FROM DUAL; -- Returns 1 SELECT F_DATE('111111') FROM DUAL; -- Returns 0
Please indicate if it helps you or correct
Kind regards
Danish -
How to check the date of last used database?
We have a few databases are not used for a long time. How we can check the last date of use?
I tried scn_to_timestamp (max (ora_rowscn)), does not, because scn_to_timestamp SNA must be not more than 5 days.
I tried DBA_TAB_modifications, but we have not defined monitoring.
Thank you very much
SkyRiverHow we can check the last date of use?
If apps/user to connect through earpiece, you can look in the newspaper of the listener.
-
How to check the data that are not digital?
I have a varchar field and I would check for all of the lines where it does not contain a numeric value. How can I achieve this?
Thanks in advance.One option is to write a small function
CREATE OR REPLACE FUNCTION is_numeric( p_str IN VARCHAR2 ) RETURN NUMBER IS l_num NUMBER; BEGIN l_num := to_number( p_str ); RETURN 1; EXCEPTION WHEN others THEN RETURN 0; END;
only then can you call
SELECT * FROM some_table WHERE is_numeric( some_string_column ) = 0
Of course, you can adapt the function to return the numeric value rather than a 1 or a 0 more.
Justin
Published by: Justin Cave on June 21, 2011 18:15
Depending on the version of Oracle (which you don't mention), you can also write a regular expression to search for things other than numbers. This can become a little difficult if you have to manage commas and dots as decimal separators and grouping because different regions use the symbols differently and have different rules about what are valid models.
-
How to check the date of renewal of iCloud (paid)?
I'm completely lost. I'm sure I checked everywhere (settings iCloud, info account Apple ID, menu 'manage subscriptions', etc) but I can not find my subscription renewal date to 50 GB of extra storage. Of course, I could get my mail Inbox, but I well enough to remove all the ads/receipt of Apple without reading them, so it's not an option for me.
Any ideas?
Thank you
Adam.
I believe that it is in your purchase history: see your purchase history in iTunes on Mac or PC - Apple Support store
-
How to check the data on the device network connectivity
Hello
Please suggest me how can I test if the unit is to have internet conectivity or not.
We tried some of the samples but no use:
Example 1:
If (! blackberry.system.hasDataCoverage ()) {}
Alert ("you are not in the coverage, we will try to send later");
} else {}
}in the config.xml file
Example 2:
We tried with html5 script but it always returns true.
If (window.navigator.onLine == false) {}
}For BlackBerry 10, you can use the extension deviceinfo to get detailed information about the State of the network:
https://github.com/BlackBerry/WebWorks-community-APIs/tree/master/BB10-Cordova/deviceInfoFor BBOS, I can't find an extension to give detailed information, but hasDataCoverage should work.
https://developer.BlackBerry.com/BBOS/HTML5/APIs/BlackBerry.System.html#.hasDataCoverageNote that hasDataCoverage is not a function, it is a Boolean property. Your current use:
blackberry.system.hasDataCoverage)Must be:
blackberry.system.hasDataCoverageCan you please try this?
-
How to check the data stored in the database sqlite in black berries.
Am a newcomer to the black berries and LL hel me how to learn quickly. Wite a few good ways to study black berry quickly.
Hi dembele,.
Welcome to the world of BlackBerry,See this link, that every thing is there.
-
How to check the manufacturing date of the Z2?
Hello, so the title sums up pretty much everything this. On the previous xperia phones, you can check under the battery, with xperia Z, that it was written on the back at the bottom but on Z2? How to check the date of manufacture?
Hello and welcome to the community! Since you are new, please make sure that you have checked our Forum.
This label can be found in the MicroSD slot, click on the following link:
http://Userguide.sonymobile.com/referrer.php?region=en&product=Xperia-Z2#IMEI-number.html -
How to check the page dirty with default values existing in viewObject?
Hi all
I use JDeveloper 11.1.1.4.
I have two pages in my application. I am browsing for page2 page1.
Before opening page 2 I created new line page 2 notice of object using method 'Create Insert()' with some default values by using the ViewRowImpl class.
My problem is that I have a button to return to Page 2. If I click the back button, then check the Application module is dirty or not.
But it always shows AM is dirty due to I'm setting some default values in ViewRowImpl. If I avoid the default values in ViewRowImpl then AM dirty check works fine.
My Question is how to check the AM (or) dirty Page with default values in the object view?
My bean Codes:
Links DCBindingContainer = (DCBindingContainer) BindingContext.getCurrent () .getCurrentBindingsEntry ();
DataControl dc = bindings.findDataControl("AppModuleDataControl");
ApplicationModuleImpl am = ((ApplicationModuleImpl) dc.getDataProvider ());
If (am.getDBTransaction (.isDirty (()))
{
return "Page is dirty."
}
My Jspx Codes:
< af:commandLink id = "cl6" text = '2 '.
shortDesc = "Add Row in Page2"
actionListener = "#{bindings." Action CreateInsert.execute}' = 'Edit' >Thank you
David...
see this
http://www.techartifact.com/blogs/2013/11/how-to-check-ifdirty-is-modified-for-view-object.html
http://www.jobinesh.com/2011/05/checking-for-dirty-data.html
-
How to check the value of the space of the tablespaces and tables when errors occur?
Hi Experts,
For example, lets say we get ORA-01653: unable to extend table of error. How to check the size of the table and a tablespace? And how understanding is full?
Thanks for your help
Hello
Select df.tablespace_name "Tablespace"
totalusedspace 'Used MB',
(df.totalspace - tu.totalusedspace) "MB free.
DF. TotalSpace 'Total MB. "
round (100 * ((df.totalspace-tu.totalusedspace) / df.totalspace))
"PCT free."
Of
(select nom_tablespace,
Round (Sum (bytes) / 1048576) TotalSpace
from dba_data_files
Group by tablespace_name) df,.
(select round (sum (bytes) /(1024*1024)) totalusedspace, nom_tablespace)
from dba_segments
you group by tablespace_name)
where df.tablespace_name = tu.tablespace_name
and df.tablespace_name = "
"; For example, lets say we get ORA-01653: unable to extend table of error. How to check the size of the table and a tablespace? And how understanding is full?
Is to say clearly to the question (you can let us know what you have understood so we can fix)
[oracle@machine1 ~] $01653 oerr ora
01653, 00000, "impossible to extend %s.%s table by %s in %s tablespace»
* Cause: Failed to allocate a certain measure the required number of blocks for
a segment of the table in the specified tablespace.
* Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more
storage of files indicate.
-Thank you
Pavan Kumar N
-
How to check the values in multi-record block. ?
Hello
I'm new to forms. I have the field titled "Comments" in the block of multi-record. I have a button called "reject". Reject button is in the control block. If I press the button reject, field comments must be entered in one of the record. Otherwise, he should tell message. How to check the multi-record block. ?
Pl.Help.
Thanks in advance.
ManoMano,
Add NEXT_RECORD just before the END of the LOOP.
GO_BLOCK('
'); FIRST_RECORD; LOOP IF NVL(: . , ' ' ) = ' ' THEN MESSAGE(' '); RAISE FORMS_TRIGGER_FAILURE; END IF; EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE'; NEXT_RECORD; END LOOP; Kind regards
Manu.
If my response or response from another person was helpful, please mark accordingly
-
How to check all existence directory in TestStand?
How to check all existence directory in TestStand?
Is there a function TestStand? Or another option without writing my own code in the external program (for example, LabVIEW or C)?
Thanks in advance
Try the Engine.FindPath method. BTW several times when you do file IO, depending on what you're doing exactly, you need to write a code module.
CC
-
How to check the JSON object properties available
Hi I have a JSON of WebService object.
How to check the available JSON object?
ex JSON:
{
name: "someName".
DESC: 'someDesc '.
}
How to check the available name?
Because sometimes not available from the server name properties
void MyClass::httpFinished(QNetworkReply* reply) { QString data = (QString) reply->readAll(); bb::data::JsonDataAccess jda; QVariant variant = jda.loadFromBuffer(data); QVariantMap variantMap = variant.value
(); QString name = variantMap.value("name").toString(); } I want to hide component Label on my .qml if name not available from webservice.
Thank you
Kaz32 wrote:
Hi I have a JSON of WebService object.
How to check the available JSON object?
ex JSON:
{
name: "someName".
DESC: 'someDesc '.
}
How to check the available name?
Thank you
If you want to check if the name is available, you must use
bool nameExists = variantMap.contains ("name")
Maybe you are looking for
-
Hello community, Since a month or two I feel the prohibitive sign with my macbook pro 13-inch mid 2012. Running on El Capitan 10.11.5 It took about a month to start to repair it because I needed it for work so I kept it running until it got so slow t
-
Hello! I bought and used my N600 with Comcast year last year in Chicago, with no problems. I moved to Dallas yesterday and tried to get my internet set in place. Hooked upward, called Time Warner (TWC) to give them the MAC address, but we couldn't wo
-
Default values for input unconnected subvi in LabView RT
As LVRT does not include the front screw executing, how the default values should be prescribed to control entries that were left unconnected? Thank you XL600
-
List of XP Windows Add/Remove Programs fill
I'm running Windows XP and IE 7. Does my Add/Remove Programs list. I tried http://support.microsoft.com/kb/266668 and stuck on the addition of a few with the error message saying "Imgutil.dll was loaded, but the DllRegisterServer entry point was not
-
I continue to receive notices of Windows security KB2478663 and KB2518870 update
These 2 files were installed several times, but I keep getting updates to install again and again and again!