Sys_context and Order by clause

Hi All,
Im using Oracle 11g R2.
Is it somehow possible to use Context variable (to store column name) in ORDER BY clause? My ultimate aim is to construct Order by at runtime without using concatenation.
e.g. i created context as my_ctx for some pkg and its variable as v_ctx having value set as "TABLE_NAME"
so is it possible to use it as
select * from all_tables
order by sys_context('my_ctx', 'v_ctx');
if no, is there any work around??
Thanks,
Vivek

Hi, Vivek,
Vivek wrote:
Hi All,
Im using Oracle 11g R2.
Is it somehow possible to use Context variable (to store column name) in ORDER BY clause? My ultimate aim is to construct Order by at runtime without using concatenation.Sure, you can use SYS_CONTEXT in an ORDER BY clause, but it's unclear what you're trying to do, so I don't know if SYS_CONTEXT will help you.
e.g. i created context as my_ctx for some pkg and its variable as v_ctx having value set as "TABLE_NAME"
so is it possible to use it as
select * from all_tables
order by sys_context('my_ctx', 'v_ctx');
if no, is there any work around??Post a complete test script hat people can run to re-create the problem and test their ideas. Show the output you want from the parameters an data you give.
Think about using a CASE expression in the ORDER BY clause. You can use SYS_CONTEXT in the CASE expression if you want to.

