SQL & PL/SQL :: Linking Two Tables With Extra Field
Oct 1, 2011
Once I add an extra column to link the two tables the number of rows is reduced by one, however when I try to get this extra record I find none matching the same criteria that led to reducing the records.
SQL> SELECT count(*)
2 FROM N_CONTRACT NC, N_WITHDRAWAL_REQUEST NWR
3 WHERE NC.fk_temP_withdrawal_req_serial = NWR.SERIAL_NUMBER;
COUNT(*)
----------
2243
[code]...
I remember a method in which I used a property in the property pallete to specify the query in which i wanted the list linked with, it gave me the option to input a static list or as mentioned a dynamic list which was dependent on a query entry, but I cant for the life of me remember where this property was.
I have two tables as per attachement - TABLE_A has Vehicle details while TABLE_B has Address details:
I am trying to build a query in order to link the Vehicle Details with their Address Details.
I would require an SQL that links records in TABLE_A with records in TABLE_B when group_number are the same; however links with group_number '999' (for the same customer_number) if there are no exact matches.
SELECT A.*,B.* FROM TABKE_A A, TABLE_B B WHERE ((A.CUSTOMER_NUMBER = B.CUSTOMER_NUMBER AND A.GROUP_NUMBER = B.GROUP_NUMBER) OR (A.CUSTOMER_NUMBER = B.CUSTOMER_NUMBER AND A.GROUP_NUMBER = '999'))
The only problem with such query is that record in TABLE_A with group_number '456' will return 2 times. One with address having group_number '456' and one with group_number '999'.
I need to copy records from a working table to a history table. I have the following sql statement
insert into test.history (equip_ID, state, manufacturer, install_year, capacity, group_ID, Test_status) select (equip_ID, state, manufacturer, install_year, capacity, group_ID, Test_status from test.info_AP
Table test.history has one more field in it called test_year. I need to fill this field when I do the insert. Can't use an after update trigger as the field is currently set to not allow nulls.
I have inherited a query that union alls 2 select statements, I added a further field to one of the select statements ( a date field). However I need to add another dummy field to the 2nd select statement so the union query marries up I have tried to do this by simply adding a
select 'date_on' to add a field called date on populated by 'date_on' (the name of the column in the first query)
however when I run the union query i get the error Ora-01790 expression must have same datatype as corresponding expression.
I am using two databases one prd1 and another ftn. I want to do some data verification between these two databases. So I created the following db link in prd1 and also in ftn.
CREATE PUBLIC database LINK ftn CONNECT TO ftn_link IDENTIFIED BY password USING ftn
CREATE PUBLIC database LINK prd1 CONNECT TO prd1_link IDENTIFIED BY password USING prd1
I gave the following sql command from prd1 but it showed error message.
ORA-12154: TNS:could not resolve service name
SELECT A.CUST_ID_MSS_OWNER, B.CUST_ID_MSS_OWNER FROM MSS_V_CAR_REC A, mss_v_car_rec@ftn b WHERE a.lic_no_org = b.lic_no_org;
I have already created the sql net configuration also.
I have two master tables , one is supplier master and the other customer, the requirement is , i will pass a code as IN parameter and the result it should bring the appropriate name of that code , for example if i pass a code which exists in supplier master , it should get me the supplier name for that code , if i pass code which exists in customer ,it should bring customer name.
CREATE TABLE OM_CUST (CUST_CODE VARCHAR2(30),CUST_NAME VARCHAR2(240)); INSERT INTO OM_CUST VALUES ('1001','CUST1'); INSERT INTO OM_CUST VALUES ('1002','CUST2'); CREATE TABLE OM_SUPP (SUPP_CODE VARCHAR2(30),SUPP_NAME VARCHAR2(240)); INSERT INTO OM_SUPP VALUES ('2001','SUPP1'); INSERT INTO OM_SUPP VALUES ('2002','SUPP2');
I have a table of Costs. We have Jobs that run and there will be a cost associated with a particular machine.So JobNo 1 may run on Machine A and have a cost of 50 dollars. Although its now shown below JobNO 1 could run on MachineB and so on.
We have operators (PERSONCODE) run the jobs on the machines. So Job 1 may be run by PERSONCODE 8 (e.g. Tony) and it may run on MachineA or MachineB.Multipe people may run a particular job. The PERSONCODE will be unique to the Job and it is actually unique to the list. A person never works on more than one job.
I am attempting to update a single field in one table based on a select from two tables. However, I am receiving the following error.
ORA-00933: SQL command not properly ended
The sql I am using is as follows:
update PS_TRNS_CRSE_DTL set RQMNT_DESIGNTN = 'TRN' FROM PS_TRNS_CRSE_DTL A, PS_STDNT_CAR_TERM B where (SELECT A.EMPLID, A.ACAD_CAREER, A.INSTITUTION, A.MODEL_NBR, A.ARTICULATION_TERM, A.TRNSFR_EQVLNCY_GRP, A.TRNSFR_EQVLNCY_SEQ, A.TRNSFR_STAT, A.GRADING_BASIS, A.RQMNT_DESIGNTN, B.STUDY_AGREEMENT FROM PS_TRNS_CRSE_DTL A, PS_STDNT_CAR_TERM B [code]......
I'm trying to leave out results of a query that match certain conditions, basically I'm looking at two tables that each have a status field. If the status of both is equal to zero then I want the result to be left out of the search results. I'm struggling with the logic though. In the where clause I've tried:
(ACCO.STATUS != '0' AND CCO.STATUS != '0')
this, however, omits everything where the status combination isn't 1 and 1. I've also tried: ( (ACCO.STATUS = '1' AND CCO.STATUS = '1') OR (ACCO.STATUS = '1' AND CCO.STATUS = '0') OR (ACCO.STATUS = '0' AND CCO.STATUS = '1') )
declare i INTEGER:=0; flag boolean:= FALSE; vcInsert:='INSERT INTO CRM_DELT_IMPORT ('; if length(i_vcColumn1) > 0 then flag:=TRUE;
[code]....
i am fetching data from excel all data is of general type, here i am passing value is VTDATE varchar2(100) but actual database column filed is DATE , How can i pass '13-06-13 05:54:33' to database table.
if i put this condition vcInsert:=vcInsert|| ','||''''||i_ldata(i).to_char(VTDATE,'DD-MM-RR HH12:MI:SS') i get the error to_char must be declare.
if i remove this line
i am getting this error ORA-01843: not a valid month
I have this SQL that returns the correct amount of rows which should be 2:
Select Distinct A.File_Name, A.File_Desc, A.file_location, A.location_date, A.downloaded_date, A.downloaded_id, A.file_size, A.days_to_request, B.File_Name, B.Act_Date, B.date_loaded from SDT_LOG A Inner Join ACTIVITY_LOG B On A.file_name = B.file_name and A.downloaded_date = B.date_loaded
I need to add another field in the Select query which is B.Act_Code. When I do, I get 2 extra rows. I do not know how to make these rows distinct.
The A table's structure is along with sample data for 1st record:
CODE Example of Name Type 1st record. ---- ------- -------------- FILE_NAME VARCHAR2(50) STLMK.txt FILE_DESC VARCHAR2(50) NON-RESIDENT FILE_LOCATION VARCHAR2(50) L:\NonResFiles YEAR NUMBER(4) 2008 LOCATION_DATE DATE 10/10/2007 DOWNLOADED_DATE DATE 09/04/2008 9:17:00 AM DOWNLOADED_ID VARCHAR2(50) Cindy FILE_SIZE CHAR(10) 16212 DAYS_TO_REQUEST NUMBER(3) 60
The B table's structure is along with sample data for 1st record:
CODE Example of Name Type 1st record ---- ------ ----------- FILE_NAME VARCHAR2(50) STLMK.txt ACT_CODE CHAR(2) D ACT_DATE DATE 10/10/2007 ACTIVITY_ID VARCHAR2(50) downloaded on DATE_LOADED DATE 09/04/2008 9:17:00 AM
The second record of activity would all be the same except Cindy would be "Jason", act_code would be an "S", activity_id would be "sent on" and then of course the dates would be changed to whenever the new information was saved within the system.
I am getting something like this (shortened of course):
CODEFile_name Downloaded_ID Act_Code
STLMK.txt Cindy D STLMK.txt Cindy S STLMK.txt Jason D STLMK.txt Jason S
There should only be one row for Cindy with a D act_code and one row for Jason with an S act_code. For some reason, Cindy and Jason each get a row with the different act_code. I'm retrieving 4 rows instead of two when I use B.Act_Code in the SQL statement.
Cindy should have the D Act_Code because she downloaded that file name and Jason should have the S because he sent that file to someone else. Every time a file's activity changes, it is entered into the system so we can keep track of where the files are.
Cindy should have the D Act_Code because she downloaded that file name and Jason should have the S because he sent that file to someone else. Every time a file's activity changes, it is entered into the system so we can keep track of where the files are.
Also, I get the 2 extra rows when I add activity_id field to the select.
I have this SQL that returns the correct amount of rows which should be 2:
Select Distinct A.File_Name, A.File_Desc, A.file_location, A.location_date, A.downloaded_date, A.downloaded_id, A.file_size, A.days_to_request, B.File_Name, B.Act_Date, B.date_loaded from SDT_LOG A Inner Join ACTIVITY_LOG B On A.file_name = B.file_name and A.downloaded_date = B.date_loaded
I need to add another field in the Select query which is B.Act_Code. When I do, I get 2 extra rows. I do not know how to make these rows distinct.
The A table's structure is along with sample data for 1st record: Example of Name Type 1st record. ---- ------- -------------- FILE_NAME VARCHAR2(50) STLMK.txt FILE_DESC VARCHAR2(50) NON-RESIDENT FILE_LOCATION VARCHAR2(50) L:NonResFiles YEAR NUMBER(4) 2008 LOCATION_DATE DATE 10/10/2007 DOWNLOADED_DATE DATE 09/04/2008 9:17:00 AM DOWNLOADED_ID VARCHAR2(50) Cindy FILE_SIZE CHAR(10) 16212 DAYS_TO_REQUEST NUMBER(3) 60
The B table's structure is along with sample data for 1st record: Example of Name Type 1st record ---- ------ ----------- FILE_NAME VARCHAR2(50) STLMK.txt ACT_CODE CHAR(2) D ACT_DATE DATE 10/10/2007 ACTIVITY_ID VARCHAR2(50) downloaded on DATE_LOADED DATE 09/04/2008 9:17:00 AM
The second record of activity would all be the same except Cindy would be "Jason", act_code would be an "S", activity_id would be "sent on" and then of course the dates would be changed to whenever the new information was saved within the system.
I am getting something like this (shortened of course):
File_name Downloaded_ID Act_Code
STLMK.txt Cindy D STLMK.txt Cindy S STLMK.txt Jason D STLMK.txt Jason S
There should only be one row for Cindy with a D act_code and one row for Jason with an S act_code. For some reason, Cindy and Jason each get a row with the different act_code. I'm retrieving 4 rows instead of two when I use B.Act_Code in the SQL statement.
Cindy should have the D Act_Code because she downloaded that file name and Jason should have the S because he sent that file to someone else. Every time a file's activity changes, it is entered into the system so we can keep track of where the files are. Cindy should have the D Act_Code because she downloaded that file name and Jason should have the S because he sent that file to someone else. Every time a file's activity changes, it is entered into the system so we can keep track of where the files are.
Also, I get the 2 extra rows when I add activity_id field to the select.I use Oracle 10.
view the below select statement..why it's adding extra zero's...
select to_timestamp('2001-05-22 12:00:18.600','YYYY-MM-DD HH:MI:SS.ff3AM') from dual output: 5/22/2001 12:00:18.600000000 PM ---why it's adding extra zeors's my output should be as " 5/22/2001 12:00:18.600 PM"
it gets these three characters at the start of the line l_hdr_evnt = 
So i saved header_evnt.txt as UTF-8, and used utl_file.fopen_nchar, utl_file.get_line_nchar, which got rid of first two characters, but still has ¿. How to get rid of that?
I am modifying a stored proc that i wrote a couple of years ago. The change is that i want certain inputs to accept strings of characters (comma delimited) so they can be parsed and processed in the proc. The problem is, when i pass very little data (about 50 characters) It fails saying the character sting buffer is to small.
I have setup the input as a type of a column that is a clob and i have also tried using just vahrchar2 (with no size set).
I am calling a function in front end, from front end i am passing space, now i want to trim space in parameter itself, it's psssible, assume the below is the function defination, i want to trim the p_region_name parameter like this trim(p_region_name), is this possible?
FUNCTION add_country_region_column ( p_s_country_code_iso_2 IN varchar2_table_type, p_type IN d_country.c1_type%TYPE, p_name IN d_country.c1_name%TYPE, p_desc IN d_country.c1_desc%TYPE,
INSERT INTO TEST_TBL VALUES( 1000, 2000, 3000, 4000 ) ;
Expected result
A1 1000 A2 2000 A3 3000 A4 4000
A1, A2, A3, A4 are hard coded fixed values.
I could have done this but not a good idea in case table TEST_TBL is not a single row table but an inline query on 1,00,00,000 records with summary functions. In my table I've a summary query instead of single row table.
SELECT 'A1', COL1 FROM TEST_TBL UNION ALL SELECT 'A2', COL2 FROM TEST_TBL UNION ALL SELECT 'A3', COL3 FROM TEST_TBL UNION ALL SELECT 'A4', COL4 FROM TEST_TBL
I have one issue while loading the value through sql*loader the last column data is SG1 and when its loaded , it is length of this columns is showing 4 char. Unable to understand, how to find this extra space. Though used TRIM but does not work.
I have a table where i need to update one field values based on another field of the same table , simply as it is.I have done this using one select all check box , on clicking that all check boxes of item_trans table will get selected , then i will un select some of check box and then using one button, i will update the value of the fields which are checked only.
I have put the sample code but when i am updating its taking long time and hanging.I am also attaching the form based on the test case provided.
insert into item_trans(TRANS_ITEM,TRANS_QTY,TRANS_ACT_QTY) VALUES ('TREE1',40,NULL); insert into item_trans(TRANS_ITEM,TRANS_QTY,TRANS_ACT_QTY) VALUES ('TREE2',20,NULL); insert into item_trans(TRANS_ITEM,TRANS_QTY,TRANS_ACT_QTY) VALUES ('TREE3',20,NULL);
--i want to set the value of trans_Act_qty as trans_qty
--i create one dummy or test block to keep the select all check box. for that table test script is
CREATE TABLE TEST ( C VARCHAR2(2000 BYTE), B NUMBER, A NUMBER );
insert into test (C,B,A) values ('A',1,1);
--code written in select all check box which is created on test.block.
BEGIN GO_BLOCK('item_trans'); FIRST_RECORD; LOOP :M_END_YN := :M_END_ALL; [code].......
--code written in M_END_YN ( actual check boxes where i will uncheck).
IF :M_END_YN = 'N' THEN :M_END_ALL := 'N'; END IF;
--code written on button to update those values which are checked.
BEGIN GO_BLOCK('item_trans'); FIRST_RECORD; LOOP IF :M_END_YN = 'Y' THEN [code]......
All the reports are skipping one extra page after printing of last page irrespective of number of pages in the report. if same report file is generated and given to printer using dos or linex dosen't skips extra page at end. It happens only if i print the report through ORARRP. The report file extension is '.rrpt'.
What i wnat is to update the Customer_inactive_date with the Incative_date field from Customer_type based on their Customer_type... So james and Jill would have their rows updated in this scneario ..How can i achive this in pl/Sql
I have teh code using merge function..I want something in traditional old fashion..
problem on oracle 11gR2 where i have to import data from a source database to an existing table without truncate or drop the target table in the target database.
we have found something called table_exist_action=append in impdp.