SQL STATEMENT , PLEASE HELP
Hi,
I want some help in writing a SQL Query .Its besically a hierarchical query. Let me lay down the table structure first to explain my requirements better.
PORP_TABLE(NODE_LEVEL int, WBS_ID int, WBS_NUMBER varchar(60), LFT int,RGT int)
SELECT NODE_LEVEL, WBS_ID, LFT,RGT FROM PROPOSAL_WBS PW WHERE PROPOSAL_REV_ID = 7000
(SAMPLE DATA)
NODE WBS
LEVEL WBS_ID NUMBER LFT RGT
0 7055 ROOT 1 24
1 7056 1 2 5
1 7088 2 6 9
2 7057 1.1 3 4
2 7089 2.1 7 8
2 7091 3.1 11 14
2 7103 3.2 15 16
2 7105 4.1 19 20
1 7090 3 10 17
3 7092 3.1.1 12 13
1 7104 4 18 23
2 7106 4.2 21 22
ALLOCATION_DETAIL( WBS_ID int, COST_ID int, PERIOD Date, AMOUNT Float)
sample data
WBS_ID , COST_ID , PERIOD , AMOUNT
7057 100 01-jan-2005 5000
7057 100 01-feb-2005 2000
7057 100 01-mar-2005 1000
7057 100 01-apr-2005 6000
7057 100 01-may-2005 3000
7057 100 01-jun-2005 45000
7106 100 01-mar-2005 8000
7106 100 01-apr-2005 7000
7106 100 01-may-2005 9000
Now the PORP_TABLE has got the parents and childs. Only the leaf nodes in the hierarchy has the values stored in the ALLOCATION_DETAIL table. Now here is the scenario
In the example 7055 is the root WBS . The Leaf WBS are the one with max extension in the wbs number ( in this case it is 1.1, 2.1, 3.1.1, 3.2, 4.1 and 4.2)
Now the Starting period for each leaf node in the ALLOCATION_TABLE could be differrent . What that means is WBS 1.1 could start in Jan -2003 and WBS 3.1 Could be Jul-2005 . So the ending perios are also differrent for differrent WBS . Some can span 2 years some can 5 years.
So how to write a query so it retrieves the value for all the Wbs starting from the MIN ( PERIOD ) upto the MAX(PERIOD), and it should roll up also. Now there is No connect by Prior or any analytic functions available for this . THIS NEEDS TO BE DONE ONLY THROUGH TRADITIONAL SQL STATEMENT . And NO DB FUNCTIONS CAN BE USED .
Now if the WBS is a parent node then it should have the sum of all its child nodes for the COST category.
SO THE RESULT SET SHOULD BRING LIKE THIS
WBS_NUMBER, PERIOD_NUMER, COST_CATEGORY , AMOUNT
ROOT
1
1.1
2
2.1
3
3.1
3.1.1
3.2
4
4.1
4.2
......
Thanks for all your thoughtfull replies and feedbacks. Yes it is in Sybase platform . Though I have been woking all along in Oracle , Unfortunately this one is in Sybase, and no the customer cant and wont move to Oracle. So I have to work with it . And if you want to see the table structure . Here are they :
CREATE TABLE PROPOSAL_WBS (
BURDEN_CENTER_ID numeric(18,0) NULL,
START_DATE datetime NULL,
END_DATE datetime NULL,
WBS_ID int NOT NULL,
MODIFIED_DATE datetime NULL,
CREATED_DATE datetime NULL,
MODIFIED_BY varchar(127) NULL,
CREATED_BY varchar(127) NULL,
FEE_PERCENT float NULL,
PROPOSAL_REV_ID int NOT NULL,
PARENT_WBS_ID int NULL,
NAME varchar(127) NULL,
COMMENT varchar(255) NULL,
TARGET_COST float NULL,
MONTHS_REMAINING int NULL,
DEFAULT_STAFF_FTE float NULL,
ANNUAL_GRA_SALARY float NULL,
NUMBER_OF_GRA int NULL,
MANAGEMENT_ADJUSTMENT_TOTAL float NULL,
MA_UNALLOCATED_FUNDS float NULL,
FEE_TOTAL float NULL,
FEE_UNALLOCATED_FUNDS float NULL,
TRAVEL_COMMENTS varchar(255) NULL,
ODC_COMMENTS varchar(255) NULL,
SORT_ORDER int NULL,
LFT int NULL,
RGT int NULL,
NODE_LEVEL int NULL,
WBS_NUMBER varchar(50) NOT NULL,
TOTAL_COST float NULL,
TOTAL_COST_PLUS_FEE float NULL,
PER_MILE_COST float NULL,
PER_DIEM float NULL,
TAX_RATE float NULL,
RENTAL_CAR_PER_DAY_COST float NULL,
TAXI_PER_TRIP_COST float NULL,
CONSTRAINT PK_PROPOSAL_WBS PRIMARY KEY(WBS_ID)
CREATE TABLE PROPOSAL_WBS_ALLOC_DETAIL (
WBS_ID int NOT NULL,
OBJECT_CODE_ID numeric(18,0) NOT NULL,
PERIOD_NUMBER int NOT NULL,
ALLOCATION_AMOUNT float NULL,
PERIOD_YEAR datetime NULL,
CONSTRAINT PK_PROPOSAL_WBS_AD PRIMARY KEY(WBS_ID,OBJECT_CODE_ID,PERIOD_NUMBER)
CREATE TABLE WBS_PERIOD (
PERIOD_NUMBER int NOT NULL
CREATE VIEW WBS_COST_CAT AS
SELECT PROPOSAL_WBS.PROPOSAL_REV_ID,
PROPOSAL_WBS.WBS_ID,
PROPOSAL_WBS.NAME, PROPOSAL_WBS.SORT_ORDER,
PROPOSAL_WBS.NODE_LEVEL, PROPOSAL_WBS.WBS_NUMBER,
CODES.CODE_ID COST_CATEGORY, CODES.CODE_NAME COST_CAT_NAME
FROM PROPOSAL_WBS, CODES
CREATE TABLE CODES (
CODE_ID numeric(18,0) NOT NULL,
CODE_VALUE varchar(254) NULL,
CODE_NAME varchar(254) NULL,
CODE_TYPE numeric(18,0) NULL,
CODE_PARENT_ID numeric(18,0) NULL,
CONSTRAINT PK_CODE_ID PRIMARY KEY(CODE_ID)
So let me explain little bit more . The WBSs are categorized into two differrent types. One as INPUT and the second one as NON INPUT. Now assme the the WBS in a tree structure . So only the LEAF WBSs will have the AMOUNT and they are the INPUT WBSs and all non leaf WBSs are NON INPUT. Now lets say there are 5 LEAF WBSs. Each LEAF WBS will have differrent start period ex: WBS 1.1 starts in January 2003 and goes for 48 periods . WBS 2.1 starts in November 2003 and goes for 35 periods . WBS 3.1 starts in March 2004 and goes for 52 periods. and so on .
Now as there is no Allocation Amount entry for all other WBSs except the LEAF WBSs. So how do I get the roll up . For example if you imagine the parent of WBS 1.1 is WBS 1 , and the parent of WBS 2.1 is WBS 2 and the Parent of WBS 3.1 is WBS 3 , and the parent for WBS 1, WBS 2, WBS 3 is "ROOT WBS". As I said there is no entry for WBS 1, WBS 2 , WBS 3 and the "ROOT WBS". So how do I have a roll up of the Leaf WBS data for their parent WBSs.
Now if u think of the data in a matrix report, the WBSs and the COST CATEGORY will be the row values, the Period Numbers will the column values and the Allocation Amount will be the cross values. so lets say the WBS 1 has got two leaf nodes, WBS 1.1 and WBS 1.2 then WBS 1 will have the summed amount for each period starting the minumum period of the two of its leaf nodes and for all the cost categories of both the leaf nodes. and the "ROOT WBS" will have all the cost categories of al the Leaf nodes . for all the periods , period wise.
Similar Messages
-
SQL experts please help for a query
I have following table1.
What query can give the result as given below, SQL experts please help on this.
TABLE1
Event DATETIME
in 2/JAN/2010
out 2/JAN/2010
in 13/JAN/2010
out 13/JAN/2010
in 5/JAN/2010
out 5/JAN/2010
RESULT REQUIRED FROM THE SQL QUERY
COL1_IN COL2_OUT
2/JAN/2010 2/JAN/2010
13/JAN/2010 13/JAN/2010
5/JAN/2010 5/JAN/2010I tried to help, but this puzzles me.
Why is this not returning pre-selected set of rows, why it's doing some merge join cartezian ?
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> select * from table1;
EVENT DATETIME
in 2/JAN/2010
out 2/JAN/2010
in 13/JAN/2010
out 13/JAN/2010
in 5/JAN/2010
out 5/JAN/2010
6 rows selected.
SQL> explain plan for
2 with a as
(select datetime from table1 where event='in'),
b as
(select datetime from table1 where event='out')
select a.datetime COL1_IN ,b.datetime COL2_OUT from a,b ;
Explained.
SQL> set wrap off
SQL> set linesize 200
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 185132177
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 9 | 288 | 8 (0)| 00:00:01 |
| 1 | MERGE JOIN CARTESIAN| | 9 | 288 | 8 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL | TABLE1 | 3 | 48 | 3 (0)| 00:00:01 |
| 3 | BUFFER SORT | | 3 | 48 | 5 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | TABLE1 | 3 | 48 | 2 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
2 - filter("EVENT"='in')
4 - filter("EVENT"='out')
Note
- dynamic sampling used for this statement
21 rows selected.
SQL> with a as
(select datetime from table1 where event='in'),
b as
(select datetime from table1 where event='out')
select a.datetime COL1_IN ,b.datetime COL2_OUT from a,b ;
COL1_IN COL2_OUT
2/JAN/2010 2/JAN/2010
2/JAN/2010 13/JAN/2010
2/JAN/2010 5/JAN/2010
13/JAN/2010 2/JAN/2010
13/JAN/2010 13/JAN/2010
13/JAN/2010 5/JAN/2010
5/JAN/2010 2/JAN/2010
5/JAN/2010 13/JAN/2010
5/JAN/2010 5/JAN/2010
9 rows selected.
SQL> -
Unsure of syntax for SQL SELECT statement, please help
I am trying to execute the following SQL statement:
ResultSet rs = stB.executeQuery("SELECT quantity FROM stocklevels WHERE code=salesCode[x]");where SalesCode is an integer array and x is a counter used to loop this part of the code. I keep getting the "syntax error - missing operator" message when I run the code and get to this line, can anybody please tell me the correct syntax/form to use? Many thanks.Is salesCode an array in Java or in your DB? I don't know anything about SQL arrays, so I'll assume it's in your Java code.
You want to put the value of salesCode[x] into the query--say 123456. But what you've got is like doing System.out.println("The code = salesCode[x]"); and then wondering why you're seeing "salesCode[x]" instead of "123456. You'd need to do System.out.println("The code = " + salesCode[x]); Similarly, you could take the "salesCode[x]" out of the string literal that's forming the query, in order to have it evaluated as an int and stuffed into the string as "123456". It would be better to use a PreparedStatement though: ps = con.prepareStatement("select .... where code = ?");
ps.setInt(1, salsedCode[x]);
rs = ps.executeQuery(); -
I have 2 Tables
TABLE_NAME COLUMN_NAME DATA_TYPE
TASTEWINE TWDATE DATE
TASTEWINE BIN NUMBER
TASTEWINE QUANTITY NUMBER
TASTING TDATE DATE
TASTING PLACE VARCHAR2
a) Table TASTING has 2 columns.... TDATE( date Tasting was Held) and PLACE ( locations at which Tasting was held)
b) Table TASTEWINE has 3 Columns.............. TWDATE( wine tasting date, BIN( ID number for type of wine that was tasted), AND QUANTITY( quantity of win consumed by bottles)
Here is the QUestion.... I am having a hard time figuring out how to connect those two tables based on this information .. What I want to do is this.....select the total number of bottles of wine served at each wine-tasting, but only for the second half of the year 1999, and I want to see not only the date and total bottles served, but also the location where the wine-tasting took place. I also want to display the date, the place, and total quantity.
Can Anyone please Help me??Hi,
Your query works fine - as well as the one mentioned by Alok. I have tired it with some sample values, and both show the same results:-
The two tables :-
CREATE TABLE TASTEWINE
TWDATE DATE,
BIN NUMBER,
QUANTITY NUMBER
CREATE TABLE TASTING
TDATE DATE,
PLACE VARCHAR2(100)
);Rows in the Tables:-
INSERT INTO TASTEWINE VALUES (TO_DATE('01/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('02/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('03/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('04/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('05/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('06/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('07/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('08/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('09/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('10/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('11/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('12/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('01/12/2000','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('02/12/2000','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('03/12/2000','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('04/12/2000','MM/DD/YYYY'),1,100);
COMMIT;
INSERT INTO TASTING VALUES (TO_DATE('01/12/1999','MM/DD/YYYY'),'SEATTLE');
INSERT INTO TASTING VALUES (TO_DATE('02/12/1999','MM/DD/YYYY'),'SAN FRANSICO');
INSERT INTO TASTING VALUES (TO_DATE('03/12/1999','MM/DD/YYYY'),'DENVER');
INSERT INTO TASTING VALUES (TO_DATE('04/12/1999','MM/DD/YYYY'),'AUSTIN');
INSERT INTO TASTING VALUES (TO_DATE('05/12/1999','MM/DD/YYYY'),'SALT LAKE CITY');
INSERT INTO TASTING VALUES (TO_DATE('06/12/1999','MM/DD/YYYY'),'LOS ANGLES');
INSERT INTO TASTING VALUES (TO_DATE('07/12/1999','MM/DD/YYYY'),'PORTLAND');
INSERT INTO TASTING VALUES (TO_DATE('08/12/1999','MM/DD/YYYY'),'NEW YORK');
INSERT INTO TASTING VALUES (TO_DATE('09/12/1999','MM/DD/YYYY'),'NEWARK');
INSERT INTO TASTING VALUES (TO_DATE('10/12/1999','MM/DD/YYYY'),'EL PASO');
INSERT INTO TASTING VALUES (TO_DATE('11/12/1999','MM/DD/YYYY'),'AUSTIN');
INSERT INTO TASTING VALUES (TO_DATE('12/12/1999','MM/DD/YYYY'),'CHICAGO');
INSERT INTO TASTING VALUES (TO_DATE('01/12/2000','MM/DD/YYYY'),'ATLANTA');
INSERT INTO TASTING VALUES (TO_DATE('02/12/2000','MM/DD/YYYY'),'HOLLYWOOD');
INSERT INTO TASTING VALUES (TO_DATE('03/12/2000','MM/DD/YYYY'),'');
INSERT INTO TASTING VALUES (TO_DATE('04/12/2000','MM/DD/YYYY'),'SEATTLE');
COMMIT;The First Query :-
SELECT
A.TWDATE,
B.PLACE,
SUM(A.QUANTITY)
FROM
TASTEWINE A,
TASTING B
WHERE
A.TWDATE = B.TDATE
AND B.TDATE > TO_DATE('01/07/1999', 'DD/MM/YYYY')
AND B.TDATE < TO_DATE('01/01/2000', 'DD/MM/YYYY')
GROUP BY
A.TWDATE,
B.PLACE;The Second Query :-
SELECT
A.TWDATE,
B.PLACE,
SUM(A.QUANTITY)
FROM
TASTEWINE A,
TASTING B
WHERE
A.TWDATE = B.TDATE
AND B.TDATE
BETWEEN
TO_DATE('01/07/1999', 'DD/MM/YYYY') AND
TO_DATE('01/01/2000', 'DD/MM/YYYY')
GROUP BY
A.TWDATE,
B.PLACE;Regards,
Sandeep -
I want to submit a concurrent program from pl/sql. Please help me.
Dear all,
I want to submit a concurrent program from pl/sql. But I failed. Please help me.
Detail:
I create a concurrent program in 'Cash Management, Vision Operations (USA)' responsibility. <strong>And it be submitted success in EBS</strong>.
Then
I create a test script in pl/sql. And use 'FND_GLOBAL.APPS_INITIALIZE' to initialize ebs, then use 'FND_REQUEST.SUBMIT_REQUEST' to submit
the consurrent program, But the procedure aways return <strong>0</strong>.
I cannot found the reason. Please help me.Thanks.
<em>Attached informations may describe the problem:
1.The concurrenct submitted success in EBS.</em>
request_id = 4750655 (Sorry, I dont know how to add pictures.)
<em>2.The initialize informations which from SQL</em>.
SELECT FCR.REQUESTED_BY USER_ID
,FCR.RESPONSIBILITY_ID
,FCR.RESPONSIBILITY_APPLICATION_ID
,FA.APPLICATION_SHORT_NAME
,FCP.CONCURRENT_PROGRAM_NAME
FROM FND_CONCURRENT_REQUESTS FCR
,FND_APPLICATION FA
,FND_CONCURRENT_PROGRAMS FCP
WHERE FCR.PROGRAM_APPLICATION_ID = FA.APPLICATION_ID
AND FCR.CONCURRENT_PROGRAM_ID = FCP.CONCURRENT_PROGRAM_ID
AND FCR.REQUEST_ID = 4750655;
Result: user_id = 1318;
responsibility_id = 50579;
application_id = 260;
application_short_name = 'CE';
program_short_name = 'CALLK009';
<em>3.The test script code.</em>
<p>
-- Created on 2008/10/22 by ERIC
declare
-- Local variables here
Wv_conc_req_id VARCHAR2(10) DEFAULT NULL;
BEGIN
FND_GLOBAL.APPS_INITIALIZE(
1318
,50579
,260
Wv_conc_req_id := FND_REQUEST.SUBMIT_REQUEST(
'CE'
,'CALLK009'
,NULL
,SYSDATE
,FALSE
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
, CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
DBMS_OUTPUT.PUT_LINE(Wv_conc_req_id);
COMMIT;
end;
<em>4.The concurrent program code.</em>
create or replace package body CALLTEST is
PROCEDURE T1(PvO_errbuf OUT VARCHAR2
,PvO_retcode OUT VARCHAR2)
IS
BEGIN
FND_FILE.PUT_LINE(fnd_file.log, 'TEST');
END;
end CALLTEST;
</p>Can you check from which schema you are executing FND_REQUEST? You can try as follows;
Connect to your required schema, create a synonym on apps.fnd_request, connect from apps and finally execute grant all on apps.fnd_request to all.
You can check for relevance from Doc ID: Note:147495.1
Please do keep in the mind the soultion above should be applied to a test/dev EBS instance first.
I hope this would be of help.
Saad -
SQL question - please help!
Hi,
I am working on a SQL, please help ms with the question
below .... thanks
(1)Increase by 10% salary of these captain pilots who have
traveled more than 800,000 miles.
Routes | | Flights | |Pilots |
| | | | |
#routeID | | #flightNO | |#pilotID |
depAirportID | | airplaneNO| |*name |
arrAirportID |_______/| pilotID |\___________|*hours_in_air|
length | \| routeID |/ |*grade |
______________| |_____________| |*salary |
|____________|If the length column in routes is in hours, and it represents
additional hours to those shown in hours_in_air in pilots, then
the following should work:
UPDATE pilots
SET salary = salary * 1.1
WHERE pilotid in (SELECT a.pilotid
FROM pilots a,
(SELECT b.pilotid,sum(c.length) new_hours
FROM flights b, routes c
WHERE b.routeid = c.routeid
GROUP BY b.pilotid) d
WHERE a.pilotid = d.pilotid and
new_hours + hours_in_air >= 80000)I suspect that you probably need to add additional criteria to
the sub-query from flights and routes to take into account only
flights since the hours_in_air column from pilots was last
updated. However, your table structures do not indicate any
date sensitivity. If the table flights is emptied every time
hours_in_air is updated, then the query above will work. -
Passing parameter to a SQL query - Please help
Hi All,
I am new to JDBC. I have been trying to pass an external variable to an SQL Query.
The query is
String username1="le";
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '%?%'");
pstmt.setString(1, username1);
pstmt.executeQuery();
ResultSet rs = pstmt.getResultSet();
I am trying to retrieve values from the users table where the USER_NAME column value that is a String contains the supplied value username1.
I am using the question mark (?) character to pass the value from the variable username1. I am also using the '%' substitution character which matches for any number of characters. So, the above query should retrieve rows where the USER_NAME is something like "charles","leander","Elena" etc.( that contains "le")
I am getting the error:
SQLException: java.sql.SQLException: ORA-01006: bind variable does not exist
I changed the query to
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '% " + username1 + "%'");
//pstmt.setString(1, username1);
pstmt.executeQuery();
This time , it is not giving the error and retrieving properly.
But I want to use the original query and use the "pstmt.setString(1, username1); " . Is there any way of achieving this?
Please help.
Cheers,
charles_amhi,
try this...
String username1="%le%";
pstmt = c.prepareStatement("select * from users where USER_NAME like ?")
pstmt.setString(1,username1);
cheers,
rpk -
Hi experts,
what i want to do is write a single query which will show whether a employee
exits in the company or not.I have two tables emp and dept.There are as follows.
SQL> select * from emp;
NAME DEPTNO EMPNO
xxx 10 33036
YYY 12 2345
ZZZ 13 678
KKK 14 5678
RRR 15 7865
SQL> select * from dept;
DEPTNO LOCATION
10 AAA
11 BBB
12 CCC
13 DDD
what i want is it will select records from the emp table and find whether corrosponding
deptno really exists in the dept table.If the value is found in deptno column the dept table then it will set the value
Y other wise it will be N and all i have to do with the help of a single query.
expected result
name empno exists
xxx 33036 Y
YYY 2345 Y
ZZZ 678 Y
KKK 5678 N
RRR 7865 N
Please help.
Regards
RajatSELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST
FROM EMP
ORDER BY 1
Demo
SQL> WITH EMP AS(
2 SELECT 'XXX' NAME , 10 DEPTNO ,33036 EMPNO FROM DUAL UNION
3 SELECT 'YYY', 12, 2345 FROM DUAL UNION
4 SELECT 'ZZZ', 13 ,678 FROM DUAL UNION
5 SELECT 'KKK', 14 ,5678 FROM DUAL UNION
6 SELECT 'RRR', 15 ,7865 FROM DUAL ),
7 DEPT AS(
8 SELECT 10 DEPTNO,'AAA' DNAME FROM DUAL UNION
9 SELECT 11 ,'BBB' FROM DUAL UNION
10 SELECT 12 ,'CCC' FROM DUAL UNION
11 SELECT 13 ,'DDD'FROM DUAL )
12 SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N')
EXIST
13 FROM EMP
14 ORDER BY 1
15 /
EMPNO NAM EMPNO E
678 ZZZ 678 Y
2345 YYY 2345 Y
5678 KKK 5678 N
7865 RRR 7865 N
33036 XXX 33036 Y
SQL> Edited by: Salim Chelabi on Dec 7, 2008 4:15 AM -
Table1
QTE_ID SEQ_NO
1435177 2
1435177 5
1435177 7
1435177 8
1435177 12
1435177 14
Table2
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 1 98500
1435177 2 98500
1435177 3 0
1435177 4 98500
1435177 5 98500
1435177 7 98500
1435177 8 98500
1435177 11 59300
1435177 12 59300
1435177 14 59300
The result should be
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 2 0 (where 0 = cmmt_curr_amt of seq 2 - cmmt_curr_amt of seq 1 from table 2)
1435177 5 0 (where 0 = cmmt_curr_amt of seq 5 - cmmt_curr_amt of seq 4 from table 2)
1435177 7 0 (where 0 = cmmt_curr_amt of seq 7 - cmmt_curr_amt of seq 5 from table 2)
1435177 8 0 (where 0 = cmmt_curr_amt of seq 8 - cmmt_curr_amt of seq 7 from table 2)
1435177 12 0 (where 0 = cmmt_curr_amt of seq 12 - cmmt_curr_amt of seq 11 from table 2)
1435177 14 0 (where 0 = cmmt_curr_amt of seq 14 - cmmt_curr_amt of seq 12 from table 2)
I have to get the difference of cmmt_curr_amt from the table2 from seq 14 to seq 12 for seq14 in table 1.
Please help me in writing the query.
Thanks in advance.
SrinivasWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
Cluster bar chart- sql query please help-
Hi,
I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
Here is my table
city region issue value
c1 north i1 y
c1 north i2 y
c2 north i1 n
c2 north i2 y
c3 south i1 y
c3 south i2 n
c4 east i1 n
c4 east i2 n
The bar chart will have 3 series, north south and east.
And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
How can I get something like this from the above table-
region issue count(yes)
north i1 1
north i2 2
south i1 1
south i2 0
east i1 0
east i2 0
thanksWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
I can't figure out how to parametrize my SQL statement - lil help please?
Hi all,
I was deleting records via the string-concatenation method, which I've come to understand is bad, due to security any possibly other issue. I want very much to parametrize my delete statement, but I just can't see to get it to work
The code below is my best shot at it - it returns an Oracle exception about "invalid table name". I assume that means the the substitution of the parameter for the value simply hasn't been performed, so the database is trying to process literally ":oracleTable", and the like.
Can someone please set me straight with this?
Thanks for any help,
cdj
public static void DeleteTest(DateTime start, DateTime end)
ParentFormStatusBar.Text = "Deleting records...";
string oracleStart = start.ToString("dd-MMM-yyyy");
string oracleEnd = end.ToString("dd-MMM-yyyy");
string strConn = "CONNECTSTRING";
OracleConnection dc_UAT = new OracleConnection(strConn);
string oracleTable = "DATABASETABLE";
OracleCommand oc = new OracleCommand();
oc.BindByName = true;
oc.CommandText = "delete from :oracleTable where as_of_date between :oracleStart and :oracleEnd";
oc.Connection = dc_UAT;
OracleParameter tableParam = new OracleParameter();
tableParam.ParameterName = "oracleTable";
tableParam.Value = oracleTable;
tableParam.OracleDbType = OracleDbType.Varchar2;
tableParam.Direction = ParameterDirection.Input;
OracleParameter startParam = new OracleParameter();
startParam.ParameterName = "oracleStart";
startParam.Value = start;
startParam.OracleDbType = OracleDbType.Date;
startParam.Direction = ParameterDirection.Input;
OracleParameter endParam = new OracleParameter();
endParam.ParameterName = "oracleEnd";
endParam.Value = end;
endParam.OracleDbType = OracleDbType.Date;
endParam.Direction = ParameterDirection.Input;
oc.Parameters.Add(tableParam);
oc.Parameters.Add(startParam);
oc.Parameters.Add(endParam);
MessageBox.Show(tableParam.Value.ToString()+ "\n" + oc.CommandText+"\n" + "Params: " + oc.Parameters.Count);
int rowsAffected;
try
dc_UAT.Open();
rowsAffected = oc.ExecuteNonQuery();
dc_UAT.Close();
ParentFormStatusBar.Text = rowsAffected.ToString() + " records deleted.";
catch(Exception ex)
ParentFormStatusBar.Text = "Delete error: " + ex.Message;
}It helped oodles - thanks a jillion!
Is there a master list somewhere of things you can and cannot parametrize? That would be cool.
I guess I was thinking of parameters oversimplistically as just a canned-search-and-replace-text function or something like that.
Thanks again,
cdj -
Invalid call Statement method: {0} In sql server,please help me!
Connect to a sql server 2000 DB,and the table has a identity column.
Run the code below:
String strSql = "insert into attachments([FileName],FileLength,FileContent) values(?,?,?)";
PreparedStatement pstmt = connection.prepareStatement(strSql);
pstmt.setString(1,fileName);
pstmt.setInt(2,iFileLength);
pstmt.setString(3,'aaaa');
if(pstmt.executeUpdate()==1) {//succeed;
strSql = "select @@identity";//this code run good in the Query Analyzer.
ResultSet rs = pstmt.executeQuery(strSql);//exception thrown!!!!!!!!!!!!
if(rs.next()) {//succeed;
int i = rs.getInt(1);
throw a exception:Invalid call Statement method: {0}
thanks a lot!If you really must re-use your prepared statement, then you'll have to clear the parameters associated with it.
pstmt.clearParameters();What's happening is that the statement is trying to re-apply the previously assigned parameters to a query with no placeholders.
I'd rather use an ordinary Statement in this case.
Dave -
SQL LOADER ;;; PLEASE HELP ME
Hi EveryBody,
I have useless lines in my file csv which I do not want to load in my Oracle table,
1- some one knows a means to leave the control file of SQL LOADER to load that the data which I want?
2- Another thing I want to insert my lines in the file
csv that under a condition that the sum of the lines
of a column amount in the file csv is different than 0 ?
for example:
date|amount |Currency
2006-05-19 18:35:53|12.74|Euro
2006-05-19 18:35:53|23.24|CAD
Thanks,
Regards,Executing this script :
CREATE TABLE admin_ext_emmanuel
(NUMS VARCHAR2(200) ,
NB_UNIT NUMBER ,
REVENUE NUMBER
ORGANIZATION EXTERNAL
TYPE ORACLE_LOADER
DEFAULT DIRECTORY admin_dat_dir
ACCESS PARAMETERS
records delimited by newline
badfile admin_bad_dir:'emmanuel%a_%p.bad'
logfile admin_log_dir:'emmanuel%a_%p.log'
fields terminated by ';'
missing field values are null
( employee_id, first_name, last_name, job_id, manager_id,
hire_date char date_format date mask "dd-mon-yyyy",
salary, commission_pct, department_id, email
LOCATION ('20060619_emmanuel_01.csv')
PARALLEL
REJECT LIMIT UNLIMITED
I have these errors :
ORA-29913 : error in executing ODCIEXTTABLEOPEN callout
ORA-29400 : data catridge error
KUP-04043 : table column not found in external source : NUMS
ORA-06512 : at "SYS.ORACLE_LOADER" , line 19
can u help please? -
Control Break Statements ----- Please Help me
I have some idea about the control-break statements(AT-ENDAT). Can any one please give me the example ?
Thanks in Advance. Points will be rewarded immediately.sample program for AT events
Using AT FIRST , AT NEW, AT THE END OF , AT LAST.
DATA: BEGIN OF ITAB OCCURS 0,
F1 TYPE I,
F2(6) TYPE C,
F3(10) TYPE N,
F4(16) TYPE P DECIMALS 2,
END OF ITAB.
DATA: SUB_TOT(10) TYPE P DECIMALS 3.
**--1
ITAB-F1 = 1.
ITAB-F2 = 'ONE'.
ITAB-F3 = 10.
ITAB-F4 = '1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 1.
ITAB-F2 = 'ONE'.
ITAB-F3 = 20.
ITAB-F4 = '2000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 1.
ITAB-F2 = 'ONE'.
ITAB-F3 = 30.
ITAB-F4 = '3000.00'.
APPEND ITAB.
CLEAR ITAB.
*--2
ITAB-F1 = 2.
ITAB-F2 = 'TWO'.
ITAB-F3 = 10.
ITAB-F4 = '1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 2.
ITAB-F2 = 'TWO'.
ITAB-F3 = 20.
ITAB-F4 = '2000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 3.
ITAB-F2 = 'THREE'.
ITAB-F3 = 10.
ITAB-F4 = '1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = 3.
ITAB-F2 = 'THREE'.
ITAB-F3 = 20.
ITAB-F4 = '2000.00'.
APPEND ITAB.
CLEAR ITAB.
SORT ITAB BY F1.
LOOP AT ITAB.
AT FIRST.
WRITE: /35 ' MATERIAL DETAILS:'.
ULINE.
ENDAT.
AT NEW F1.
WRITE: / 'DETAILS OF MATERIAL:' COLOR 7 , ITAB-F1.
ULINE.
ENDAT.
WRITE: / ITAB-F1, ITAB-F2, ITAB-F3, ITAB-F4.
SUB_TOT = SUB_TOT + ITAB-F4.
AT END OF F1.
ULINE.
WRITE: / 'SUB TOTAL :' COLOR 3 INVERSE ON, SUB_TOT COLOR 3 INVERSE ON.
CLEAR SUB_TOT.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: 'SUM:', ITAB-F4.
ULINE.
ENDAT.
ENDLOOP.
Reward points if helpful.
Rgds,
Abhishek -
Sms in enroute state please help
hi all,
From an ESME we are sending sms through smpp and the client code gets the smsc ok response still its not able to deliver the message for a long time and some times it dont even deliver the sms .We tried with the different sending priorities like min norm high ,still the issue is not closed .While enquiring it says that the message is in enroute state.Upto my understanding the problem is in SMSC, but still they are not able to trap it out. If anybody worked with an smsc server can help us atleast which would be great. If the posted info is not enough i will give more info as u need.Hope I will get help
Thanks in advance.Hi,
I used 2 programs with smpp 3.4 spec to test the submit function of the test class in smppapi. I made 2 queries with their messageid and found the followings:
Success: Query response (query_resp: (pdu: 44 80000003 0 3) 4651A8CA 040820032314032+ 2 0 )
Failure: Query response (query_resp: (pdu: 28 80000003 0 3) 610CBF1E 1 0 )
May I ask what reasons will cause that failure of sending a SMS? '1' seems the enroute state.
Thanks
Maybe you are looking for
-
Error while importing Still image.
I searched the data base and found a similar question but it wasn't answered. I'm running PE 10 on a Mac (O S 10.6.8) with 4GB of RAM and lots of disk space. First attempt importing a stitched photo (panorama) from LR3 as a .TIF; got this error messa
-
Sharing library across subnets
Hello, I am sharing my iTunes library for myself and would like to be able to listen to my music while on campus away from my main computer. I have set up all the firewall ports on both machines. Basically my question is if my main machine is at IP 1
-
Input should accept only alphabets(validation)
Hi I have a input field with label EMPLOYEE NAME where it should accept only alphabets spacesand dot(.)For example(k.krishna rao). Thanks Krishna
-
Query for invoice and distribution detail
hi 2 all anybody have the query for getting invoice with distribution detail in oracle payable r12. thanks zulqarnain
-
Hi, I have a class that has two private variables: private String tableName; private Vector iffields; The vector is supposed to be filled with objects of another class called DIFField. How can I write a method that adds DIFFields to this iffields Vec