SQL & PL/SQL :: Pull Records With Specific Criteria
May 9, 2013
I want to start by saying I am brand new to SQL. I have an access database linked to my oracle and am trying to query a very specific set of data and I can't seem to narroe it down. I have 244,000 lines in the DB and I'm trying to find items on a specific trype of vendor agreement. I may have the same item on multiple agreements. ex 1-, 1a-, 2-,2a-,3-,3a-,4-,4a-,5-,5a-,6-,6a-,7-,7a-,8-,8a-.
I need to find a way to select just items that appear on a 4- or 4a- and no other agreement reference. The query I did so far pulls all of the 4- and 4a- agreements but will also pull items,like #233 in the example above, but not showing the 1a- agreement. I need it to overlook that item eventhough it does appear on the agreement I am looking for but also has an agreement I am not. the statement I am using right now is:
SELECT item, ven_item, ven_agrmt_ref, base_cost, vendor
FROM "all items by agreement"
WHERE ven_agrmt_ref >= '4'
ORDER BY item
SQL Plus version Oracle8 Enterprise Edition Release 8.0.5.0.0 - Production PL/SQL Release 8.0.5.1.0 Production Forms Version : 6i Reports Version: 6i O/S : Microsoft Windows Xp professional Version 2002 Service Pack 3
With regards to the above version description here is my query. I have a form which calls report it accepts various parameters like date between, appeal and so on . I want the report to be restricted to the date parameter as passed by the user.Here is my coding which runs report
Declare Pl_id ParamList; where_cond varchar2(2500); Begin ------------Appeal------------------ if upper(ltrim(rtrim(:appeal)))<> 'ALL' then where_cond:= where_cond ||'and tbl_donation.appeal_code='||ltrim(rtrim(:blk_ihelp.appeal_code)); else where_cond:= where_cond||' and tbl_donation.appeal_code is not null'; end if;
-------------Date Option---------------- if :date_option is not null then if :date_option = 'BETWEEN'then where_cond:=' and tbl_donation.donation_date between '''||ltrim(rtrim(:fdate))||''' and ''' ||ltrim(rtrim(:tdate))||''''; else where_cond:=' and tbl_donation.donation_date '||:date_option||''''||ltrim(rtrim(:fdate))||''''; end if; end if;
--------------Country------------------- if upper (ltrim(rtrim(:country))) <> 'ALL'then where_cond:= where_cond||'and tbl_donation.country_code='||ltrim(rtrim(:blk_ihelp.country_code)); else where_cond:= where_cond||'and tbl_donation.country_code is not null'; end if;
-------------Contact Code--------------- if :contact_code is not null then if :contact_code = 'BETWEEN'then
I need to filter records in a datablock based on Yes or No criteria.So i created a listitem(INCLUDE_ZERO_QTY_ITEMS) for that and i am using following code in WHEN-LIST-CHANGED trigger.
BEGIN IF :XGEC_SW_ITEM_LOAD_ITEM_DETS_V.INCLUDE_ZERO_QTY_ITEMS = 'Y' THEN GO_BLOCK ('XGEC_SW_ITEM_LOAD_ITEM_DETS_V'); SET_BLOCK_PROPERTY ('XGEC_SW_ITEM_LOAD_ITEM_DETS_V', default_where, '1=1'); [code]....
I am able to filter the records but the list item is not displaying initial value and the value that i am selecting from poplist.
I have for example two text items(number of records to display is set to 9). What I want is when i go to studentprofile block, it should automatically shows his subjects that are already taken up. the first text item is for 1st semester subjects and the other for 2nd semester.
here is the structure of my subjsec table:
ID number(1) subj_code varchar2(10) day varchar2(10)
and for subjects table:
subj_code varchar2(10) description varchar2(50) units number(1) semester varchar2(10)
I restricted subjects that are in 1st sem. So i did something like this in my
DECLARE
CURSOR studgrade_cur IS SELECT g.stud_id, g.grade, g.subj_code, s.description, s.units, s.semester FROM studgrades g , subjects s WHERE g.subj_code = s.subj_code AND g.stud_id = :Studentprofile.student_id;
I have 1M Records coming from an External Data source as a Flat File (using ETL). Now I need only Yesterday's data only to load in my Database Table.
this can be done using Bulk Load and Filter.
write the CODE.
Second Part:-
Hint: if I need to update only those records been updated Say the Address1 field is updated. So this records need to update in my Master Customer Table.
If I have many fields in table and any records that are modified (coming to me from External Datasource as a Flat file) how to identify and update that record in my Master Customer Table?
I am having trouble trying to pull the next value from a query based on a where clauseThe query I am using is:
Declare nextID NUMBER(22);BEGINselect lag(ref_contact_id, 1,0) OVER (ORDER BY ref_contact_id)into nextID from (select ref_contact_id,lead(ref_contact_id, 1,0) OVER (order BY ref_contact_id) as "NextNbr", lag(ref_contact_id, 1,0) OVER (order BY ref_contact_id) as "LastNbr"from (select rc.ref_contact_id from REF_CONTACT rc order by FIRST_NAME ))where ref_contact_id = 793 ;END; The returned value is 0.
I understand why but not how to pull the next value base on a particular ref_contact_id.
In the database we use for transfer articulation, there are numerous tables delivered with the product. The institution decided not to use certain fields, and all instances of those fields have no data. In other words, there might be a field in the table called INSTCD, but no records in the table have ever inserted any data into that particular field. In the table there are thousands of records, and we don't necessarily know which of the fields have never been used (no list has been retained and no one who initially was involved in the decisions is available to ask), as there are multiple fields in each table. How can I write a query that pulls only the fields in the table that contain data. In the example below, the SHRTRIT table contains a field called ACTIVITY_DATE, but there is no data in any record in that particular field, so I don't want it to show up on the output. In this particular case, I KNOW not to pull this field in a SELECT, but in a case where there might be 130,000 records and I DON'T know if a field has records in it, how could I do that?
if the question I'm asking doesn't make sense and I'll attempt to word it better.
I want to move data between two instances and recommended we create a local database link to PULL data from remote database located here (supplier on site) but they want to PUSH data to us. I thought you could only PULL data over a database link but then read the link [URL] where PUSH is considered ? I was going to use standard creatas like create table A as select * from table A@<remote_db_link> which works well and fast ( tried and tested) but some are saying they think PUSH quicker/better ?
we do have data "PUSH" already but this does not use a db link - effectively it calls a local proceedure here and passes a row of data and is slow ie for a 1000 row table to be pushed to us we have our local proceedure called 1000 times.
I have always suggested a PULL with db_link as the fastest method - any proof OR info on a fast PUSH method ( that is quicker than PULL ) ? can you REALLY push ?
I'm needing to pull data into a cursor, then split this data into 3 different tables, each having the same number of rows and a select number of columns from the original. i can pull the data, but then i can only access it one row at a time via FETCH, then i can't load into the 3 new CURSORS one row at a time.
I am writing a query where I'd like to pull one year's worth of data. Ideally I want to prompt for the END DATE and have the query go back in time one year from that date.
Here is what I've got after doing some research online... but It's not quite working for me.
select * from mrtcustomer.profile where reg_type = 'B' and contact_type = 0 and active_ind = 'Y' [code].....
I'm trying to pull all the degrees into a table based on which institution is selected. If institution is 'AAA' or 'BBB' then pull ACAD_PLAN, DESCR by ACAD_PROG where ACAD_PROG >= some value and <= some other value.
If institution is 'CCC' then pull ACAD_PLAN, DESCR by institution regardless of ACAD_PROG.
Something like
INSERT INTO table SELECT 'value_a'
[Code].....
I don't have this formatted right cause it keep telling me missing keywords.
My table has the follwoing 3 columns (in addition to others)
Col Name = active ; type=number ; values=1 (true) or 0 (false) col name start_date ; type=date; format=dd-mmm-yy col name end_date ; type=date; format=dd-mmm-yy
I need to select all rows where all active=1, start_date=<today and end_date=>today
my sql is: SELECT id, start_date, end_date FROM offers WHERE (active='1' AND start_date<='14-SEP-09' AND end_date>='14-SEP-09');
However the results are not right. Example, the first row returned is: Offer5000312 01-JAN-09 11-DEC-08
This is not correct. Due to the end_date this row should not be part of the results.
I have a report based on one table with three columns , one column will be updated upon user intervention that if approves the status flag of that column will be 3 and if he amends it will be 1 , by default it will be null.I want to display digital signature or image if the status is approved.I want to store the image/digital signature in Database.Do i need to create a table with BLOB column and store.
create table ot_rq_head ( r_date date, r_no number , r_status number );
I have a complex requirement to be resolved, i have one table of quantities from where i want to show or select the data based on 2 criteria.
1) if the ps_qty is greater than 1000 then there should be two lines , like the qty should not be displayed greater than 1000, instead it should be lesser than 1000. 2) The weight should not be more than 50,000, it should be less than 50000 if its more it should be displayed as 2 lines.
The following is the test case.
CREATE TABLE OW_STAG_SHIP (PS_CODE VARCHAR2(12),PS_DESC VARCHAR2(30),PS_QTY NUMBER,PS_WT NUMBER); INSERT INTO OW_STAG_SHIP VALUES ('A','AAA',400,30000); -- this will be displayed as its because qty and wt are ok INSERT INTO OW_STAG_SHIP VALUES ('B','BBB',1100,4000); --Need to be displaed in two lines as qty is more than 1000 INSERT INTO OW_STAG_SHIP VALUES ('C','CCC',2500,6000); --Need to be displayed in three lines as qty is more INSERT INTO OW_STAG_SHIP VALUES ('D','DDD',600,60000); --Need to be displaed in two lines as wt is more. select * from ow_stag_ship
i am looking to write a query that will count all NOT NULL queue values in a table that belongs to a certain group, but not sure how to write it. The following is what I have wrote, but just wanted to clarify how to implement count case based on 2 criterias.
select * count(case when queue is not null then 1 end) over(partition by group) as queue_orders from table_a;
For example if I have 10 jobs that belong to group 1, but I would like to count all group 1 jobs that have a queue value.
I have no data at the mo, just something that I am trying to start off.
I have an Oracle 10g database, on the App Serv I have an image file that has 20,000 .jpg files that has an id number as each image name.I have successfully queryed the image file and posted one image to my web page matching the image id number. sample:
the &1 is the matching id number that is input from the user.My task now is to select multiple images using a department field in the spriden table to pull the needed id numbers.I have not been successful in the proper format to pass the id number to the <img src field.
I have the following query with analytic function but wrong results on the last column COUNT.
1)I am getting the output order by b.sequence_no column . This is a must. 2)COUNT Column :
I don't want the total count based on thor column hence there is no point in grouping by that column. The actual requirement to achieve COUNT is:
2a -If in the next row, if either the THOR and LOC combination changes to a new value, then COUNT=1 (In other words, if it is different from the following row)
2b-If the values of THOR and LOC repeats in the following row, then the count should be the total of all those same value rows until the rows become different. (In this case 2b-WHERE THE ROWS ARE SAME- also I only want to show these same rows only once. This is shown in the "MY REQUIRED OUTPUT) .
My present query: select r.name REGION , p.name PT, do.name DELOFF, ro.name ROUTE,
[code]...
My incorrect output[PART OF DATA]:Quote: REGIONPT DELOFF ROUTE THOR LOC SEQ COUNT NAASNAAS MAYNOOTHMAYNOOTHR010 DUBLINRD CEL 1 1 NAASNAAS MAYNOOTHMAYNOOTHR010 NEWTOWNRD CEL 2 1
[code]...
My required output[PART OF DATA]-:Quote: REGIONPT DELOFF ROUTE THOR LOC COUNT NAASNAAS MAYNOOTHMAYNOOTHR010 DUBLINRD CEL 1 NAASNAAS MAYNOOTHMAYNOOTHR010 NEWTOWNRD CEL 1 NAASNAAS MAYNOOTHMAYNOOTHR010 PRIMHILL CEL 1
[code]...
NOTE :Count as 1 is correctly coming.But where there is same rows and I want to take the total count on them, I am not getting.
2. report parameters will be the bill_month & no_of_months
Based on above 2 parameters I need to scan through the data for BILL_MONTH <= '20-Jun-2012' and NO_OF_MONTHS <= 6 the other criteria being the AVG_IND in (1,2).
In brief the criteria will be to pick all BPRF_NO having AVG_ID in (1, 2) consecutively till a break (AVG_IND not in (1, 2) starting from the given BILL_MONTH and going below this period, that is BILL_MONTH <= '30-Jun-2012'.
For the below data, if my parameters are: BILL_MONTH <= '30-Jun-2012' and NO_OF_MONTHS <= 3, only the underscore added data should be picked (as they fulfill the criteria) and the report output will be like:
Here the NO_OF_TIMES is the count, that is no of times the BPRF_NO falls into the above mentioned criteria consecutively starting from the provided BILL_MONTH.
I am using: Desktop / Discoverer 4.1 / Windows XP.
I am attempting to add a new calculated column and have had some success with the CASE function but need to add additional criteria.
What I have that works is:
SUM(CASE WHEN Expenditure Type = 'Supplier Rebates' THEN Total Spend Plus Commit ELSE 0 END)
What I need to add are a few additional criteria. I attempted and failed with a few variants of this:
SUM(CASE WHEN Expenditure Type = 'Supplier Rebates' AND Capitalizable = 'Y' AND Task Owing Company = '534' OR '915' THEN Total Spend Plus Commit ELSE 0 END)
The three criteria points that I am looking to includea are:
•Expenditure Type = 'Supplier Rebates' •Capitalizable = 'Y' •Task Owing Company = '534' OR '915'
I have search function that takes the input parameters and returns all the matching rows. this is straight forward only. My problem is having multiple types as a input parameter. that is the reason i am not able to pass the input value for these types.
My Input Type table looks like this.
CREATE OR REPLACE TYPE T_T_PARTY_REQUEST_CRITERIA AS TABLE OF T_O_PARTY_REQUEST_CRITERIA; / CREATE OR REPLACE TYPE T_O_PARTY_REQUEST_CRITERIA AS OBJECT ( SYSTEM_IDENTIFER VARCHAR2(50), PROCESS_TYPE VARCHAR2(50), [code]........
Last two inputs are type again.my question here is how to pass the values for these two T_T_PARTY_KEY_IDENTIFIER and T_T_ADDTN_IDENTIFIER_INFO. I have defined the the last two types following.
CREATE OR REPLACE TYPE T_T_PARTY_KEY_IDENTIFIER AS TABLE OF T_O_PARTY_KEY_IDENTIFIER; / CREATE OR REPLACE TYPE T_T_ADDTN_IDENTIFIER_INFO AS TABLE OF T_O_ADDTN_IDENTIFIER_INFO; / [code].......
I have pasted the query here from my function. when i pass the null as part of input for these 2 types my query is working. otherwise it is saying invalid Identifier.First I tried with first Type.
I am passing the value as
(PRKYTP.PRTY_KEY_TYP_NM = ITTPRC.PARTY_KEY_IDENTIFIER.PARTY_KEY_TYP_NM OR ITTPRC.PARTY_KEY_IDENTIFIER.PARTY_KEY_TYP_NM = 'ALL' OR ITTPRC.PARTY_KEY_IDENTIFIER.PARTY_KEY_TYP_NM IS NULL);
Error is Error(34,147): PL/SQL: ORA-00904: "ITTPRC"."PARTY_KEY_IDENTIFIER"."PARTY_KEY_TYP_NM": invalid identifier
SELECT DISTINCT T_O_PARTY_REQUEST_IDENTIFIER(PR.PRTY_RQST_ID) BULK COLLECT INTO T_T_P_R_CRITERIA FROM TABLE(CAST(I_T_T_PARTY_REQUEST_CRITERIA AS T_T_PARTY_REQUEST_CRITERIA)) ITTPRC, PRTY_RQST PR JOIN BUSN_APPLC BIAP ON BIAP.BUSN_APPLC_ID = PR.BUSN_APPLC_ID [code]........