Need objective sql and pl/sql question for preparing interview
Hey buddy please help me, now I am preparing interview of sql and pl/sql where asking objective question, so I need online site for preparing interview, your suggestion would be greatly appreciated.
Have you tried searching using one of the many Internet search engines?
I expect that there are many kinds of sites out there that may cater to you.
The only other recommendation I would have would be to review the documentation at http://tahiti.oracle.com. Probably the SQL Language Reference, PL/SQL Reference, Application Developer's Guide, and Concept's Guide.
Similar Messages
-
Need some intermediate and advance level website for SQL
Hi Gurus
I want to improve my SQL skills, is there any website through which I can improve that skills.
Need some intermediate and advance level website for SQL.
appreciate your suggestion. Thanks
Regards
Shuif you have a lot of time you can follow some of the larger threads on AskTom. I think Mr. Kyte can do almost anything with SQL. And there are also some recurrent contributors as Stew Ashton provinding very interesting solutions.
Another option is to take a look at the answers in this forums: some participiants as Frank Kulash or Solomon Yakobson (to name just two of them) come up with astonishing pieces of SQL frequently. -
Need pl/sql stmnts. for this simple logic
Hi,
I need PL/SQL program for this simple logic i am doing mistake somewhere unbale to trace
out ..
select * from GSR03_PO_DTL;
PO_NUM
L53177000 -- > no changes reqd (only one entry with new format)
L00041677 --> to be updated to L41677000(only one entry with OLD format)
L43677000 -- > no change reqd (exists one row with new format and old format like below)
L00043677 -- > to be deleted this is old format (and new format like above already exists)
EX:
L00012345 --- old format
L12345000 --- new format
Hope question is clear. I written the following program.
update is working fine but delete is not working.
Please help.
Thanks in Advance
Devender
declare
Cursor c_test is
(select po_num from GSR03_PO_DTL);
BEGIN
FOR r_test in c_Test
LOOP
dbms_output.put_line (r_test.po_num);
IF ('L'||substr(r_test.po_num,5,5)) = ('L'||substr(r_test.po_num,2,5)) then
dbms_output.put_line ('delete stmnt');
END IF;
EXIT WHEN c_test%NOTFOUND;
END LOOP;
FOR r_test in c_Test
LOOP
IF r_test.po_num like 'L000%' then
IF ('L'||substr(r_test.po_num,5,5)) is not NULL then
update GSR03_PO_DTL set PO_NUM = 'L'||substr(po_num,5,5)||'000'
where po_num like 'L000%' ;
dbms_output.put_line ('update stmnt');
END IF;
END IF;
END LOOP;
END;
*********************No need for PL/SQL, man.
SQL> SELECT po_no FROM po1
2 /
PO_NO
L53177000
L00041677
L43677000
L00043677
SQL> UPDATE po1 y
2 SET y.po_no = 'L'||substr(y.po_no,5,5)||'000'
3 WHERE y.po_no LIKE 'L000%'
4 AND NOT EXISTS ( SELECT null FROM po1 x
5 WHERE x.po_no = 'L'||substr(y.po_no,5,5)||'000')
6 /
1 row updated.
SQL> DELETE FROM po1 y
2 WHERE y.po_no LIKE 'L000%'
3 AND EXISTS ( SELECT null FROM po1 x
4 WHERE x.po_no = 'L'||substr(y.po_no,5,5)||'000')
5 /
1 row deleted.
SQL> SELECT po_no FROM po1
2 /
PO_NO
L53177000
L41677000
L43677000
SQL> Cheers, APC -
SQL Statement for Post-Interview Question
Hello,
I was recently asked a question for an interview and think I got (part of it) wrong, but here is the question followed by my query with output. If someone could show me where I went wrong I would greatly appreciate it. It would be a great learning experience
for me. I think where I fell short was the count of each repeating output row.
Q: There is a table called Member with three columns: MemberID, FirstName, and LastName. We need a query to find how many First Name and Last Name combination duplicates exists.
The desired output is First Name, Last Name, total number times the combination is repeated.
• BONUS question 1: Have the result set with the largest number of duplicates first.
• BONUS question 2: What do you do if there are extraneous leading or trailing spaces on each name cause the same first name last name combination showing up on multiple lines?
SELECT * FROM (
SELECT (ROW_NUMBER() OVER (
ORDER BY a.LastName, a.FirstName, a.MemberID DESC
)) AS ROWNUM
, a.MemberID
, rtrim(ltrim(a.LastName))
, rtrim(ltrim(a.FirstName))
, a.name
FROM User_Details AS a INNER JOIN
(SELECT rtrim(ltrim(LastName)), rtrim(ltrim(FirstName))
FROM User_Details
WHERE LastName !='' AND FirstName != ''
GROUP BY LastName, FirstName
HAVING
(COUNT(*) > 1)) AS b ON rtrim(ltrim(a.LastName)) = rtrim(ltrim(b.LastName)) AND rtrim(ltrim(a.FirstName)) = rtrim(ltrim(b.FirstName))
WHERE 0=0
--first placeholder condition
) AS TEAM_OUTPUT
WHERE ROWNUM BETWEEN 1 and 100
Output:
123456 Allen Michael
123456 Allen Michael
46683 Allen Michael
46683 Allen Michael
71795 Allen Mike
71795 Allen Mike
32171 Allen Mike
32171 Allen Mike
38058 Allen Patricia
32524 Allen Patricia
211454 Allen Susan
34679 Allen Susan
29826 Allen Susan
39684 Allen Teri
77557 Allen Terri
227006 Allen Theresa
107360 Allen Theresa
Thanks,
BusterShouldn't it be as simple as
SELECT FirstName, LastName, COUNT(*) AS C
FROM Member
GROUP BY FirstName, LastName
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
(add the LTRIM AND RTRIMs back in to deal with the possible extra spaces) -
XML SQL format for Prepared statements in batch mode
Hi
I want to use the batch mode in JDBC adapter for inserting huge volume of records with better performance.
so i need to execute the prepared statements in one batch. Is the XML SQL format for prepared statements below correct ?to<root>
<stmt>
<Customers action="SQL_DML">
<access> INSERT INTO Customers (CompanyName,Address,CustomerID) VALUES($NAME$,$ADDRESS$,$KEYFIELD$)
</access>
<key>
<NAME>IBM</NAME>
<ADDRESS>Street 3 </ADDRESS>
<KEYFIELD>CO</KEYFIELD>
</key>
<key>
<NAME>PWC</NAME>
<ADDRESS>Street 4 </ADDRESS>
<KEYFIELD>NO</KEYFIELD>
</key>
</Customers>
</stmt>
</root>
Please adviseHello Experts
Please throw some light on the above question.
Thanks in advance. -
Hi,
I need a PL/SQL code for this one...
Let me know if something is not clear...
1) The table CLOB_CLOBJECT_CDA has the columns described below...
Explaining only those fields which are important in this context
-- CDA_STEP_ID : Basically a Sequence
-- CLOBJECT_SOURCE1_ID : Every id has got a set of records
-- CLOBJECT_SOURCE2_ID : Every id has got a set of records
-- LVL : There are total 8 levels..
This is the main aim :
1) There are total 16 million rows..(limited to 10 rows here)
2) We need to go through level by level (LVL column) & insert the intersection records (CLOBJECT_SOURCE1_ID intersect CLOBJECT_SOURCE2_ID)
into another table...but this is how it goes..
Level (LVL column) 3's basically have CLOBJECT_SOURCE1_ID as level (LVL column) 2 CDA_STEP_ID's..
(consider the statement --** where CLOBJECT_SOURCE1_ID = 285 which is same as 1st insert statement step id)..
The above process goes for next levels until 8..(so have to use loops)
So for ex :
We go through the first insert statement and insert the insertion records only when both CLOBJECT_SOURCE1_ID & CLOBJECT_SOURCE2_ID has got records ..
If we don't find any records for both of them we should skip the corresponding step id when we go to the next levels...
Let's go through the 1st insert statement...
-- We have CDA_STEP_ID = 285 & two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 74...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 74 ..(In fact we insert counts into this table only if they have records)
-- If so, we insert the intersection records into CDA_MRN_RESULTS ( we do have counts for both of them..) with CDA_STEP_ID 285...
-- Then we insert the step id which is 285 along with the count into CLOBJECT_COUNTS..
Let's go through another insert statement...
-- Consider CDA_STEP_ID = 288 which has two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 92...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 92 ..(we have records for 19 but not for 92)
-- So we should not proceed with this..& also skip all those records (future records with increasing levels..basically level 3's) which have got 288 as CLOBJECT_SOURCE1_ID..
(As said earlier that the present CDA_STEP_ID will always be CLOBJECT_SOURCE1_ID in the next level)...
I wrote the following code which is after the statement...
Let me have the create & insert statements here..
create table CLOB_CLOBJECT_CDA
CDA_STEP_ID NUMBER,
CDA_ID NUMBER,
CDA_SEQ_NUMBER NUMBER,
CLOBJECT_SOURCE1_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE1_ID NUMBER,
CLOBJECT_OPERATOR VARCHAR2(3000),
CLOBJECT_SOURCE2_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE2_ID NUMBER,
LVL NUMBER
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (285, 285, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 74, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (286, 286, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 75, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (287, 287, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 91, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (288, 288, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 92, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4869, 4869, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 91, 3); -- **
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4870, 4870, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4871, 4871, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 93, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4880, 4880, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 91, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4881, 4881, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4882, 4882, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 93, 3);
create table CDA_MRN_RESULTS
CDA_STEP_ID NUMBER,
MRN NUMBER,
INSERT_DATE_TIME DATE
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 4, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 6, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
create table CLOBJECT_COUNTS
CDA_STEP_ID NUMBER,
CLOBJECT_COUNT NUMBER,
DATE_TIME DATE
Insert into CLOBJECT_COUNTS values (19,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (74,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (75,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (91,2, to_date('19-10-2011', 'dd-mm-yyyy'));The output goes into two tables...
CDA_MRN_RESULTS : O/p of intersection records between source1 & source2 id
CLOBJECT_COUNTS : Step id with counts ...(useful for skipping next level step id's if either of source id has "0" counts)
Any help is appreciated..
Thanks..I tried to code this..but looping takes a lot of time..I want to skip certain rows where source1_step_id & source_2_step_id are not in clobject_counts table as we proceed to the next levels..Not sure how to skip the rows..
declare
cursor c1 (p_level varchar2 ) is
Select * from clob_clobject_cda
where lvl = p_level ;
TYPE V_TT IS TABLE OF C1%ROWTYPE INDEX BY PLS_INTEGER;
L_TT V_TT;
v1 number;
v2 number;
v_step_id number;
v_operator varchar2(100) := '';
begin
for i in 2..8 loop
open c1(i);
LOOP
FETCH C1 BULK COLLECT INTO L_TT LIMIT 500;
FOR indx IN 1 .. L_TT.COUNT
LOOP
v1 := L_TT(indx).clobject_source1_id;
v2 := L_TT(indx).clobject_source2_id;
v_step_id := L_TT(indx).cda_step_id;
v_operator := L_TT(indx).clobject_operator;
Execute Immediate ('Insert into cda_mrn_results Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v1 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' ||
v_operator ||
' Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v2 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' );
Insert --+ Append
into clobject_counts Select cda_step_id, count(distinct mrn),
insert_date_time dt from cda_mrn_results where cda_step_id = v_step_id group by cda_step_id,insert_date_time;
COMMIT;
END LOOP;
EXIT WHEN L_TT.COUNT = 0;
END LOOP;
CLOSE C1;
End Loop;
Commit;
End; -
Proxy to JDBC scenario need dynamic sql query for sender .
Hi Experts,
I am developing proxy to jdbc scenario. in this i need to pass dynamic sql query whre we are passing classical method like below.
while we are passing select stmt in constant and mapped with access field and key field mapped with key field.
MY requirement is like instead of passing select stmt in constant where i can generate dynamically and passed in one field and mapped with access field.Hi Ravinder,
A simple UDF or use of graphical mapping functions in most cases should provide you everything you need to construct a dynamic SQL statement for your requirement.
Regards,
Ryan Crosby -
Need the sql query for IN clause.
Hi All,
i have item data like --
IBM 200 and IBM 500
have present code like this ----select * from emp where in (IBM 200 and IBM 500);
so i need change or repalce like ('IBM 200','IBM 500')
Any body please help me out this..
Need to get out put 'IBM 200','IBM 500' from data IBM 200 and IBM 500 ...
Edited by: anbarasan on Oct 17, 2011 10:30 PMPlease consider the following when you post a question. This would help us help you better
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude. -
GL AND AR datasource and data targets - question for BI 7.0
Folks,
It has been sometime I did GL, AP and wanted to know if this still holds good
GL Balance : Extract via 0FI_GL_6 and load it to 0FIGL_C01 with or whihout an ODS OFIGL_O06.
GL Line itms: Extract via 0FI_GL_4 and load to ODS 0FIGL_O02.
Similiarly use AP_6 and AP_4 Data sources for Accounts Payable. I am assuming GL and AP Data sources are coupled.
Now has anything changed in BI 7.0 or because of ECC5 or ECC6.
For All the above I did not see any transformation BI Content I only still see 3.x flow.
whats up with 0FIGL_C10 and 0FI_GL_10 ?.
At the end of the day I only need GL balance and their line items. So what should I use ?.
thanks
GmanHi GMAN,
1) GL and AP datasources extract from 2 different sets of OLTP tables. They are NOT coupled
from BW extraction pointof view....But In R3...when a financial posting is made to a GL
account....a related posting made into AP tables......
2) In GL or AP functionality nothing has changed due to: BI 7.0 or because of ECC5 or ECC6.
3) In the new Business Content Release...."SAP NW 7.0 BI Content Add-on 3 SP06"....
SAP gave new cubes, ODS etc....
New Business Content link:
http://help.sap.com/saphelp_nw2004s/helpdata/en/3d/5fb13cd0500255e10000000a114084/frameset.htm
Good luck, BB -
What I need to create and publish a magazine for iOS and Android?
Hi!
I would like to know what I need to design, create and publish a magazine for iOS and Android. I would also like to know what products I need, what price would you pay and what process I have to follow to carry out this work.
Thanks in advance!It is NOT possible to create a Single Edition app for Android. Single Edition apps work only on the iPad.
You can create Single Edition apps using any account—CC, Pro, or Enterprise—and if you cancel your DPS subscription, these Single Edition (or single-folio) apps are still available in the App Store as long as you maintain your iOS account with Apple.
For multi-folio apps, the app container is downloaded from an app store, but the folios are downloaded from the Adobe Distribution Service. If you cancel your DPS subscription, the Adobe Distribution Service basically shuts down for that app. New users can still download your apps from an app store, but the library will be empty. Existing users can still view the folios they've downloaded, but they can't get any updates or new folios. -
Facts and Figures - A Question for the Forum Mods
A bit of a daft question for which I am sure the Forum Mods can provide an answer.
How many folks were registered on the old forum and how many on the new one?
I just want to put something BT Chairman Sir Michael Rake wrote to BT shareholders this month into context.
"To forbid us anything is to make us have a mind for it."
-- Michel de Montaigne, Essays, 1559Naughty naughty General - they dont do "daft" on this forum, you should know that.
"You may well think that, I'm afraid I could'nt possibly comment"
Francis Urqhuart, who was never known by his initials to his friends.
AQ.
"Welcome to Royston Vasey - You'll never leave." -
Need object,Name and ID of Contract
Hi All,
I want to read text under contract number(VA43) of Header text of SITE ID/LINK ID by using read_text.
as i need to pass object , name and id if anyone knows this information pls reply me back.ur help is appriciated.
With regards,
Hari..In general, upon double clicking inside the text area, you will be navigated (if not already there) to the text 'editor' view. Next, via the menu navigate from Goto->header. This is where the get your info.
-
Need PL/SQL Command for to check all rows value for child record and update
Hi All,
i want to update one field following by
one to many relationship for example
in child applet status field is value is "Closed" for all child record then parent value also should update to closed
Note: if one child record field status is "Open" don't do the update operationYou can do it in single UPDATE operation.
Here is sample & Result:
create table PA (id varchar2(3), name varchar2(12), STATUS varchar2(12));
insert into pa values('001','Cary','Open');
insert into pa values('002','TOM','Open');
create table boy (par_id varchar2(3), id varchar2(4), name varchar2(12), status varchar2(12));
insert into boy values('001','ABC1','Cary','Open');
insert into boy values('001','ABC2','Mac','Closed');
insert into boy values('001','ABC3','Ray','Closed');
insert into boy values('001','ABC4','NALLY','Open');
insert into boy values('002','ABC5','ME','Closed');
insert into boy values('002','ABC6','SHE','Closed');
UPDATE PA
SET STATUS='Closed'
WHERE NOT EXISTS
(SELECT 1
FROM BOY
WHERE BOY.PAR_ID=PA.id
GROUP BY BOY.PAR_ID,
BOY.STATUS
HAVING SUM(DECODE(BOY.STATUS,'Open',1,'Closed',0,0))>0
select * from pa;
001 Cary Open
002 TOM Closed -
SQL question for to get a top customer
Hi All,
I am prasanna. I have a question on SQL,to get a top customer based on year and customer name.I written query like this. But i got an error.
select calendar_year,cust_first_name,max(sum(amount_sold)) from sales,times,customers where sales.cust_id=customers.cust_id and times.time_id=sales.time_id group by calendar_year,cust_first_name
The error is like this:
*Error starting at line 1 in command:
select calendar_year,cust_first_name,max(sum(amount_sold)) from sales,times,customers where sales.cust_id=customers.cust_id and times.time_id=sales.time_id group by calendar_year,cust_first_name
Error at Command Line:1 Column:7
Error report:
SQL Error: ORA-00937: not a single-group group function
00937. 00000 - "not a single-group group function"*
*Cause:
Action:
Thanks inadvace
Regards,
prasannaIt is not clear what you want. Code below will return a customer with highest total amout sold regardless of year:
select calendar_year,
cust_first_name,
total_amount_sold max_amount_sold
from (
select calendar_year,
cust_first_name,
sum(amount_sold) total_amount_sold,
row_number() over(order by sum(amount_sold) desc) rn
from sales,
times,
customers
where sales.cust_id=customers.cust_id
and times.time_id=sales.time_id
group by calendar_year,
cust_first_name
where rn = 1
/Keep in mind, if more than one customer has that highest total amount sold and you want all such customers:
select calendar_year,
cust_first_name,
total_amount_sold max_amount_sold
from (
select calendar_year,
cust_first_name,
sum(amount_sold) total_amount_sold,
rank() over(order by sum(amount_sold) desc) rn
from sales,
times,
customers
where sales.cust_id=customers.cust_id
and times.time_id=sales.time_id
group by calendar_year,
cust_first_name
where rn = 1
/And if you want top customer for each calendar year:
select calendar_year,
cust_first_name,
total_amount_sold max_amount_sold
from (
select calendar_year,
cust_first_name,
sum(amount_sold) total_amount_sold,
row_number() over(partition by calendar_year order by sum(amount_sold) desc) rn
from sales,
times,
customers
where sales.cust_id=customers.cust_id
and times.time_id=sales.time_id
group by calendar_year,
cust_first_name
where rn = 1
/Keep in mind, if more than one have that highest total amount sold and you want all such customers:
select calendar_year,
cust_first_name,
total_amount_sold max_amount_sold
from (
select calendar_year,
cust_first_name,
sum(amount_sold) total_amount_sold,
rank() over(partition by calendar_year order by sum(amount_sold) desc) rn
from sales,
times,
customers
where sales.cust_id=customers.cust_id
and times.time_id=sales.time_id
group by calendar_year,
cust_first_name
where rn = 1
/SY.
Edited by: Solomon Yakobson on Dec 22, 2011 9:24 AM -
Need PL/SQL procedure for file transfer local system to server location
Hi Experts,
The requirement is one file ex: text file,excel file is there in Local system suppose c:newfolder/test.txt.
once run the concurrent program for this particular file in the local system should transfer into server location for the mentioned path.
is it possible to do in PL/SQL or shell script.
can you please share the code.
Thanks
MeherMeher Irk wrote:
The requirement is one file ex: text file,excel file is there in Local system suppose c:newfolder/test.txt.
once run the concurrent program for this particular file in the local system should transfer into server location for the mentioned path.Why do you want to copy a local file from the local client file system, via the Oracle database server, to a remote directory on the server?
Why is the Oracle database server to be used? For what purpose?
There are standard secure methods for a client to copy a file to a server. Such as sftp and scp. No complex Oracle database server layer needed in-between.
So why do you want to use the Oracle database to act as the copy mechanism for you?
It will only make sense if the local file is copied into the database (as a LOB or securefile) and managed by the database. I fail to see why Oracle should be acting as the go-between for the client file system copy process to the server file system. This introduces another moving part in the copy process. Adds more security issues. Adds more authentication issues. And what for?
Maybe you are looking for
-
How to find out which "purchased items" are not authorized?
I have an iPhone 5, and my son has an iPod touch that are both synced to iTunes on my MacBook Pro. Since I upgraded the MBP to Yosemite, I can no longer sync the apps on the iPod; it always responds with "The iPod could not be synced because this com
-
Is there another way to download music to iPods without using iTunes
Do I have to use iTunes to download music to our ipods
-
D200 P2P mode import fails on Vista 64
If I set my D200 USB mode to "PTP" Lightroom cannot see any images on the D200, but Vista can. However, if I set the D200 USB mode to "MAss Storage" Lightroom is able to see and import files. It would be nice to get that fixed, since P2P mode is requ
-
IChatUSBCam not supported by 10.4.3
Hi all, I used to be able to use my Kritter USB web cam with OS 10.4.2 by using iChatUSBCam 2.0.3 along with ioxpertswebcam 1.1. However, since upgrading to OS 10.4.3, I get the following error message: "iChat USBCam cannot run with this version of i
-
I have a problem updating the new ipod touch 5th generation
I have a problem updating the new ipod touch 5th generation and I need help: With each attempt I receive the message: iTunes has detected an iPod in recovery mode. You must restore this iPod before it can be used with iTunes. The iPod only displays