Giving START WITH dynamically in a query

Hi,
How do you specify the value in START WITH dynamically during runtime.
For example please consider the bewlo scenario:
CREATE TABLE ISCT
ITEM_NO VARCHAR2(15 CHAR) NOT NULL,
ITEM_TYPE VARCHAR2(3 CHAR) NOT NULL,
ITEM_TYPE_SCO VARCHAR2(3 CHAR) NOT NULL,
ITEM_NO_SCO VARCHAR2(15 CHAR) NOT NULL,
ARTSAL_SEQ_PRIO NUMBER(3) NOT NULL,
ART_SCO_QTY NUMBER(6,3) NOT NULL,
ITEM_SEQ_PRIO NUMBER(3),
PCKL_SEQ_PRIO NUMBER(3),
REG_DATE DATE NOT NULL,
UPD_DATE DATE NOT NULL,
DELETE_DATE DATE,
USER_NO_CHG VARCHAR2(7 CHAR) NOT NULL
CREATE TABLE ICONT
ITEM_TYPE VARCHAR2(3 CHAR) NOT NULL,
ITEM_NO VARCHAR2(15 CHAR) NOT NULL,
ITEM_TYPE_CHILD VARCHAR2(3 CHAR) NOT NULL,
ITEM_NO_CHILD VARCHAR2(15 CHAR) NOT NULL,
ITEM_QTY_CHILD NUMBER(5) NOT NULL,
REG_DATE DATE NOT NULL,
UPD_DATE DATE NOT NULL,
DELETE_DATE DATE,
II_DATE DATE NOT NULL,
IU_DATE DATE NOT NULL,
SORT_NO NUMBER(5)
Now inserting rows:
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('15795', 'CCI', 'SCI', '00245905', 25,
1, NULL, NULL, TO_DATE('10/03/2009 15:40:01', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('00245781', 'SCI', 'SCI', '00245905', 1,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('80067553', 'ART', 'SCI', '00245905', 2,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('84178910', 'ART', 'SCI', '00245905', 3,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('70132375', 'ART', 'SCI', '00245905', 4,
8, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('30067555', 'ART', 'SCI', '00245905', 5,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('50067559', 'ART', 'SCI', '00245905', 6,
5, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('14278710', 'ART', 'SCI', '00245905', 7,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('00130092', 'ART', 'SCI', '00245905', 8,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('10110159', 'ART', 'SCI', '00245905', 9,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('30124693', 'ART', 'SCI', '00245905', 10,
4, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('80130093', 'ART', 'SCI', '00245905', 11,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('90110155', 'ART', 'SCI', '00245905', 12,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('60035916', 'ART', 'SCI', '00245905', 13,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('54249810', 'ART', 'SCI', '00245905', 14,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('14180110', 'ART', 'SCI', '00245905', 15,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('97872010', 'ART', 'SCI', '00245905', 16,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('34180010', 'ART', 'SCI', '00245905', 17,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('57871710', 'ART', 'SCI', '00245905', 18,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('40067588', 'ART', 'SCI', '00245905', 19,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('00067590', 'ART', 'SCI', '00245905', 20,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('80067586', 'ART', 'SCI', '00245905', 21,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('20145196', 'ART', 'SCI', '00245905', 22,
2, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('00067585', 'ART', 'SCI', '00245905', 23,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('80124087', 'ART', 'SCI', '00245905', 24,
1, NULL, 1, TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/03/2009 15:46:04', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1008920');
Insert into isct
(ITEM_NO, ITEM_TYPE, ITEM_TYPE_SCO, ITEM_NO_SCO, ARTSAL_SEQ_PRIO,
ART_SCO_QTY, ITEM_SEQ_PRIO, PCKL_SEQ_PRIO, REG_DATE, UPD_DATE,
DELETE_DATE, USER_NO_CHG)
Values
('39809661', 'SPR', 'SCI', '00245781', 1,
1, 1, 1, TO_DATE('10/04/2009 15:24:22', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/04/2009 15:24:22', 'MM/DD/YYYY HH24:MI:SS'),
NULL, '1007193');
Insert into icont (ITEM_TYPE,ITEM_NO,ITEM_TYPE_CHILD,ITEM_NO_CHILD,ITEM_QTY_CHILD,REG_DATE,UPD_DATE,DELETE_DATE,II_DATE,IU_DATE,SORT_NO) values ('SPR','39809661','ART','44178610',1,to_timestamp('23-FEB-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('23-FEB-07','DD-MON-RR HH24.MI.SSXFF'),null,to_timestamp('15-NOV-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('20-DEC-07','DD-MON-RR HH24.MI.SSXFF'),2);
Insert into icont (ITEM_TYPE,ITEM_NO,ITEM_TYPE_CHILD,ITEM_NO_CHILD,ITEM_QTY_CHILD,REG_DATE,UPD_DATE,DELETE_DATE,II_DATE,IU_DATE,SORT_NO) values ('SPR','39809661','ART','70132375',1,to_timestamp('06-SEP-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('06-SEP-07','DD-MON-RR HH24.MI.SSXFF'),null,to_timestamp('15-NOV-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('20-DEC-07','DD-MON-RR HH24.MI.SSXFF'),4);
Insert into icont (ITEM_TYPE,ITEM_NO,ITEM_TYPE_CHILD,ITEM_NO_CHILD,ITEM_QTY_CHILD,REG_DATE,UPD_DATE,DELETE_DATE,II_DATE,IU_DATE,SORT_NO) values ('SPR','39809661','ART','74249710',1,to_timestamp('23-FEB-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('23-FEB-07','DD-MON-RR HH24.MI.SSXFF'),null,to_timestamp('15-NOV-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('20-DEC-07','DD-MON-RR HH24.MI.SSXFF'),3);
Insert into icont (ITEM_TYPE,ITEM_NO,ITEM_TYPE_CHILD,ITEM_NO_CHILD,ITEM_QTY_CHILD,REG_DATE,UPD_DATE,DELETE_DATE,II_DATE,IU_DATE,SORT_NO) values ('SPR','39809661','ART','80067553',1,to_timestamp('23-FEB-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('23-FEB-07','DD-MON-RR HH24.MI.SSXFF'),null,to_timestamp('15-NOV-07','DD-MON-RR HH24.MI.SSXFF'),to_timestamp('20-DEC-07','DD-MON-RR HH24.MI.SSXFF'),1);
COMMIT;
Now if you create a view:
create or replace view test_v
(ITEM_NO, ITEM_TYPE, ITEM_NO_SCO,ITEM_TYPE_SCO)
as
SELECT T.ITEM_NO, T.ITEM_TYPE, CONNECT_BY_ROOT T.ITEM_NO_SCO,T.ITEM_TYPE_SCO
FROM
SELECT NVL(C.ITEM_NO_CHILD, I.ITEM_NO) ITEM_NO, NVL(C.ITEM_TYPE_CHILD, I.ITEM_TYPE) ITEM_TYPE, I.ITEM_TYPE_SCO, I.ITEM_NO_SCO
FROM isct I,
icont C
WHERE I.ITEM_NO = C.ITEM_NO(+)
AND I.ITEM_TYPE = C.ITEM_TYPE(+)
) T
CONNECT BY PRIOR T.ITEM_NO = T.ITEM_NO_SCO AND PRIOR T.ITEM_TYPE = T.ITEM_TYPE_SCO;
Then run the below query:
select * from test_v where item_no_sco = '00245905'
the output is got within a second. but the real scenario is that both table icont and isct have millions of rows. In that case even this small query of the view takes 10minutes as there a FULL TABLE JOIN.
How do I give the START WITH in the view to make it faster i.e.
even with millions of rows the output of this comes in seconds:
SELECT T.ITEM_NO, T.ITEM_TYPE, CONNECT_BY_ROOT T.ITEM_NO_SCO,T.ITEM_TYPE_SCO
FROM
SELECT NVL(C.ITEM_NO_CHILD, I.ITEM_NO) ITEM_NO, NVL(C.ITEM_TYPE_CHILD, I.ITEM_TYPE) ITEM_TYPE, I.ITEM_TYPE_SCO, I.ITEM_NO_SCO
FROM isct I,
icont C
WHERE I.ITEM_NO = C.ITEM_NO(+)
AND I.ITEM_TYPE = C.ITEM_TYPE(+)
) T
START WITH T.ITEM_NO_SCO = '00245905'
CONNECT BY PRIOR T.ITEM_NO = T.ITEM_NO_SCO AND PRIOR T.ITEM_TYPE = T.ITEM_TYPE_SCO;
I want to summarize the above the post, you can use START WITH in a stand alone query, in a function etc. But how do you use it in a VIEW?
Thanks,
Vikram

user12004283 wrote:
Hi,
Thanks for the quick replies.
I was more looking for a solution with only SQL i.e I dont want to go for any package or outside variable.
Isn't there a way to achieve this through advanced SQL?
Also why when I create a join in a query having connect by without start with it does a full table scan of the joined table, isnt there a better way to create a join, I mean there is no need to run the whole view at a time, it would be run with a input but why isnt the connect by using to input as a START WITH!
Thanks,
VikramBut the solution is "only SQL", that you have to initialize a variable doesn't change that fact.
If you absolutely can't make that solution work, you could code this in DYNAMIC SQL, but that would much more 'bad' than the suggested implementation.
Why exactly do you need a view at all for this?
SELECT
  NVL(C.ITEM_NO_CHILD, I.ITEM_NO)     as ITEM_NO,
  NVL(C.ITEM_TYPE_CHILD, I.ITEM_TYPE) as ITEM_TYPE,
  CONNECT_BY_ROOT I.ITEM_NO_SCO       as ITEM_NO_SCO,
  I.ITEM_TYPE_SCO 
FROM  isct  I,
      icont C
WHERE I.ITEM_NO = C.ITEM_NO(+)
AND I.ITEM_TYPE = C.ITEM_TYPE(+)
start with I.ITEM_NO_SCO = :YOUR_BIND_VARIABLE
CONNECT BY PRIOR I.ITEM_NO = I.ITEM_NO_SCO AND PRIOR I.ITEM_TYPE = I.ITEM_TYPE_SCO;Is about as simple as it gets, no need for a view ... no need for anything flashy. What is your justification behind 'needing' a view for this?

Similar Messages

  • Adding dynamic 'start with' clause in Hierarchial query in Discoverer 4i

    I have created a custom folder based upon the following hierarchial guery:
    SELECT supervisor_name, level
    FROM xxhr084_hr_emps_v
    START WITH supervisor_name = 'TEST SUPER'
    CONNECT BY prior person_id = supervisor_id
    ORDER SIBLINGS by supervisor_name
    I want the 'START WITH' value to be based upon a parameter i.e. the User enters the value of supervisor name at runtime.
    However, I can't use a parameter within the custom folder and I can't generate the 'start with' condition in my workbook.
    Anyone have a solution for populating the start with clause at run-time?
    Thanks,
    Kevin

    Can you create the custom folder without a condition on supervisor_name - i.e. without the supervisor_name = 'X' starts with clause - in the EUL, and then define the condition on the supervisor_name field within the report?
    SELECT supervisor_name, level
    FROM xxhr084_hr_emps_v
    CONNECT BY prior person_id = supervisor_id
    ORDER SIBLINGS by supervisor_name
    You can then restrict the results that the hierarchical query returns (from the custom folder) within the report, by adding a condition on supervisor_name.
    Hope that makes some sense.

  • Start with Advanced mode in Query Panel

    JDev 11.1.1.5.0 ADF BC
    I have a query panel in my form with table made from View Criteria.
    When runs, it starts with Basic mode.
    I want this to be changed to start with Advanced mode straight away.
    Is that possible?

    Hi,
    Edit the ViewCriteria. In the UI Hints tab set Search Region Mode to Advanced.
    Kevin
    Message was edited by: KevinAngus - you beat me Timo!

  • How do I get Started with Dynamic Web Pages?

    I am presently following Janine Warner's Dreamweaver CS3  video series.  I noted that the Advanced part of this tutorial series focuses on Dynamic Web Pages, but only uses Cold Fusion.  From what I can gather, CF costs around $1000, while PHP is free!  My question is really this: in going from static to dynamic web design I'M A COMPLETE NEWBIE, so what do I need?   I am doing some planning here -- I know it won't happen overnight.
    (BTW:  I was surprised to discover that CF is NOT included in my CS3 Master Collection).  It might appear then that support for PHP is better than for CF?
    Apparently, I need a server -- well, OK I have PCs to spare.  Fast internet, I also have: Comcast standard -- 12MP
    Now, I think I also need Apache -- which apparently runs on the server and does something.
    So then I DL PHP, figure out how it works, and it will integrate with DW CS3 in some way.
    Now, what have I missed?  Is there some really basic, first-time-with-using-a-server place or tut I should go to or read?  Before you ask: No, I'm doing all this myself on a shoestring budget.
    Are there expensive hosting fees for dynamic web sites or other items I will run into?  Can I just use a PC over my Comcast cable as the server run from my home?  (Really high traffic is not anticipated)
    All recommendations appreciated, thanks.
    Thom

    Many of these questions have already been answered in your thread in the Dreamweaver General Discussion forum, so I'll just stick to a few basics.
    You need a server whichever server-side technology you choose, but "server" is not a physical machine, but a piece of software that you install on your development computer. You'll find details of how to install a PHP environment in the following article: http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php.html.
    Similar instructions are available for setting up a ColdFusion server at http://www.adobe.com/devnet/dreamweaver/articles/setting_up_coldfusion.html. The article is for ColdFusion 8, but ColdFusion 9 is installed in exactly the same way.
    Hosting for PHP/MySQL is plentiful and relatively cheap. However, make sure the hosting company offers a minimum of PHP 5.2 and MySQL 5.1. Hosting for CF is harder to find and tends to be a bit more expensive, but not prohibitively so.

  • Value of the start in the Select with in a Hierarchical Query

    Exist any way for put in the select the value of the start with in a Hierarchical Query?
    An example:
    I'll need sth like
    CTH@> select n code, level, np code_parent, 1 code_first_parent
    2 from demo
    3 start with n=1
    4 connect by np = prior n
    5 ;
    CODE LEVEL CODE_PARENT CODE_FIRST_PARENT
    1 1 1
    2 2 1 1
    3 3 2 1
    4 4 3 1
    5 5 4 1
    6 6 5 1
    7 7 6 1
    8 8 7 1
    9 9 8 1
    10 10 9 1
    -- Naturally it couldn´t be a constant value
    The query
    select n,d, level nivel
    , np, prior n
    from demo
    start with n=1
    connect by np = prior n
    --Table and inserts
    create table demo
    ( n number,
    d varchar2(5),
    np number);
    insert into demo values (1,'A', null);
    insert into demo values (2,'B',1);
    insert into demo values (3,'C',2);
    insert into demo values (4,'D',3);
    insert into demo values (5,'E',4);
    insert into demo values (6,'F',5);
    insert into demo values (7,'G',6);
    insert into demo values (8,'H',7);
    insert into demo values (9,'I',8);
    insert into demo values (10,'J',9);
    insert into demo values (11,'K', null);
    insert into demo values (12,'L',11);
    insert into demo values (13,'M',12);
    insert into demo values (14,'N',13);
    insert into demo values (15,'O',14);
    insert into demo values (16,'P',15);
    Message was edited by:
    cth

    On 10g
    connect_by_root(n)Best regards
    Maxim

  • Hierarchy query with dynamic start condition

    Hi,
    I have a table that stores hierarchical items (foohierarchy) and another one storing users and such items (useritems). Unfortunately the latter one is not consistent and misses some entries. I would like to fix that using pure sql. Fixing here means that a user that possesses a certain child element should also have parents of that child. There are a couple of obstacles here though. First the hierarchy table does not explicitly state which elements are top level elements. I am trying to fix that by emulating a proper structure and named that fixedhierarchy. A select statement that returns all intended user/item relationships would be nice.
    Here some visualization and sample data, the sample data follows the pattern that each item uses its level as its suffix, but this shouldn't be exploited in the statement:
    asci art:
    -- A1 (peter,paul)
    --   \_ B2
    --   \_ C2
    --        \_D3 (thomas)
    --            \_X4
    -- E1
    --   \_F2
    -- G1
    --   \_H2 (heidi)sample data
    drop table foohierarchy;
    drop table useritems;
    create table foohierarchy (
    child_item varchar2(30),
    parent_item varchar2(30));
    insert into foohierarchy values ('B2','A1');
    insert into foohierarchy values ('C2','A1');
    insert into foohierarchy values ('D3','C2');
    insert into foohierarchy values ('X4','D3');
    insert into foohierarchy values ('F2','E1');
    insert into foohierarchy values ('H2','G1');
    create table useritems (
    username varchar2 (40),
    item varchar2(30)
    insert into useritems values ('peter','A1');
    insert into useritems values ('paul','A1');
    insert into useritems values ('thomas','D3');
    insert into useritems values ('heidi','H2');
    commit;my attempt at fixing the hierarchy table
    with fixedhierarchy as
    (select parent_item,child_item from foohierarchy
    union all
    select distinct null parent_item,parent_item child_item from foohierarchy where parent_item not in (select child_item from foohierarchy))
    select * from fixedhierarchy;What the select should return:
    'peter'|'A1'
    'paul'|'A1'
    'thomas'|'A1'
    'thomas'|'C2'
    'thomas'|'D3'
    'heidi'|'G1'
    'heidi'|'H2'

    Hi,
    Thanks for posting the CREATE TABLE and INSERT statments; that's very helpful! Don't forget to mention what version of Oracle you're using. That's especially important with hierachies; every version since Oracle 7 has had significant improvements in how to handle them.
    I'm a little comfused as to what you want. Are you trying to permanently change the tables? If so, show what the changed table(s) should look like when the job is finished. Post the output you would want to see from "SELECT * FROM useritems;" or "SELECT * FROM foohierarchy;", or, if you want to change both tables, from both.
    It looks like you have two separate problems:
    (1) Changing foohierarchy, so that every item appears once as a child_id. That means adding rows with NULL parent_item for all the roots ('A1', 'E1' and 'G1'). The query you posted seems directed toward this.
    (2) Denormalizing useritems, so that when a username is linked to an item, the username is linked to all that item's ancestors, too. The results you posted seem to be what you want useritems to look like after this is done.
    Here's how to do those things:
    <h4>(1) Changing foohierarchy</h4>
    The query you posted looks good. Do you see anything wrong with it? You can use that query (or something very close to it) in an INSERT or MERGE statement.
    If you just want to add some new rows to foohierarchy, then you don't need the UNION: just the second branch of it. If you're cvertain that none of those rows already exist in foohierarchy, then
    INSERT INTO foohierarchy (parent_item,      child_item)
         SELECT DISTINCT   NULL,          childitem
         FROM     foohierarchy
         WHERE     parent_item     NOT IN (
                             SELECT      child_item
                             FROM     foohierarchy
    ;If some of the roots might already be in foohierarchy correctly, then you'll want a something in the WHERE clause to make sure you don';t add a duplicate. A MERGE statment might do this better than INSERT.
    <h4>(2) Denormalizing useritems</h4>
    This adds new rows to useritems, to make it look like what you posted:
    ERGE INTO     useritems     dst
    USING (
         WITH     all_ancestors     AS
              SELECT     CONNECT_BY_ROOT child_item     AS descendant
              ,     parent_item               AS ancestor
              FROM     foohierarchy
              START WITH     child_item   IN     (
                                       SELECT     item
                                       FROM     useritems
              CONNECT BY     child_item   = PRIOR parent_item
         SELECT DISTINCT
              u.username
         ,     a.ancestor
         FROM     all_ancestors     a
         JOIN     useritems     u  ON     a.descendant     = u.item
          )                    src
    ON     (     src.username     = dst.username
         AND     src.ancestor     = dst.item
    WHEN NOT MATCHED THEN
         INSERT     (dst.username,     dst.item)
         VALUES     (src.username,     src.ancestor)
    ;After doing this, "SELECT * FROM useritems;" will produce this output:
    USERNAME   ITEM
    paul       A1
    peter      A1
    thomas     A1
    thomas     C2
    thomas     D3
    heidi      G1
    heidi      H2Here's how it works:
    Sub-query all_ancestors is a bottom-up CONNECT BY query, linking each node in useritems with all of its ancestors. CONNECT BY queries are often slow under the best circumstances; doing a join in a CONNECT BY query makes it even slower. It's more efficient to do the CONNECT BY query first, in a sub-query, and then join tht result set to other tables, as I did in src.

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • Running a SQL Stored Procedure from Power Query with Dynamic Parameters

    Hi,
    I want to execute a stored procedure from Power Query with dynamic parameters.
    In normal process, query will look like below in Power Query. Here the value 'Dileep' is passed as a parameter value to SP.
        Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData 'Dileep'"]
    Now I want to pass the value dynamically taking from excel sheet. I can get the required excel cell value in a variable but unable to pass it to query.
        Name_Parameter = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
        Name_Value = Name_Parameter{0}[Value],
    I have tried like below but it is not working.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData Name_Value"]
    Can anyone please help me with this issue.
    Thanks
    Dileep

    Hi,
    I got it. Below is the correct syntax.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData '" & Name_Value & "'"]
    Thanks
    Dileep

  • Creating Query with dynamic columns to show results

    Hi experts,
    I need to know how to create a query with dynamic columns. Meaning, I don't want to create a query with fixed columns representing the 12 periods of the fiscal year to show me actuals as the fiscal year proceeds.
    For example, if I am currently in the middle of period 3 (March) of a fiscal year, when I execute the query, I need it to automatically only show me the 'Actuals' for periods 1 and 2, without seeing the columns from periods 3 to 12 showing blank.
    Then when I am in the middle period 5 (May) the query should ONLY show me the columns for periods 1 to 4 'Actuals', no results should be shown for periods 5 to 12 yet, and I don't want to even see blank columns for period 6 to 12.
    How do I define my columns, to achieve this.
    Maximum points will be awarded.
    Thanks Everyone.

    Hi Josh,
    I'm having a little difficuluty understanding what should be included in my restricted key figures.
    The time characteristics that I have available to use are:
    0FISCPER3 (posting period)
    0FISCYEAR (fiscal year), currently using SAP EXIT to default current fiscal year.
    0FISCVARNT (fiscal year variant).
    In addition, I have the following characteristics available to be used in the columns:
    Value type (10)
    version (currently I'm using variable for it)
    Currency type (020)
    Currency (USD).
    Can you explain what my restricted key figure should be based on and how it should look.
    I tried to create a restircted key figure using 0AMOUNT, and 0FISCPER3. For 0FISCPER3  I created a range from 1 to previous period (using SAP EXIT that supplied previous period).I also had value type, version, currency type, and currency included in that restricted key figure.Then when I tried to drag 0FISCPER3 under the restricted key figure once again, it wouldn't let me, probably because I've already used 0FISCPER3 in the restricted key figure.
    Please let me know if my explanation is not clear.
    Your step by step help would be great.
    Thanks
    Edited by: Ehab Mansour on Sep 23, 2008 2:40 PM

  • Question when I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    Question
    when I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    See this. <br />
    https://support.mozilla.com/en-US/kb/Firefox+hangs#Hang_at_exit

  • When I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    Question
    When I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    See this. <br />
    https://support.mozilla.com/en-US/kb/Firefox+hangs#Hang_at_exit

  • Absolute dynamic select query with dynamic join and where

    Has anyone ever tried creating an absolutely dynamic SELECT query with dynamic Join and Where conditions.
    I have a requirement of creating such a query in an Utility Class, and i have written the code. But its throwing my sysntax errors.
    Please let me know where am I going wrong OR is it really possible to create such a dynamic Query??
        SELECT (FIELDS) INTO TABLE IT_TABLES
          FROM ( (ME->TABLE1)  inner join ( me->table2 )
          on ( on_condition ) )
          WHERE (me->where_fields).
    Ags.

    It worked for me in a following way:
    select * into corresponding fields of table <result_table>
            from (join_string)
            where (l_where).
    Where the contents of join_string were dynamically build using concatenation. So it will be something like
    concatenate ME->TABLE1 'as a INNER JOIN' me->table2 'as b ON (' into join_string separated by space.
    <...>
    add here matching/reference colums, something like
    concatenate 'a~' me->TABLE1_JOIN_COL into temp1.
    concatenate 'b~' me->TABLE2_JOIN_COL into temp2.
    concatenate join_string temp1 '=' temp2 into join_string separated by space.
    <...>
    concatenate join_string ')' into join_string separated by space.
    And then use similar approach for l_where variable.

  • Dynamic select query with dynamic where condition

    Hi all,
    I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
    Please advice, if there is any other way to achieve this requirement.
    Thanks,
    Sanket Sethi
    Code***************
    PARAMETERS: p_tabnam      TYPE tabname,
                p_selfl1      TYPE edpline,
                p_value       TYPE edpline,
                p_where1      TYPE edpline .
    DATA: lt_where    TYPE TABLE OF edpline,
          lt_sel_list TYPE TABLE OF edpline,
          l_wa_name   TYPE string,
          ls_where    TYPE edpline,
          l_having    TYPE string,
          dref        TYPE REF TO data,
          itab_type   TYPE REF TO cl_abap_tabledescr,
          struct_type TYPE REF TO cl_abap_structdescr,
          elem_type   TYPE REF TO cl_abap_elemdescr,
          comp_tab    TYPE cl_abap_structdescr=>component_table,
          comp_fld    TYPE cl_abap_structdescr=>component.
    TYPES: f_count TYPE i.
    FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
    *                <ls_outtab> TYPE ANY,
                    <l_fld> TYPE ANY.
    struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
    elem_type   ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
    comp_tab = struct_type->get_components( ).
    comp_fld-name = 'F_COUNT'.
    comp_fld-type = elem_type.
    APPEND comp_fld TO comp_tab.
    struct_type = cl_abap_structdescr=>create( comp_tab ).
    itab_type   = cl_abap_tabledescr=>create( struct_type ).
    l_wa_name = 'l_WA'.
    CREATE DATA dref TYPE HANDLE itab_type.
    ASSIGN dref->* TO <lt_outtab>.
    *CREATE DATA dref TYPE HANDLE struct_type.
    *ASSIGN dref->* TO <ls_outtab>.
    * Creation of the selection fields
    APPEND p_selfl1 TO lt_sel_list.
    APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
    ** Creation of the "where" clause
    *CONCATENATE p_selfl1 '= '' p_value ''.'
    *            INTO ls_where
    *            SEPARATED BY space.
    *APPEND ls_where TO lt_where.
    * Creation of the "where" clause
    APPEND p_where1 TO lt_where.
    * Creation of the "having" clause
    l_having = 'count(*) >= 1'.
    * THE dynamic select
    SELECT          (lt_sel_list)
           FROM     (p_tabnam)
           INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
    *       WHERE    (lt_where).

    Hi Sanket,
    The above given logic of mine works for you, put the code in the If condition and try-
    just like below:
    IF NOT P_EBELN IS INITIAL.
    lt_where = '& = ''&'' '.
    REPLACE '&' WITH p_ebeln INTO lt_where.
    REPLACE '&' WITH field_value INTO lt_where.
    SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
    FROM (p_tabnam)
    WHERE (lt_where).
    ENDIF.
    thanks\
    Mahesh

  • How to form an Endeca query where a field must start with certain letters

    hi, Is it possible to form an Endeca query to retrieve a field that must start with certain letters? Say like get all users who's first letter is 'A' ? I checked with Range filters but it is supporting only numerical fields as well as Wild card search. But nothing worked well so far. any suggestion?

    Yes. Here's the gist of how it works:
    Typeahead is commonly implemented by enabling wildcard search on one or more Dimensions. An AJAX query is sent out containing the beginning of a search term. A controller in the app layer answers that AJAX query and formulates an Endeca Dimension Search query. It sends that off to the Endeca MDEX engine. Endeca responds with relevant Dimension matches. The controller returns these to the client who made the AJAX request. They are rendered as hyperlinks that lead to a particular navigation state in the catalog.

  • [ADF] Query panel advanced search - starts with

    Hi all
    I have a query panel with an attribute which has an Attached LOV. The operator is defined as "Equals" in the View criteria
    The attribute is behaving properly
    View image: 1
    but when switched to advanced mode and "starts with" operator selected, the LOV changes to a numeric field and expects a numeric value
    View image: 2
    Is there a work around for this apart from removing the startswith operator
    Jdev version - 11.1.2.0.0

    User, please always tell us your jdev version.
    Well, this use case need some thinking to be done. What do you want to archive with adding a new query field to the panel? As you said you already have one field for employeeId and now, on a click on a button, you add another one. How would the resulting query work with the new field? Should it use 'and' to concatenate the query or should it use 'or'?
    I suggest that you use the ADF Riche Client Demo (http://jdevadf.oracle.com/adf-richclient-demo/faces/index.jspx) select the Query node and then select 'af:query'. This shows you what is possible otu of hte box using the af:query component. You can add fields to existing queries in advanced mode (e.g. use system query 5, which starts with an empty panel and allows you to add fields).
    Once you understand how this works you may come back with a more detailed use case description or you have found the solution already. Read the documentation on af:query along with trying otu the component.
    Timo

Maybe you are looking for