Similar Messages

  • How to use left outer joins ,right outer joins and order by clause for belo

    Hi,
    How to use left outer joins ,right outer joins and order by clause for below XML query.
    The query which is red colour returns null then its not displaying any values for columns in that tables. Tried decode, nvl function hasn't worked.
    SELECT XMLAGG ( XMLELEMENT( "P", XMLFOREST( P.process_id AS Ppid,
              (SELECT XMLAGG( XMLELEMENT( "PI", XMLFOREST( PI.question_id AS PIqid,
                                       PI.process_id AS PIpid,
    PI.innertext AS
                                       PItext, PI.itemtype AS PItype,
                                       PI.linkfrom AS PIfrom,
                                       PI.linkto AS PIto,
    PI.associated AS PIas,
                                       PI.content_id AS PIc,
                                       PI.exitpoint1_id AS PIe1,
                                       PI.exitpoint2_id AS PIe2,
                                       PI.exitpoint3_id AS PIe3,
                                       PI.followoncall AS PIfoc,
    PI.userinput AS PIui,
                                       PI.resolveidentifier AS PIri,
    PI.libquestion_idfk AS PIlqid,
                                       PI.isLocked AS PIstls,
                                       PI.PreviousAnswer AS PIPAns,
                                       PI.VisibleToAgent AS PIVAgent,
                                       PI.RetryAttempt AS PIRetry,
                                       PI.Tags AS PITag,
                                  SELECT XMLAGG( XMLELEMENT( "PO", XMLFOREST( PO.option_id AS POoid,
                                       PO.question_id AS POqid,
                                                           PO.process_id AS popid,
                                                           PO.opt_innertext AS POtext,
                                                           PO.opt_linkfrom AS POfrom,
                                                           PO.opt_linkto AS POto,
                                                           PO.libquestion_idfk AS POlqid,
                                                           PO.liboption_idfk AS POloid ) ) )
                                  FROM vw_liveProcessOption_Sim_v6 PO
                                       WHERE PI.question_id = PO.question_id (+)
                                  AND PI.process_id = PO.process_id (+)
                                  ) "A" ) ) ) AS "PO"
         FROM vw_liveProcessItem_Sim_v6 PI
              WHERE P.process_id = PI.process_id
              ) "A" ) ) ) AS "PI"
    FROM liveProcess_ec P
    WHERE (P.process_id = 450)
    Any help really appreciated.
    Thanks

    user512743 wrote:
    Hi,
    Here below is the scripts of tables, insert statements and Required output.
    CREATE TABLE VW_LIVEPROCESSOPTION_SIM_v6
    (     "OPTION_ID" NUMBER,
         "QUESTION_ID" NUMBER(10,0),
         "PROCESS_ID" NUMBER(10,0),
         "OPT_INNERTEXT" VARCHAR2(200 CHAR),
         "OPT_LINKFROM" VARCHAR2(20 CHAR),
         "OPT_LINKTO" VARCHAR2(20 CHAR),
         "LIBQUESTION_IDFK" NUMBER,
         "LIBOPTION_IDFK" NUMBER
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,2,450,'Yes',null,'5',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,3,450,'Yes',null,'5',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,5,450,'Yes',null,'6',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,6,450,'Yes',null,'7',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,8,450,'Block All',null,'9',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,9,450,'Yes',null,'10',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,11,450,'Yes',null,'12',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,12,450,'Yes',null,'13',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,14,450,'Yes',null,'16',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,2,450,'No',null,'3',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,3,450,'No',null,'4',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,5,450,'No',null,'8',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,6,450,'No',null,'8',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,8,450,'Standard',null,'11',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,9,450,'No',null,'11',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,11,450,'No',null,'14',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,12,450,'No',null,'14',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,14,450,'No',null,'15',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (3,8,450,'Disabled',null,'12',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (4,8,450,'User Defined',null,'12',null,null);
    REATE TABLE "VW_LIVEPROCESSITEM_SIM_v6"
    (     "QUESTION_ID" NUMBER(10,0),
         "PROCESS_ID" NUMBER(10,0),
         "INNERTEXT" VARCHAR2(200 CHAR),
         "ITEMTYPE" VARCHAR2(50 CHAR),
         "LINKFROM" VARCHAR2(500 CHAR),
         "LINKTO" VARCHAR2(500 CHAR),
         "ASSOCIATED" VARCHAR2(200 CHAR),
         "CONTENT_ID" NUMBER,
         "EXITPOINT1_ID" NUMBER(10,0),
         "EXITPOINT2_ID" NUMBER(10,0),
         "EXITPOINT3_ID" NUMBER(10,0),
         "RESOLVEIDENTIFIER" VARCHAR2(40 CHAR),
         "LIBQUESTION_IDFK" NUMBER(10,0),
         "FOLLOWONCALL" NUMBER(1,0),
         "USERINPUT" VARCHAR2(200 CHAR),
         "ISLOCKED" NUMBER(1,0),
         "PREVIOUSANSWER" NUMBER(1,0),
         "VISIBLETOAGENT" NUMBER(1,0),
         "RETRYATTEMPT" NUMBER(10,0),
         "TAGS" VARCHAR2(50 BYTE)
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (1,450,'CBB1015 - Router Firewall Settinngs Process','Title',null,'2',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (2,450,'Is the customers PC Firewall turned off?','Question','1','2.2,2.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (3,450,'Advise the customer to turn off the PC Firewall in order to continue. Has this been done?','Question','2.2','3.2,3.1',null,278,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (4,450,'Advise the customer the PC Firewall must be switched off before this process????','ExitPoint','3.2',null,null,null,14,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (5,450,'Is the customer able to access the internet now?','Question','3.1,2.1','5.2,5.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (6,450,'Is the customer having a problem with a specific website?','Question','5.1','6.2,6.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (7,450,'1536: CBB1008 - Browser Setup and Daignostics','SubProcess','6.1',null,'1536-1-0',null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (8,450,'What is the security level on the CPE Management page?','Question','6.2,5.2','8.4,8.3,8.2,8.1',null,279,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (9,450,'Change the security level to Standard. Does this resolve the customers issue?','Question','8.1','9.2,9.1',null,280,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (10,450,'Issue Resolved','ExitPoint','9.1',null,null,null,1,6,122,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (11,450,'Change the security level to Disabled. Is the customer able to browse the internet?','Question','9.2,8.2','11.2,11.1',null,281,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (12,450,'Change the security level to Standard. Is the customer able to browse the internet now?','Question','11.1,8.3,8.4','12.2,12.1',null,283,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (13,450,'Issue Resolved','ExitPoint','12.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (14,450,'Ask the customer to perform a master reset. Does this resolve their issue?','Question','12.2,11.2','14.2,14.1',null,282,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (15,450,'Faulty CPE','ExitPoint','14.2',null,null,null,1,6,124,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (16,450,'Issue Resolved','ExitPoint','14.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
    CREATE TABLE "LIVEPROCESS_EC_V"
    (     "PROCESS_ID" NUMBER(10,0),
         "USER_ID" NUMBER(10,0),
         "CREATED" TIMESTAMP (6)
    Insert into LIVEPROCESS_EC (PROCESS_ID,USER_ID,CREATED) values (450,7460,to_timestamp('21-APR-08 09.34.41.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'));
    Required O/P in XML format
    <P>
    <Ppid>450</Ppid>
    <PI>
    <PIqid>1</PIqid>
    <PIpid>450</PIpid>
    <PItext>CBB1015 - Router Firewall Settinngs Process</PItext>
    <PItype>Title</PItype>
    <PIto>2</PIto>
    <PO />
    </PI>
    <PI>
    <PIqid>2</PIqid>
    <PIpid>450</PIpid>
    <PItext>Is the customers PC Firewall turned off?</PItext>
    <PItype>Question</PItype>
    <PIfrom>1</PIfrom>
    <PIto>2.2,2.1</PIto>
    <PO>
    <POoid>1</POoid>
    <POqid>2</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>5</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>2</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>3</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>3</PIqid>
    <PIpid>450</PIpid>
    <PItext>Advise the customer to turn off the PC Firewall in order to continue. Has this been done?</PItext>
    <PItype>Question</PItype>
    <PIfrom>2.2</PIfrom>
    <PIto>3.2,3.1</PIto>
    <PIc>278</PIc>
    <PO>
    <POoid>1</POoid>
    <POqid>3</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>5</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>3</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>4</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>4</PIqid>
    <PIpid>450</PIpid>
    <PItext>Advise the customer the PC Firewall must be switched off before this process????</PItext>
    <PItype>ExitPoint</PItype>
    <PIfrom>3.2</PIfrom>
    <PIe1>14</PIe1>
    <PO />
    </PI>
    <PI>
    <PIqid>5</PIqid>
    <PIpid>450</PIpid>
    <PItext>Is the customer able to access the internet now?</PItext>
    <PItype>Question</PItype>
    <PIfrom>3.1,2.1</PIfrom>
    <PIto>5.2,5.1</PIto>
    <PO>
    <POoid>1</POoid>
    <POqid>5</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>6</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>5</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>8</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>6</PIqid>
    <PIpid>450</PIpid>
    <PItext>Is the customer having a problem with a specific website?</PItext>
    <PItype>Question</PItype>
    <PIfrom>5.1</PIfrom>
    <PIto>6.2,6.1</PIto>
    <PO>
    <POoid>1</POoid>
    <POqid>6</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>7</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>6</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>8</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>7</PIqid>
    <PIpid>450</PIpid>
    <PItext>1536: CBB1008 - Browser Setup and Daignostics</PItext>
    <PItype>SubProcess</PItype>
    <PIfrom>6.1</PIfrom>
    <PIas>1536-1-0</PIas>
    <PO />
    </PI>
    <PI>
    <PIqid>8</PIqid>
    <PIpid>450</PIpid>
    <PItext>What is the security level on the CPE Management page?</PItext>
    <PItype>Question</PItype>
    <PIfrom>6.2,5.2</PIfrom>
    <PIto>8.4,8.3,8.2,8.1</PIto>
    <PIc>279</PIc>
    <PO>
    <POoid>1</POoid>
    <POqid>8</POqid>
    <popid>450</popid>
    <POtext>Block All</POtext>
    <POto>9</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>8</POqid>
    <popid>450</popid>
    <POtext>Standard</POtext>
    <POto>11</POto>
    </PO>
    <PO>
    <POoid>3</POoid>
    <POqid>8</POqid>
    <popid>450</popid>
    <POtext>Disabled</POtext>
    <POto>12</POto>
    </PO>
    <PO>
    <POoid>4</POoid>
    <POqid>8</POqid>
    <popid>450</popid>
    <POtext>User Defined</POtext>
    <POto>12</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>9</PIqid>
    <PIpid>450</PIpid>
    <PItext>Change the security level to Standard. Does this resolve the customers issue?</PItext>
    <PItype>Question</PItype>
    <PIfrom>8.1</PIfrom>
    <PIto>9.2,9.1</PIto>
    <PIc>280</PIc>
    <PO>
    <POoid>1</POoid>
    <POqid>9</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>10</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>9</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>11</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>10</PIqid>
    <PIpid>450</PIpid>
    <PItext>Issue Resolved</PItext>
    <PItype>ExitPoint</PItype>
    <PIfrom>9.1</PIfrom>
    <PIe1>1</PIe1>
    <PIe2>6</PIe2>
    <PIe3>122</PIe3>
    <PO />
    </PI>
    <PI>
    <PIqid>11</PIqid>
    <PIpid>450</PIpid>
    <PItext>Change the security level to Disabled. Is the customer able to browse the internet?</PItext>
    <PItype>Question</PItype>
    <PIfrom>9.2,8.2</PIfrom>
    <PIto>11.2,11.1</PIto>
    <PIc>281</PIc>
    <PO>
    <POoid>1</POoid>
    <POqid>11</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>12</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>11</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>14</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>12</PIqid>
    <PIpid>450</PIpid>
    <PItext>Change the security level to Standard. Is the customer able to browse the internet now?</PItext>
    <PItype>Question</PItype>
    <PIfrom>11.1,8.3,8.4</PIfrom>
    <PIto>12.2,12.1</PIto>
    <PIc>283</PIc>
    <PO>
    <POoid>1</POoid>
    <POqid>12</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>13</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>12</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>14</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>13</PIqid>
    <PIpid>450</PIpid>
    <PItext>Issue Resolved</PItext>
    <PItype>ExitPoint</PItype>
    <PIfrom>12.1</PIfrom>
    <PIe1>1</PIe1>
    <PIe2>6</PIe2>
    <PIe3>123</PIe3>
    <PO />
    </PI>
    <PI>
    <PIqid>14</PIqid>
    <PIpid>450</PIpid>
    <PItext>Ask the customer to perform a master reset. Does this resolve their issue?</PItext>
    <PItype>Question</PItype>
    <PIfrom>12.2,11.2</PIfrom>
    <PIto>14.2,14.1</PIto>
    <PIc>282</PIc>
    <PO>
    <POoid>1</POoid>
    <POqid>14</POqid>
    <popid>450</popid>
    <POtext>Yes</POtext>
    <POto>16</POto>
    </PO>
    <PO>
    <POoid>2</POoid>
    <POqid>14</POqid>
    <popid>450</popid>
    <POtext>No</POtext>
    <POto>15</POto>
    </PO>
    </PI>
    <PI>
    <PIqid>15</PIqid>
    <PIpid>450</PIpid>
    <PItext>Faulty CPE</PItext>
    <PItype>ExitPoint</PItype>
    <PIfrom>14.2</PIfrom>
    <PIe1>1</PIe1>
    <PIe2>6</PIe2>
    <PIe3>124</PIe3>
    <PO />
    </PI>
    <PI>
    <PIqid>16</PIqid>
    <PIpid>450</PIpid>
    <PItext>Issue Resolved</PItext>
    <PItype>ExitPoint</PItype>
    <PIfrom>14.1</PIfrom>
    <PIe1>1</PIe1>
    <PIe2>6</PIe2>
    <PIe3>123</PIe3>
    <PO />
    </PI>
    </P>
    Thanks in advance
    Edited by: user512743 on Nov 18, 2008 4:46 AM

  • Group by and order by clause

    Hi,
    I have wriiten the below query and i am using group by and order by clause....but i am not getting the required result
    SELECT b.ACCOUNT_REGION,CASE WHEN b.product_reference_status='Reference' THEN 'Recruited' WHEN b.product_reference_status in ('Inactive','Declined') THEN 'Inactive' WHEN b.product_reference_status ='Nominate' THEN 'Inprogress' ELSE 'Other' END product_reference_status, COUNT(decode(b.product_quarter,'Q1FY09',b.REFERENCE_ID)) Q1FY09, COUNT(decode(b.product_quarter,'Q2FY09',b.REFERENCE_ID)) Q2FY09, COUNT(decode(b.product_quarter,'Q3FY09',b.REFERENCE_ID)) Q3FY09, COUNT(decode(b.product_quarter,'Q4FY09',b.REFERENCE_ID)) Q4FY09, COUNT(decode(b.product_quarter,'Q1FY10',b.REFERENCE_ID)) Q1FY10, COUNT(decode(b.product_quarter,'Q2FY10',b.REFERENCE_ID)) Q2FY10, COUNT(decode(b.product_quarter,'Q3FY10',b.REFERENCE_ID)) Q3FY10, COUNT(decode(b.product_quarter,'Q4FY10',b.REFERENCE_ID)) Q4FY10, COUNT(b.product_quarter) Total
    FROM refdump a, ref_dh_pr b
    WHERE A.REFERENCE_ID=b.REFERENCE_ID AND (b.CREATED_ON - NVL(a.REFERENCE_DATE,a.CREATED))>15 group by b.account_region,product_reference_status order by 2
    output is as given below
    Region Status Count
    LAD     Inactive     0
    EMEA     Inactive     21
    *APAC     Inactive     2
    *APAC     Inactive     1
    EMEA     Inactive     2
    EMEA     Inprogress     220
    LAD     Inprogress     19
    LAD     Other     2
    LAD     Other     0
    LAD     Other     5
    LAD     Recruited     182
    APAC     Recruited     191
    My question is
    1) Why i am geeting two APAC regions and 3 LAD (marked *) regions when i have grouped by region and status
    2) How can i make the status in the following order
    a) Recruited
    b)Inprogress
    c)Inactive
    d)Other
    Thanks,

    <i>group by b.account_region,product_reference_status</i>
    Just take all the columns in the group by clause in your select segment and run the SQL, you'll come to know abt the different values in columns which group together.
    *009*

  • Session Context Variable and Order by clause

    Hi All,
    Im using Oracle 11g R2.
    Is it somehow possible to use Context variable (to store column name) in ORDER BY clause? My ultimate aim is to construct Order by at runtime without using concatenation.
    e.g. i created context as my_ctx for some pkg and its variable as v_ctx having value set as "TABLE_NAME"
    so is it possible to use it as
    select * from all_tables
    order by sys_context('my_ctx', 'v_ctx');
    if no, is there any work around??
    Thanks,
    Vivek

    its better to post here
    Oracle Discussion Forums » Oracle Database » SQL and PL/SQL

  • Materialized view and Order by clause

    Hi all. I'd like to have some information regarding the order by clause used in a materialized view.
    I'm using Oracle 9.2 and Win2003 server. I have a common view (my_common_view) on which a materialized view is based (my_materialized_view). Materialized view is built for fast refresh and is created in this way:
    create materialized view my_materialized_view as
    select * from my_common_view
    order by 1,2,3;
    My question is: if I query this materialized view without adding an order by clause in the statement, I will obtain always an ordered result set? So, is it useful to include the order by clause in the materialized view script or the order by has to be include in the statement used for quering the materialized view (for example like this: select * from my_materialized view order by ...)?
    Thank you very much.
    Ste.

    SQL> create table t
      2  (x int)
      3  /
    Table created.
    SQL> create view vw
      2  as
      3  select *
      4    from t
      5   order by x
      6  /
    View created.
    SQL> select *
      2    from v$version
      3  /
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
    PL/SQL Release 9.2.0.7.0 - Production
    CORE    9.2.0.7.0       Production
    TNS for IBM/AIX RISC System/6000: Version 9.2.0.7.0 - Production
    NLSRTL Version 9.2.0.7.0 - Production
    SQL>

  • PreparedStatement and order by clause

    Hi all,
    I'm having a strange problem, when I try to use a preparedStatement which has a parameter in the order by clause the query ignores the order by clause and returns the data in the default table order.
    I'm trying to allow the enduser the ability to sort the results in any way they like.
    a sample of code is:
    javax.sql.DataSource dataSource;
    java.sql.Connection myConnection = null;
    String sort_order = null;
    sort_order = request.getParameter("sort_order");
    if(sort_order == null) {
         sort_order = "start_date, hostname";
    String sql = (String)Tokens.getInstance().getSQLProps().get(Tokens.FIND_SCHED);
    try {
    dataSource = getDataSource(request);
    myConnection = dataSource.getConnection();
    PreparedStatement pstmt = myConnection.prepareStatement(sql);
    pstmt.setString(1, (Tokens.getInstance().getProps().getProperty(Tokens.CURRENT)));
    pstmt.setString(2, sort_order);
    ResultSet rset = pstmt.executeQuery();
    thanks for any help you can provide

    You cannot use bind variables for column names. In this case, what you are telling Oracle to do is to sort by the literal string 'start_date, hostname', which (since the literal string is the same for every row) has no effect. If you want Oracle to sort by the values in those columns, you would have to have different versions of the query depending on the ORDER BY clause. In this case, you would probably want to append the ORDER BY clause to your base SQL statement rather than trying to pass the ORDER BY clause in as a bind variable.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Derived tables and Order by clause

    Hi,
    I have a query that looks as below.
    The execution time of the query (10 sec) is fine when order by clause is removed from the query. But with order by clause, the execution time is 40 times more(400 sec). How to optimize this query so that it will execute within a minute, with ORDER BY clause included?
    select X.a1, X.a2, X.a3, X.a4, Y.b1, Y.b2, Y.b3
    from (select A.a1 a1, A.a2 a2, A.a3 a3, A.a4 a4
    from A_table A
    where A.a1 = 'something') X,
    (select B.b1 b1, B.b2 b2, B.b3 b3
    from B_table B
    where B.b1 = 'some') Y
    where
    X.a1 = Y.a1 (+) AND (some other conditions)
    order by X.a1, X.a2, Y.b1, Y.b2, X.a3, X.a4
    thanks in advance,
    Venkat

    You do need the inline view Y if you are outer joining it because you must apply the
    where B.b1 = 'some'
    condition first.
    However, the inline view X is not needed. Still, I'm not sure that getting rid of it is going to improve performance. Try it and see.
    Incidentally, the outer join condition
    where X.a1 = Y.a1 (+)
    refers to Y.a1, but the inline view Y has no column named a1. Did you mean Y.b1?
    What are the "some other conditions"? Do any of them involve the inline view Y alone (that is, are not join conditions)? If so, it may be that either: a) you don't need an outer join, or, b) those conditions should be moved into the inline view Y. In either case, this may improve performance.
    Are you sure the execution time without the order by clause is really 10 seconds? Or, is that just the elapsed time to return the first row? With the order by clause, Oracle must identify all the rows before it can return the first row.

  • 3 Table Join with group by and order by clauses

    I am porting from MySQL to Oracle 8i. I have a three Table Join in MySQL as follows:
    select distinct TO_DAYS(l.listend)-TO_DAYS(NOW()) AS daysLeft, i.minbid, l.listend, i.itemid, i.itemtitle, l.listingid, l.lendstart, l.lendend, l.status, MAX(b.amount) AS curBid, COUNT(b.amount) AS numBids from TBL_ITEMS i, TBL_LISTING l LEFT JOIN TBL_BIDS b ON l.listingid=b.listingid where i.itemid = l.itemid AND l.status='1' AND (TO_DAYS(l.listend)-TO_DAYS(NOW()) >= 0) AND i.catcode LIKE'12__' GROUP BY listingid order by curBid DESC, daysLeft;
    It performs an straight join on the first 2 tables (TBL_ITEMS and TBL_LISTING) and a LEFT JOIN between the previous result set and TBL_BIDS. TBL_BIDS uses a group by clause to obtain MAX and COUNT info. This final result set is the sorted (ORDER BY).
    I have tried to reconstruct this type of call in Oracle and have failed. Several problems that I have notices: Oracle does not let me pull in additional columns when doing a GROUP BY clause.
    (see below for my work around)
    I have worked around the problem by creating a TABLE with the group by functionality and doing a straing 3 table join. (NOTE: I cannot create a view because use a LIKE function in the call... view dont have indexes). However, when I try to alias the column that returns DATE subtraction ("l.listend-TRUNC(SYSDATE) daysLeft" OR "l.listend-TRUNC(SYSDATE) dayLeft") I cannot use the LIKE statement.
    Here is my question. How do I port the above 3-table MySQL call to Oracle. Why am I having these problems (is it the Oracle optimizer?) and how do I avaopid them in the future.
    I really appreciate anyone's input. Thanks,
    Inder
    WORK AROUND:
    FIRST STEP:
    "create TABLE BIDSUM as
    select l.listingid, COUNT(b.amount) numBids, MAX(b.amount) curBid from TBL_LISTING l, TBL_BIDS b where l.listingid=b.listingid(+) group by (l.listingid);"
    NEXT STEP:
    select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE), l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12%';
    THIS ALSO WORKS (no LIKE):
    "select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode='12'";
    BUT THIS DOES NOT (alias the DATE arimetic)
    select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12__';

    I am porting from MySQL to Oracle 8i. I have a three Table Join in MySQL as follows:
    select distinct TO_DAYS(l.listend)-TO_DAYS(NOW()) AS daysLeft, i.minbid, l.listend, i.itemid, i.itemtitle, l.listingid, l.lendstart, l.lendend, l.status, MAX(b.amount) AS curBid, COUNT(b.amount) AS numBids from TBL_ITEMS i, TBL_LISTING l LEFT JOIN TBL_BIDS b ON l.listingid=b.listingid where i.itemid = l.itemid AND l.status='1' AND (TO_DAYS(l.listend)-TO_DAYS(NOW()) >= 0) AND i.catcode LIKE'12__' GROUP BY listingid order by curBid DESC, daysLeft;
    It performs an straight join on the first 2 tables (TBL_ITEMS and TBL_LISTING) and a LEFT JOIN between the previous result set and TBL_BIDS. TBL_BIDS uses a group by clause to obtain MAX and COUNT info. This final result set is the sorted (ORDER BY).
    I have tried to reconstruct this type of call in Oracle and have failed. Several problems that I have notices: Oracle does not let me pull in additional columns when doing a GROUP BY clause.
    (see below for my work around)
    I have worked around the problem by creating a TABLE with the group by functionality and doing a straing 3 table join. (NOTE: I cannot create a view because use a LIKE function in the call... view dont have indexes). However, when I try to alias the column that returns DATE subtraction ("l.listend-TRUNC(SYSDATE) daysLeft" OR "l.listend-TRUNC(SYSDATE) dayLeft") I cannot use the LIKE statement.
    Here is my question. How do I port the above 3-table MySQL call to Oracle. Why am I having these problems (is it the Oracle optimizer?) and how do I avaopid them in the future.
    I really appreciate anyone's input. Thanks,
    Inder
    WORK AROUND:
    FIRST STEP:
    "create TABLE BIDSUM as
    select l.listingid, COUNT(b.amount) numBids, MAX(b.amount) curBid from TBL_LISTING l, TBL_BIDS b where l.listingid=b.listingid(+) group by (l.listingid);"
    NEXT STEP:
    select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE), l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12%';
    THIS ALSO WORKS (no LIKE):
    "select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode='12'";
    BUT THIS DOES NOT (alias the DATE arimetic)
    select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12__';

  • Cascading LOV - and order by clause?

    Hi, I have a collection that makes use of cascading lovs.
    The cascading lov works properly, but I would like the return values sorted alphabetically and cannot figure out why they are not. If I run the query in SQL, it runs perfectly.
    My query is:
    select......
    apex_item.select_list_from_query_xl(15,c015,'select port_name, port
    from valid_ports
    where state = '
    ||nvl(c014,0)
    *||'order by port_name',*
    'style="width:150px;background-color:#FBEC5D;"',
    'YES',
    '0',
    '- Select PORT -',
    'f15_' || LPAD (seq_id, 4, '0'),
    NULL,
    'NO' ) PORT,
    c014 is a state code. Order by port_name.
    any thoughts? thanks

    Hi Varad, thanks for your response. It is the child...here is the full query, it may make more sense.
    thanks again!
    Karen
    {select  apex_item.hidden (1,seq_id) checkbox,
    apex_item.hidden (2,seq_id)||
            *apex_item.select_list_from_query(3,c003,'select partner_name d, state_code r*
                                                      *from   partners*
                                                      *where state_code is not null*
                                                      *order by partner_name',*
                               *'style="width:100px;background-color:#FBEC5D; "'*
                                *||'onchange="f_set_casc_sel_list_item_port(this,f4_'||LPAD (seq_id, 4,'0')||')"',*
                                 *'YES',*
                                    *'0',*
                                    *'- Select State -',*
                                    *'f3_' || LPAD (seq_id,4, '0'),*
                                    *NULL,*
                                    *'NO'*
                                   *) STATE,*
               *apex_item.select_list_from_query_xl(4,c004,'select port_name, port*
                                                        *from   valid_ports*
                                                        *where  fips_state = '*
                                                        *||nvl(c003,0)*
                                                        *||' order by port_name',*
                                             *'style="width:150px;background-color:#FBEC5D;"',*
                                             *'YES',*
                                             *'0',*
                                             *'- Select PORT -',*
                                             *'f4_' || LPAD (seq_id, 4, '0'),*
                                             *NULL,*
                                             *'NO' )  PORT,*apex_item.POPUPKEY_FROM_LOV(5,c005,'VESSELS_DE',NULL,NULL,NULL,NULL,NULL,
                                    'style="width:150px;background-color:#FBEC5D; "') vessel_id,
          apex_item.text(7,c007,8,null,'style="background-color:#FBEC5D;"'
    ||'onchange="f_set_start_date(this,f7_'||LPAD(seq_id, 4,'0')||')"') trip_start_date,    
            apex_item.text(8,c008,5,null,'style="background-color:#FBEC5D"')  trip_start_time,
            apex_item.text(9,c009,null,10,'style="width:100px;background-color:#FBEC5D"') trip_end_date,
            apex_item.text(10,c010,5,null,'style="background-color:#FBEC5D"')  trip_end_time,
            apex_item.SELECT_LIST_FROM_LOV(11,c011,'TRIP_TYPE','style="width:100px;background-color:#FBEC5D;  "') trip_type,
            apex_item.SELECT_LIST_FROM_LOV(12,c012,'YES_NO','onchange="setMultipleFishermen(#ROWNUM#);"','YES',0,' ','f12_#ROWNUM#') multiple_fishermen,
            apex_item.text(13,c013,3,null,'style="background-color:#FBEC5D"')  days_at_sea,
            apex_item.text(14,c014,3,null,'style="background-color:#FBEC5D"')  nbr_of_crew,
           -- apex_item.hidden(15,c015) supplier_trip_id,
            apex_item.hidden(16,c016,1) trip_nbr,
            apex_item.text(17,c017,5) partner_vtr
      from apex_collections where collection_name = 'TRIP_C'
    }

  • Where clause and order by to DAO classes

    Hi
    Is it ok(I mean design wise) to pass the 'where clause' conditions and order by clause as a parameter to the method of DAO class?

    Well, I would suggest you write seperate methods in your dao , one to select data without the where clause and one to select data with the where clause thrown in. If you have different 'where' clauses for selecting different kinds of data, have that many dao methods. The dao methods being specific know exactly what is the data that's coming in.
    Lets assume you have a list of purchase orders and each purchase order is indetified by a unique id called PURCHASE_ORDER_ID.
    1. The following code would populate a purchase order's details given an id.
    private statis final String QUERY_1 = "select * from PURCHASE_ORDERS where PURCHASE_ORDER_ID = ? ";
    PurchaseOrderModel getPurchaseOrderData(long poId){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the poId passed as params to your query
         pst.setLong(1, poId);
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //populate data into a model          
         finally{
              //clean up resources
         return model;    
    }2. The following code would return a list of PurchaseOrderModel's whose shipping date falls between a set of dates selected by the user.
    private statis final String QUERY_2 = "select * from PURCHASE_ORDERS where SHIPPING_DATE between ? and ? ";
    PurchaseOrderModel getPurchaseOrdersBetweenDates(list bindValues){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the dates passed as params to your query
         //we know that the List ought to contain only 2 dates
         pst.setDate(1, (Date)bindValues.get(0));
         pst.setDate(2, (Date)bindValues.get(1));
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
         3. This is more interesting - the dao method searches a list of Purchase Orders starting with a set of specific words. The words themselves may be one or many. This means that the number of '?' in your prepared statement may be dynamic. Each element of the list is a String that contains the start substring of a purcahse order name. For example - the list may contain elements like ["a", "ab", "c", "gh"] and the dao method returns all purchase order starting with these names.
    private statis final String QUERY_3 = "select * from PURCHASE_ORDERS where ";
    PurchaseOrderModel getPurchaseOrderNameMatches(list bindValues){
         //construct the query dynamically
         StringBuffer query = new StringBuffer(QUERY_3);
         int count = 0;
         for(Iterator itr = bindValues.iterator(); itr.hasNext();;){
              String value = (String)itr.next();
              query.append ("name like 'value%' ");
              if (count != 0 and (count+1 != bindValues.length)){
                   query.append(" or ");
              count ++;          
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(query.toString());     
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
    To sum up,
    1. You need as many methods as you have different kinds of searches (one method for each kind of 'where' clause).
    2. The ejb/business layer would examine the data and decide on which method to call.
    3. Increases coding effort, but makes the code clean and readable. Each layer does it's job. Thus we dont have ejbs forming 'where' clauses and so on.
    Having said that, it really is your decision - you should take into consideration the following factors -
    1. How big is the project ? If its a huge codebase developed by many people, then segregate the responsibilities clearly in each layer as I have outlined. For a small scale project, you could go with your approach.
    2. Whats the take on maintenance and future add-ons ? Do you see the codebase growing with time ?
    3. Is your project a commercial one - is it a product that needs to be maintained or is it a one-off development - develop once and you are done with it.
    4. What are the design considerations ? Is somebody going to audit code for quality ? Or is it a academic one ?
    You should take into account all these before deciding to go one way or the other.
    A general thumb rule should be that you should be convinced that your code readable (maintainable), scalable and efficient. Anything that you do towards these ends is good code/design despite what people/books/patterns say, IMO.
    cheers,
    ram.

  • Exception caused by bind variables in ORDER BY clause and VO RANGE_PAGING

    Hi,
    I'm using a ViewObject in RANGE_PAGING mode and discovered a problem when using bind variables in the ORDER BY clause of my statement:
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3 When a bind variable is used in the ORDER BY CLAUSE and the method VO.getEstimatedRowCount() is call then the DB issued an SQL error:
    java.sql.SQLException: Ungültiger Spaltenindex (eng.: invalid column index)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:137)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:174)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:239)
         at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4612)The numbering of the bind variables indicates that the last two bind variables have the wrong numbering (??)
    When I rewrite the SQL into the following statement, the SQL error does not occur but I have not verified yet that the VO delivers the correct range of data because the numbering of the bind variables is not correct.
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT *, decode (attr2, :1, 1, null, 0, -1) as ATTR_FOR_SORTING FROM T_TABLE WHERE (attr1 = :2) ORDER BY ATTR_FOR_SORTING  desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3I'm working with JDev 10.1.2 and Oracle DB 9203.
    Any comments are welcome!
    Thanks,
    Markus

    You are using the bind variable :2 twice. Did you try
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :4) WHERE Z_R_N > :3
    setWhereClauseParm(0, "a"); // :1
    setWhereClauseParm(1, "b"); // :2
    setWhereClauseParm(2, "c"); // :3
    setWhereClauseParm(3, "b"); // :2setting the fourth parameter the same as the second one?
    I remeber reading something about using bind variables twice causing problems, but I#m not sure about it.

  • Without using order by and connect by clause

    hi all,
    can i write a tree query without using start with clause and connect by clause
    and
    can i order the employee names in a select query without using order by clause
    can those things are possible in select statement...

    dipuna wrote:
    hi all,
    can i write a tree query without using start with clause and connect by clause
    and
    can i order the employee names in a select query without using order by clause
    can those things are possible in select statement...A very odd question.
    Those clauses are the means to do what you are asking. Why would you be looking for some other method?

  • Answers Select clauses:  DISTINCT and ORDER BY

    When I run an Answers query two things automatically happend:
    (1) The DISTINCT clause is added to the Select statement
    (2) An ORDER BY is aded to the end.
    The DISTINCT appears to be inclusive of all of the columns selected as are all of the columns included in the ORDER BY.
    Is there a way that I can setup ANSWERS so that it:
    (1) Does not default to add the DISTINCT?
    (2) Does not by default include an ORDER BY?
    (3) Limit the columsn that the DISTINCT is applied to?
    (4) Limit the number of columns in the ORDER BY to only those that I want to sort on?
    (5) Is there a way to specify in the OBIEE specific columns that should excluded from the DISTINCT and ORDERE BY?
    Thanks...

    I wrote a long explanation for this query and the oracle forum preview window decided to eat it, so I'm just posting the query, which might help some people looking for a SELECT DISTINCT approach that retains a sort order and takes the first value for the various grouping columns. In this case, my goal is to get a distinct list of agencies (agname):
    select distinct
          first_value(program_category_desc) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname) cat,
          first_value(program_subcategory_desc) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname) sub,
          first_value(progtypename) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname) ptype,
          first_value(agname) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname) ag
        from R_CONCERTS_REPORT
        order by first_value(program_category_desc) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname),
          first_value(program_subcategory_desc) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname),
          first_value(progtypename) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname),
          first_value(agname) over (partition by agname
            order by program_category_desc, program_subcategory_desc, progtypename, agname);

  • Order by clause not working

    Hi, everyone,
    I am trying to use the following insert statement to insert records in asc order. if i use the select statement alone the order by clause works fine, but when i use the same sql and add a insert into table statment the order by clause does not work. I am not getting the records in ascending order. could anybody help me in this regard?
    INSERT INTO cat_sales_stg
    select      b.SSC,                
         ltrim(rtrim(a.CAT_DESC)) cat_desc,                
         SUM(a.AMOUNT) AMOUNT               
    FROM Trans a, SSC b                     
    WHERE a.ACCOUNT_NUMBER = TO_CHAR(b.ACCOUNT_NUMBER)                    
         AND a.TMONTH >= 200905 AND a.TMONTH <= 200910                
         AND a.FORMAT_NAME = 'ABC'                
         AND b.BMONTH = 200910                
         AND b.SAMPLE = 3                
         AND b.BANNER_NAME = 'ABC'               
         AND b.MODEL_NAME = 'XYZ'               
    group by b.SSC, ltrim(rtrim(a.CAT_DESC))
    order by ssc,cat_desc
    Thanks in advance

    user10636796 wrote:
    Hi, everyone,
    I am trying to use the following insert statement to insert records in asc orderWhat Toon, William, and others have said is that you DON'T insert rows in a specific order. That is completely outside the way relational databases are designed. You insert rows as unordered and use an ORDER BY clause in a SELECT when reading them. ORDER BY is for SELECT statements, not INSERT.
    In particular Toon poined out that we can't control where individual rows get stored.
    There is a databas object called a varray that can store data in sorted order. I have never seen them used because selecting the data back out again is more work; using an ordinary table and an ORDER BY clause is much easier.

  • Suppress "Order By" clause in Answers Query

    Hello,
    Is it possible to Suppress "Order By" clause in Answers Query.
    I'm using a database view as data source. In the view definition, "order by" clause is already specified. Is it possible to get the same order in the OBIEE report??
    I do not want to use Sort Order column in the repository.
    Thanks,
    Girish

    You add a rownumber to your DB view and use that to 'sort' your report.
    regards
    John
    http://obiee101.blogspot.com/

Maybe you are looking for

  • Email Template in OIM API

    Hi All I wanted to send an email using an email definition that i already created through Design Console. is there any API that uses the email template to send mail in the custom code. instead of we hard coding everything in the code. Thank you sas

  • How to Switch iTunes store?

    I used to live in Greece and I was using the Greek iTunes store now that I live to UK how to I switch stores?I tried to do that but I was prompted that I would lose my I iTunes match subscription.Plz help

  • Missing password window when waking from screen saver

    I've had some issues with waking from sleep once I turned on the screen saver password. I opened the lid and the screen lit up and I had the mouse pointer--but no user name/password box. I tried opening/closing the lid a few times, plugging it in to

  • DB2 and AIX on p570 server with Virtual I/O Server

    Hi, All We are implementing a system landscape on IBM p5 570 servers and currently are planning of 3 LPARs with dual VIO-servers on each box. Have anybody expirience for this configuration in production systems ? Is there any DB2-specific problems fo

  • JRE msi - how to disable next-gen plugin ?

    Is anyone familiar with a method to modify the JRE 6u13 msi's tables such that the next-generation plugin (and auto-update if possible) are disabled? Thanks for your time and attention in advance.