Help With Dynamic PL/SQL LOV Syntax

Hello
I am trying to create a dynamic pl/sql lov in Oracle Apex 3.2 on 11g. I am having some issues with the syntax of the statements below and I'd appreciate any suggestions.
DECLARE
BEGIN
IF :p3_current_a_workshop != 0 THEN
RETURN
'select distinct workshop_title ||':  '  || presenter_name ||'    $'|| workshop_fee display_value, workshop_id return_value
from WORKSHOP
where session_time = 'A'
and workshop_status = 'Open'
or workshop_id = :p3_current_a_workshop
order by 1';
ELSE
RETURN
'select distinct workshop_title ||':  '  || presenter_name ||'    $'|| workshop_fee display_value, workshop_id return_value
from WORKSHOP
where session_time = 'A'
and workshop_status = 'Open'
order by 1';
END IF;
EXCEPTION
        WHEN OTHERS THEN
            HTP.PRN('ERROR'||SQLERRM);         
END;I am trying to model the above code off of the example given by apex:
A function that returns a SQL query with two columns:
IF :MY_ITEM='10' THEN
  RETURN
  'SELECT ename, empno
FROM  emp
WHERE depno = 10
ORDER BY 1';
ELSE
  RETURN
  'SELECT ename, empno
FROM emp
WHERE depno = :my_item
ORDER BY 1';
END IF;~Andrew Schultz

Hi Andrew,
Try something like:
DECLARE
BEGIN
IF :p3_current_a_workshop != 0 THEN
RETURN
' select distinct workshop_title ||'':  ''  || presenter_name ||''    $''|| workshop_fee display_value, workshop_id return_value '||
' from WORKSHOP '||
' where session_time = ''A'' '||
' and workshop_status = ''Open'' '||
' or workshop_id = :p3_current_a_workshop '||
' order by 1 ';
ELSE
RETURN
' select distinct workshop_title ||'':  ''  || presenter_name ||''    $''|| workshop_fee display_value, workshop_id return_value '||
' from WORKSHOP '||
' where session_time = ''A'' '||
' and workshop_status = ''Open'' '||
' order by 1 ';
END IF;
EXCEPTION
        WHEN OTHERS THEN
            HTP.PRN('ERROR'||SQLERRM);         
END;Regards,
Lev

Similar Messages

  • Please help with dynamic pl/sql

    Trying to write a generic pl/sql package that can be used on any table I specify at runtime. The procedures are simple and there are only two. I don't understand advanced pl/sql enought to write it myself dynamically. Could someone please give me ideas on this? Because I don't know the syntax of dynamic pl/sql, books aren't helping much with a project I have due tomorrow :)

    Yes, it will all be done at the same time, but I would like them to be able to run independent of each other in case i want one and not the other and vice versa. In procedure 1, the only thing to be done is to get the text in column_1 of tableA to column_1 in tableB.
    I have a regular procedure for procedure 1 that I think will work:
    CREATE OR REPLACE PROCEDURE UPDATE_COLUMN_1
    IS
    v_column_1 tableB.column_1%TYPE;
    v_name tableC.name%TYPE;
    CURSOR c_name_column_1 IS
    SELECT column_1, name from tableA;
    BEGIN
    OPEN c_name_column_1;
    LOOP
    Fetch c_name_column_1 INTO v_column_1, v_name;
    EXIT WHEN c_name_column_1%NOTFOUND;
    UPDATE tableB
    SET column_1 = v_column_1,
    lst_updt = sysdate,
    updt_by = 'anna'
    WHERE name = v_name;
    END LOOP;
    CLOSE c_name_column_1;
    END UPDATE_COLUMN_1;
    My main email is in my husband's name. I will get it faster than my hotmail account. [email protected]

  • Is it possible to make a search help with dynamic  selection table?

    Hi Experts,
    Is it possible to create search helps with dynamic seletion tables means
    i dont know the selection table names at the time of creation of search help.
    These tables will be determined at runtime.
    if yes, Please give an idea how to create and pass the table names at runtime.
    Thanks
    Yogesh Gupta

    Hi Yogesh,
    Create and fill your itab and show it with FM F4IF_INT_TABLE_VALUE_REQUEST
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          retfield        = 'field to return from itab'
          dynpprog        = sy-repid
          dynpnr          = sy-dynnr
          dynprofield     = 'field on your screen to be filled'
          stepl           = sy-stepl
          window_title    = 'some text'
          value_org       = 'S'
        TABLES
          value_tab       = itab
        EXCEPTIONS
          parameter_error = 1
          no_values_found = 2
          OTHERS          = 3.
    Darley

  • Help with dynamic SQL

    Hello,
    I have the following function that works ok:
    CREATE OR REPLACE FUNCTION Get_Partition_Name (sTable VARCHAR2, iImportIndex INTEGER)
    RETURN VARCHAR2 IS
    cursor c is select A.partition_name from (select table_name, partition_name,
    extractvalue (
    dbms_xmlgen.
    getxmltype (
    'select high_value from all_tab_partitions where table_name='''
    || table_name
    || ''' and table_owner = '''
    || table_owner
    || ''' and partition_name = '''
    || partition_name
    || ''''),
    '//text()') import_value from all_tab_partitions) A where table_name = sTable and A.import_value = iImportIndex;
    sPartitionName VARCHAR(20);
    err_num NUMBER;
    BEGIN
    open c;
    fetch c into sPartitionName;
    IF c%ISOPEN THEN
    CLOSE c;
    END IF;
    RETURN sPartitionName;
    EXCEPTION
    WHEN OTHERS THEN
    err_num := SQLCODE;
    --save error in log table
    LOG.SAVELINE(SQLCODE, SQLERRM);
    END Get_Partition_Name;
    I am trying to replace the cursor statement with dynamic SQL, something like (see below) but it doesn't work any more; I think I am missing some quotes.
    CREATE OR REPLACE FUNCTION Get_Partition_Name (sTable VARCHAR2, iImportIndex INTEGER)
    RETURN VARCHAR2 IS
    TYPE t1 IS REF CURSOR;
    c t1;
    sSql VARCHAR2(500);
    sPartitionName VARCHAR(20);
    err_num NUMBER;
    BEGIN
    sSql := 'select A.partition_name from (select table_name, partition_name,
    extractvalue (
    dbms_xmlgen.
    getxmltype (
    ''select high_value from all_tab_partitions where table_name=''''
    || table_name
    || '''' and table_owner = ''''
    || table_owner
    || '''' and partition_name = ''''
    || partition_name
    || ''''''),
    ''//text()'') import_value from all_tab_partitions) A where table_name = :a and A.import_value = :b';
    OPEN c FOR sSql USING sTable, iImportIndex;
    fetch c into sPartitionName;
    IF c%ISOPEN THEN
    CLOSE c;
    END IF;
    RETURN sPartitionName;
    EXCEPTION
    WHEN OTHERS THEN
    err_num := SQLCODE;
    --save error in log table
    LOG.SAVELINE(SQLCODE, SQLERRM);
    END Get_Partition_Name;
    Please advise,
    Regards,
    M.R.

    Assuming the requirement is to find the partition in the supplied table with the supplied high value and the issue is that dba/all_tab_partitions.high_value is a long, one alternative along the same lines as you've done already is as follows. (I've just used a cursor rather than a function for simplicity of demo).
    SQL> var r refcursor
    SQL> set autoprint on
    SQL> declare
      2   ctx dbms_xmlgen.ctxhandle;
      3   v_table_name VARCHAR2(40) := 'LOGMNR_USER$';
      4   v_value      NUMBER       := 100;
      5  begin
      6   ctx := DBMS_XMLGEN.NEWCONTEXT
      7          ('select table_name
      8            ,      partition_name
      9            ,      high_value  hi_val
    10            from   dba_tab_partitions
    11            where  table_name     = :table_name');
    12   dbms_xmlgen.setbindvalue(ctx,'TABLE_NAME',v_table_name);
    13   open:r for
    14   with x as
    15   (select xmltype(dbms_xmlgen.getxml(ctx)) myxml
    16    from   dual)
    17   select extractvalue(x.object_value,'/ROW/TABLE_NAME') table_name
    18   ,      extractvalue(x.object_value,'/ROW/PARTITION_NAME') partition_name
    19   ,      extractvalue(x.object_value,'/ROW/HI_VAL') hi_val
    20   from   x
    21   ,      TABLE(XMLSEQUENCE(EXTRACT(x.myxml,'/ROWSET/ROW'))) x
    22   where  extractvalue(x.object_value,'/ROW/HI_VAL') = v_value;
    23  end;
    24  /
    PL/SQL procedure successfully completed.
    TABLE_NAME
    PARTITION_NAME
    HI_VAL
    LOGMNR_USER$
    P_LESSTHAN100
    100
    SQL> I'm sure there are other ways as well. Especially with XML functionality, there's normally many ways to skin a cat.

  • Need help with Dynamic Excel File Name please.

    I am try to output an excel file with dynamic date. 
    Here what I done.
    I am using SQL 2012.
    Create Execute SQL Task Connect Type: Excel
    Create Data Flow Task set to DelayValidation: True
    Create OLE DB Sourc
    Create Data Converstion
    Excel Destination
    Excel Connection, Expression, select ExcelFilePath
    @[User::sXLFilePath] +  @[User::sFileName] + RIGHT("0" + (DT_WSTR, 2) DATEPART("DD", GETDATE()), 2)+ RIGHT("0" + (DT_WSTR, 2) DATEPART("MM", GETDATE()), 2) + RIGHT((DT_WSTR,
    4) DATEPART("YYYY", GETDATE()), 2) +".csv"
    C:\ExcelOutPut\SOX_CAM_SQL_Report_010215.xls
    What I try to accomplish is output the file with each day append to it, date must be DDMMYY.
    I google it and found many samples, tested it, and none of them is work for me. 
    Any suggestions or some examples to share is greatly appreciate. 
    I am new to SSIS.  I found one poster have similar issue and inside the posted below, there was one suggestion to create variable and connection string but how do I bind that variable to Excel Connection manger.
    Please help.
    Thank you so much in advance.
    Ex: SOX_CAM_SQL_Report _020215.csv
           SOX_CAM_SQL_Report _030215.csv
    --Similar issue:
    https://social.msdn.microsoft.com/Forums/en-US/bda433aa-c8f8-47c9-9e56-efd20b8354ac/creating-a-dynamic-excel-file?forum=sqlintegrationservices
    Suggestion in the above posted but where can bind this to Excel Connection Manger. 
    Please help provide step by step.  Thanks.
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\temp\\" + "ExcelTarget" + (DT_WSTR,4)DATEPART("yyyy",GETDATE())  +
    ".xls" + ";Extended Properties=\"EXCEL 8.0;HDR=YES\";"
    And yes, as you were intimating, the delay validation on the dataflow should be set.

    Hi NguyenBL,
    According to your description, you created ssis package to export data from database to excel, when the package runs, you want to create new excel and name the file with time stamp. If that is the case, we can achieve the goal by following steps:
    Create a script task used to create excel files.
    Create a data flow task to export data from database to excel.
    Add OLE DB source to data flow task.
    Add Excel Destination to data flow task.
    Create connection manager for OLE DB and Excel.
    Click Excel Connection Manager, in Properties window, click (…) button next to Expressions, then set ExcelFilePath with expression like below:
    "C:\\ETL Lab\\CreateNewExcel\\ExportData_"+REPLACE((DT_STR, 20, 1252)(DT_DBTIMESTAMP)@[System::StartTime], ":", "")+".xls"
    For detail information, please refer to the document:
    https://sqljourney.wordpress.com/2013/01/12/ssis-create-new-excel-file-dynamically-to-export-data/
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • Help with anonymus pl/sql layout using javascript

    Hi people.
    i want to display some records on a region (using apex 4.2) , this anonymous pl/sql script below shows 3 records from database, but the layout only shows me the first record with it's data, the others 2 records, only show me labels.
    i have verified this same query creating a report and it shows the 3 records correctly.
    i guess i am doing something wrong with this javascript routine or i am surely missing something,
    in this link you can see the layout i am getting. (http://sdrv.ms/Xrv0J8).
    the other little help i need is to display in one row for each record. actually i am getting one row for each label and one row for each data record. i have read and found is something about /div, but i don't no how to change it to get desired results, any suggestion is welcome.
    thanks in advance for any help.
    i am completely new in apex and java script, but i have several years experience in pl/sql.
    The Script :
    Begin
    Declare
    Cursor Deliv Is
    Select item,
    To_char (Delivery, 'month dd, yyyy hh24:mi:ss') Delivery,
    Current_date
    From pending_items;
    Begin
    For A In Deliv Loop
    Begin
    Sys.Htp.P ('<script type="text/javascript">');
    Sys.Htp.P ('function cdtd() {');
    Sys.Htp.P (' var xmas = new Date("' || a.delivery || '")');
    Sys.Htp.P (' var now = new Date();');
    Sys.Htp.P (' var timeDiff = xmas.getTime() - now.getTime();');
    Sys.Htp.P (' if (timeDiff <= 0) {');
    Sys.Htp.P (' clearTimeout(timer);');
    -- Sys.Htp.P (' document.write("Some Text Here!");');
    Sys.Htp.P (' // Run any code needed for countdown completion here');
    Sys.Htp.P (' }');
    Sys.Htp.P (' var seconds = Math.floor(timeDiff / 1000);');
    Sys.Htp.P (' var minutes = Math.floor(seconds / 60);');
    Sys.Htp.P (' var hours = Math.floor(minutes / 60);');
    Sys.Htp.P (' var days = Math.floor(hours / 24);');
    Sys.Htp.P (' hours %= 24;');
    Sys.Htp.P (' minutes %= 60;');
    Sys.Htp.P (' seconds %= 60;');
    Sys.Htp.P (' document.getElementById("daysBox").innerHTML = days;');
    Sys.Htp.P (' document.getElementById("hoursBox").innerHTML = hours;');
    Sys.Htp.P (' document.getElementById("minsBox").innerHTML = minutes;');
    Sys.Htp.P (' document.getElementById("secsBox").innerHTML = seconds;');
    Sys.Htp.P (' var timer = setTimeout("cdtd()",1000);');
    Sys.Htp.P ('}');
    Sys.Htp.P ('</script>');
    Sys.Htp.P ('Days ');
    Sys.Htp.P ('<div id="daysBox"></div>');
    Sys.Htp.P ('Hours');
    Sys.Htp.P ('<div id="hoursBox"></div>');
    Sys.Htp.P ('Minutes');
    Sys.Htp.P ('<div id="minsBox"></div>');
    Sys.Htp.P ('Seconds');
    Sys.Htp.P ('<div id="secsBox"></div>');
    Sys.Htp.P ('<script type="text/javascript">');
    Sys.Htp.P ('cdtd();</script>');
    End;
    End Loop;
    End;
    End;

    Let's focus on your delivery dates and javascript for now.
    Why you would put your javascript in htp.p calls in a plsql region is quite beyond me. When you edit the page there is a javascript region where you can put global variables and functions, an excellent spot for this then, and a lot more maintainable than this.
    Now it's also obvious that your query on pending items will return more than one record. So, using a report would serve you well in this case. However, using code like this:
    document.getElementById("daysBox").innerHTML = days;
    document.getElementById("hoursBox").innerHTML = hours;
    document.getElementById("minsBox").innerHTML = minutes;
    document.getElementById("secsBox").innerHTML = seconds;will not serve you. getElementById is meant to return one element uniquely identified by an ID. If you have a report with multiple rows, and elements on each row with the same ID, you are doing something wrong. You would need the delivery date per row, and I guess that you put out your code with htp.p because you do not know how to deal with that and passing it in to the javascript procedure.
    But wouldn't it be more oppurtune for you to simply create a report with a source sql where you calculate each part of the date, and then refresh this region with a certain interval. If you'd refresh every 5 minutes, wouldn't that be more than fast enough to keep track of things? Don't forget, refreshing a region will execute the sql again.
    It's not that you can't accomplish a multirecord report with a countdown per row, but are you comfortable enough with javascript and jquery to code and maintain that versus leveraging plsql and dynamic actions (there is even a dynamic action timer plugin provided by oracle)?

  • Help with Dynamic Form Input

    Hello,
    I'd like to generate a form with a PL/SQL script.
    Basically I'd like to ask the user to rank a set of items.
    I have two tables one, ITEMS [ID (Primary Key), NAME (VARCHAR2)] and one PREFERENCES [ID (Primary Key), ITEM_ID (Foreign Key),PREFERENCE (Number), USERNAME (VARCHAR2)]
    From what I understand Collections and APEX_ITEM would be useful here.
    What should I do next?
    Should I read all of the ITEMS ( there will only be 7-13) into a collection and then use APEX_ITEM to generate rows in the form?
    Should I first create rows in Preferences, containing only the ITEM_ID and the USERNAME, and then use multiple row update in APEX_ITEM to generate a tabular form to update the rows?
    Any input would be greatly appreciated.
    Thanks,
    Sam

    I would like one form on one page for creating multiple rows. A tabular form would be fine.
    the page would look like
    Item 1 , Choose a Preference (LOV)
    Item 2, Choose a Preference (LOV)
    Item n, choose a Preference (LOV)
    I know that this could probably be done more easily one row at a time, but I am concerned about making it easy for the end user.
    A tabular form could be appropriate, however it seems like most of your example tabular forms, have already generated records. (ie http://htmldb.oracle.com/pls/otn/f?p=31517:170:4031429456413649::NO ).
    Would it make sense to prepare the form by inserting values into the table just before displaying the form.
    something like (in psudocode)
    select ID from ITEMS into l_items;
    INSERT INTO PREFERENCES (ITEM_ID)
    VALUES (l_items)
    I have a trigger on Preferences that inserts v('APP_USER') into the USERNAME column.
    If I did this the form could display
    select     "ITEMS"."NAME" as "NAME",
         "PREFERENCES"."PREFERENCE" as "PREFERENCE"
    from     "ITEMS" "ITEMS",
         "PREFERENCES" "PREFERENCES"
    where "PREFERENCES"."ITEM_ID"="ITEMS"."ID"
    NAME would be displayed as TEXT
    PREFERENCE would be an LOV
    USERNAME would be hidden
    Thanks for your help.
    -Sam

  • Help with dynamic statement returning values into collection

    Hi All
    I am trying to use dynamic statement to return values into a collection using the returning clause. However, I get an ORA-00933 error. Here is a simple setup:
    create table t(
        pk number,
        id_batch varchar2(30),
        date_created date,
        constraint t_pk primary key ( pk )
    create or replace type num_ntt is table of number;
    create or replace type vc2_ntt is table of varchar2(30);
    create or replace
    package pkg
    as
      type rec is record(
          pk        num_ntt,    
          id_batch  vc2_ntt
      procedure p(
          p_count in number,
          p_rt    out nocopy rec
    end pkg;
    create or replace
    package body pkg
    as
      procedure p(
          p_count in number,
          p_rt    out nocopy rec
      is
      begin
          execute immediate '
          insert into t
          select level, ''x'' || level, sysdate
          from   dual
          connect by level <= :p_count
          returning pk, id_batch into :pk, :id_batch'
          using p_count returning bulk collect into p_rt.pk, p_rt.id_batch;
      end p;
    end pkg;
    declare
      r  pkg.rec;
    begin
      pkg.p( 5, r );
    end;
    /

    sanjeevchauhan wrote:
    but I am working with dynamic statement and returning multiple fields into a collection.And using an INSERT...SELECT statement combined with a RETURNING INTO clause still does not work. Whether it's dynamic SQL or not: it doesn't work. The link describes a workaround.
    By the way, I don't see why you are using dynamic SQL here. Static SQL will do just fine. And so you can literally copy Adrian's setup.
    Regards,
    Rob.

  • Help with some PL/SQL Triggers

    hello there, I'm totally new using PL/SQL so I need your help with two triggers.
    For instance
    1. Compare two dates, and verify that there are different, you must send a message Error
    2. When I insert a new record, a trigger must obtain data from other tables and add it (on a new record)
    Maybe not the answers, maybe the way to go!
    Thks!

    Hi,
    Welcome to the forum
    1. Compare two dates, and verify that there are different, you must send a message Errorwhy trigger ?
    Trigger is Only for when DML Performed :)
    try 1st one in procedure..
    create or replace procedure testing(p_date in date)
    is
    v_date date;
    begin
    select to_date(hiredate,'mm-dd-rr') into v_date
    from emp
    where to_date(hiredate,'mm-dd-rr')=to_date(p_date,'mm-dd-rr');
    dbms_output.put_line(v_date);
    exception
    when others then
    dbms_output.put_line('No Data Found');
    end;
    2. When I insert a new record, a trigger must obtain data from other tables and add it (on a new record)i didn't understand can you please explain me in detail ?
    Thanks
    Venkadesh

  • Help with dynamic page layouts

    Hello JSP Gurus,
    I'm attempting to dynamically generate the page layout for my site based on the organization a user belongs to. Basically, I'd have certain resources like navigation links, graphics, etc, that are modular. Then I'd like to construct the layout using these "moduls" in a dynamic fashion. Does anyone have any suggestions on techniques or technologies that would be useful? I'm not really looking at the portal/portlet model. Is this something that Cocoon could do by storing the layout for each customer as an XML file or something? Any ideas, suggestions, experiences would be helpful.
    Thanks!

    How does Tiles differ from the JetSpeed apache
    project? They both appear to be portal-like
    frameworks, or am I incorrect about that? Which is
    preferred?Frankly, I can't give you an in-depth answer to that. Maybe someone else can help with more details.
    What I can tell you is that JetSpeed seems to be more of a real portal architecture. Emphasis is placed on the framework portion, interfacing with exisiting applications. Visual layout takes second seat to this.
    Tiles on the other hand puts more emphasis on visual layout and reuse.
    Just looking at JetSpeed's visual interfacing a little bit makes me really dislike it. You build tables and such inside of a servlet, so there's a tight coupling (or at least, much tighter than with Struts/Tiles) between the presentation and logic. (I'm basing this on a JavaWorld article at
    http://www.javaworld.com/javaworld/jw-07-2001/jw-0727-jetspeed.html )
    Based on your initial question, it would seem to me that tiles is much closer to what you're looking for (and likely easier to just pick up and use).
    Anyway, take all this with a grain of salt; I'm not exactly an expert on JetSpeed. =)

  • Help with dynamic text and and css !

    My second question of the day.
    I'm trying to build a feature in my app in which the user can
    hide/reveal
    bolding and or
    italics and or
    underlining. The text is being loaded in from an xml file
    and I was thinking about styling it with css in order to get the
    underlining. My problem is that the only way I can think about
    pulling this off is to have a css style sheet that has a defined
    bold,italic and underline class defined- - then another one that
    just has a italic and underline class defined -- then another one
    that has just a bold and underline class defined . . . and so on
    and so on. You can see why I would prefer a much more streamlined
    system. Unfortunately my experience with dynamic text styling is
    somewhat limited. Hopefully someone can help me out here.

    Perfect. I knew it was some little snippet that I was
    forgetting. I made a temporary fix of creating a 0% alpha box over
    the button like a fake click area above the text, and that worked
    but I know that it was a half-arsed way of working around it.
    Thanks.

  • Please help with workflow inspired SQL

    Hi everyone, I need some help with a piece of sql I need to create. It will be used in a workflow scenario and is therefore a bit hairy and has some limitations. So here goes..
    I have 2 current tables that will be used in this query. The first is a table used as a supervisor cross reference, and the second will be used for signing authority, or approval authorization. In short...the first table will give you the supervisor for the particular employee or employee in the where clause. This tells us who to route to. The second table has the operators authority level. As an example.... 1, 2, 3, or 4. A 1 could signify that this supervisor can approve for up to $5,000, and a 4 could signify that this person can approve up to $250,000. thats the basic idea.
    So what I need to do in ONE statement is get the requestor's supervisor, and then check his/hers authority level for level 1, 2, 3 or 4. The authority level needed will be passed into the query, so I will have that as well as the requestor. And here is the hard part...... If no rows are returned (the supervisor does not have authority to approve) I need the query to apply the same logic to the next supervisor. In other words, the supervisor's supervisor. Every requestor will have a supervisor. Every supervisor will also have a supervisor....so it goes until we get to the CEO. So the query needs to keep going until it finds a row matching the signing authority.
    So the limitations are......this needs to happen in one SQL query, and this query can only return ONE field!
    Here are some creates and inserts to give you something to work with. Been suffering with this one for a few days so your help is GREATLY appreciated.
    Supervisor cross reference table
    CREATE TABLE PS_ROLEXLATOPR (ROLEUSER VARCHAR2(30) DEFAULT ' ' NOT
    NULL,
    DESCR VARCHAR2(30) DEFAULT ' ' NOT NULL,
    OPRID VARCHAR2(30) DEFAULT ' ' NOT NULL,
    EMAILID VARCHAR2(70) DEFAULT ' ' NOT NULL,
    FORMID VARCHAR2(70) DEFAULT ' ' NOT NULL,
    WORKLIST_USER_SW VARCHAR2(1) DEFAULT 'Y' NOT NULL,
    EMAIL_USER_SW VARCHAR2(1) DEFAULT 'Y' NOT NULL,
    FORMS_USER_SW VARCHAR2(1) DEFAULT 'Y' NOT NULL,
    EMPLID VARCHAR2(11) DEFAULT ' ' NOT NULL,
    ROLEUSER_ALT VARCHAR2(30) DEFAULT ' ' NOT NULL,
    ROLEUSER_SUPR VARCHAR2(30) DEFAULT ' ' NOT NULL,
    EFFDT_FROM DATE,
    EFFDT_TO DATE) TABLESPACE PTTBL STORAGE (INITIAL 40000 NEXT 100000
    MAXEXTENTS UNLIMITED PCTINCREASE 0) PCTFREE 10 PCTUSED 80
    INSERT INTO PS_ROLEXLATOPR
    DESCR,
    OPRID ,
    EMAILID ,
    FORMID ,
    WORKLIST_USER_SW ,
    EMAIL_USER_SW ,
    FORMS_USER_SW ,
    EMPLID ,
    ROLEUSER_ALT ,
    ROLEUSER_SUPR ,
    EFFDT_FROM
    VALUES
    DESCR,
    'ABC123',
    'XYZ123',
    Signing Authority table..
    CREATE TABLE PS_ZZ_WF_AUTHORITY (OPRID VARCHAR2(30) NOT NULL,
    EMPLID VARCHAR2(11) NOT NULL,
    EMAILID VARCHAR2(70) NOT NULL,
    ZZ_SIGN_AUTHORITY VARCHAR2(1) NOT NULL) TABLESPACE APLARGE STORAGE
    (INITIAL 40000 NEXT 100000 MAXEXTENTS UNLIMITED PCTINCREASE 0)
    PCTFREE 10 PCTUSED 80
    insert into PS_ZZ_WF_AUTHORITY
    OPRID,
    EMPLID,
    EMAILID,
    ZZ_SIGN_AUTHORITY
    Values
    'XYZ123',
    'Any_Email',
    '1'
    )

    Hi,
    Welcome to the forum!
    Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful!
    Whenever you have a question, also post the results you want to get from the sample data your posted.
    Always say what version of Oracle you're suing.
    In the sample data you posted, I only see one row in each table. Does that really give a good picture of the problem? If the problem involves going up the chain of command 1, 2, 3 or more levels, then shouldn't you have a chain of at least 3 people to show the problem and test the results?
    I think what you need is CONNECT BY Query , which works on a table with a parent-child relationship. Given a parent, you can find that ow's children, the children's children, their children, and so on, however many generations there are.
    I don't think I can demonstrate this with your sample data, so I'll use the scott.emp table, whcih you should be able to query.
    The emp table contains a hierarcy of employees, including this data:
    NAME                 EMPNO        MGR        SAL JOB
    KING                  7839                  5000 PRESIDENT
       JONES              7566       7839       2975 MANAGER
          SCOTT           7788       7566       3000 ANALYST
             ADAMS        7876       7788       1100 CLERK
          FORD            7902       7566       3000 ANALYST
             SMITH        7369       7902        800 CLERK
       BLAKE              7698       7839       2850 MANAGER
          ALLEN           7499       7698       1600 SALESMAN
          WARD            7521       7698       1250 SALESMAN
          MARTIN          7654       7698       1250 SALESMAN
          TURNER          7844       7698       1500 SALESMAN
          JAMES           7900       7698        950 CLERK
       CLARK              7782       7839       2450 MANAGER
          MILLER          7934       7782       1300 CLERKThis show, among other things, that the employee with ename='KING' (empno=7839) has no boss.
    JONES (empno=7566) does have a boss (mgr=7839), namely KING.
    SCOTT (empno=7788) has a bos (mgr=7566), who is JONES.
    I got the results above using this CONNECT BY query:
    SELECT     LPAD ( ' '
              , 3 * (LEVEL - 1)
              ) || ename          AS name
    ,     empno
    ,     mgr
    ,     sal
    ,     job
    FROM     scott.emp
    START WITH     mgr     IS NULL
    CONNECT BY     mgr     = PRIOR empno
    ;This is an example of a Top-Down Query , where we start with a parent, then find its children, grandchildren, and so on.
    In your probelm, you want to do a Bottom-Up Query ; given a child, you want to see if its parent has a certain level of authority. If not, you need to look at that parent's parent, and keep going until to either reach someone with the right qualifications, or you reach the end of the chain of command.
    That's similar to this problem: given a set of employees in scott.emp (say, everyone with job='CLERK') we want to find their closest ancestor who has a sal of 3000 or more. Look at the data above: you can see that SMITH is a CLERK, and SMITH'S boss, FORD, has sal=3000, so we want a row of output that shows SMITH and FORD.
    For a different example, looks at MILLER. MILLER's boss, CLARK, only has sal=2450, so we need to look at CLARK's boss, KING.
    One way to do that in a CONNECT BY query is:
    SELECT     CONNECT_BY_ROOT ename     AS subordinate
    ,     ename
    ,     LEVEL - 1          AS steps_apart
    FROM     scott.emp
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     job       = 'CLERK'
    CONNECT BY     empno       = PRIOR mgr
         AND     PRIOR sal < 3000
    ;Output:
    SUBORDINAT ENAME      STEPS_APART
    SMITH      FORD                 1
    ADAMS      SCOTT                1
    JAMES      KING                 2
    MILLER     KING                 2You should be all set to write the query now.
    Just kidding. I'll bet there's a lot of stuff in this message that's new to you. It's all documented in the SQL Language manual:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/index.htm
    If you'd like help, post your version, a more complete set of sample data, and the results you want from that data.
    Explain, with specific examples, how you get the results you posted from the data you posted.
    Do as much of the query as you can, and post your code.

  • URGENT: Help with dynamic borders!

    Hello all -
    I DESPERATLY need help with this! I am using the code from
    kirupa's xml photo gallery with the thumbnails. right now the alpha
    changes on mouseover, fine...but my client is demanding that it
    draw a border instead. I have been at this for about a week and
    have NO idea how to do this...i have looked at things like API's
    and things...but my main issue is that the images and MC's are all
    created on the fly and i dont know how to code in an on mouseover
    draw a border type of function, no idea at all!
    This is my code as it sits now, PLEASE SOMEONE HELP ME!!!
    thank you in advance!

    really could use some help quick here guys

  • Help with dynamic playlist for mpd

    Hi guys,
    I use mpd with sonata for playing my music, and after trying exaile there is one thing id really like for mpd, and that is the dynamic playlist function.
    When you're playing a song in exaile with dynamic playlist enabled, it queries audioscrobbler and automatically adds similar artists/songs to your playlist (if you have them on your pc).
    I dont want to use exaile as it just feels too big and slow and bloated (not KISS ), i know a little bit of python so i thought i'll try and make my own little script/program as Sonata has audioscrobbler support, but i dont think there is anyway to query similar artists.
    I think im going to try and make this as a daemon type program that will run in the background adding songs to the playlist.
    Ive found the code from the exaile source (audioscrobbler.py) which queries lastfm e.g.
    >>> lips = AudioScrobblerQuery(artist='The Flaming Lips')
    >>> for artist in lips.similar():
    ... print artist.name, artist.mbid
    This will print a list of similar artists to the flaming lips.
    I've not done much with python so i thought this would be a good way to try and improve.
    Does anyone have any suggestions as to what the best way to go about searching and comparing the results to my mpd database, would the best way just to be to search the mpd.db?
    And if anyone else has any ideas/comments id like to hear them.
    Edit:
    I just found this too, so i may only need to change some things to integrate it with mpd rather than amarok
    http://www.kde-apps.org/content/show.php?content=31920
    Thanks
    Last edited by Kane (2008-06-05 13:24:33)

    well i just modified the patch into a little script, it does what i need
    its here if anyone wants it
    import audioscrobbler
    import mpd
    import random
    import time
    lastsong = {}
    def timer_control():
    get_similar()
    time.sleep(10)
    timer_control()
    def get_similar():
    audioscrobbler
    client = mpd.MPDClient()
    client.connect("localhost", 6600)
    mpdstatus = client.status()
    prevsonginfo = client.currentsong()
    global lastsong
    if mpdstatus['state'] == "stop": return
    if prevsonginfo == lastsong: return
    lastsong = prevsonginfo
    similarartists = ""
    song = prevsonginfo
    #if not song: break #No song, do nothing
    prevartist = song['artist']
    # Is the info already cached?
    similar_cache = {}
    if similar_cache.has_key(prevartist):
    similarartists = similar_cache[prevartist]
    else:
    #Not cached so fetch from Audioscrobbler
    try:
    similarartists = [artist.name for artist in audioscrobbler.AudioScrobblerQuery(artist=prevartist).similar()]
    # Cache search results and save some time next search
    similar_cache[prevartist] = similarartists
    except audioscrobbler.AudioScrobblerError:
    similar_cache[prevartist] = None # Empty cache
    return # Do nothing!
    if not similarartists: return # Empty list
    # Split list in half and sort upper half
    # this means good matches will have priority
    # but makes sure artist A does not always result in artist B
    half_idx = len(similarartists)/2
    upperhalf = similarartists[:half_idx]
    lowerhalf = similarartists[half_idx:]
    random.shuffle(upperhalf)
    artistlist = upperhalf
    artistlist.extend(lowerhalf)
    # Try each artist in order
    for artist in artistlist:
    try:
    print "Trying:",artist
    songs = client.search("artist", artist)
    if not songs: continue
    selected_song = random.sample(songs, 1)[0]
    client.add(selected_song['file'])
    print "Added", selected_song['title'],"by",selected_song['artist']
    # Delete old song from playlist?
    break
    except mpd.MPDError, e:
    print "MPDError", e.message
    continue
    except ValueError, e:
    print "ValueError:",e.message
    continue
    timer_control()
    Last edited by Kane (2008-06-06 16:22:49)

  • Help with dynamic sql across multiple tables

    I have more than one similar table that stores data from different dynamically generated relations:
    Following are the scripts to create and populate tables
    CREATE TABLE RELATION_1(
        SRC            NUMBER(38, 0)               NOT NULL,
        TRG            NUMBER(38, 0)               NOT NULL,
        VALUE          NUMBER(38, 0)               NOT NULL
    CREATE TABLE RELATION_2(
        SRC            NUMBER(38, 0)               NOT NULL,
        TRG            NUMBER(38, 0)               NOT NULL,
        VALUE          NUMBER(38, 0)               NOT NULL
    CREATE TABLE RELATION_3(
        SRC            NUMBER(38, 0)               NOT NULL,
        TRG            NUMBER(38, 0)               NOT NULL,
        VALUE          NUMBER(38, 0)               NOT NULL
    insert into RELATION_1 values(1, 1, 13);
    insert into RELATION_1 values(1, 2, 4);
    insert into RELATION_1 values(1, 3, 6);
    insert into RELATION_1 values(2, 1, 3);
    insert into RELATION_1 values(2, 3, 7);
    insert into RELATION_1 values(3, 1, 5);
    insert into RELATION_2 values(1, 2, 1);
    insert into RELATION_2 values(4, 1, 1);
    insert into RELATION_2 values(5, 1, 1);
    insert into RELATION_3 values(1, 1, 11);
    insert into RELATION_3 values(2, 1, 4);
    insert into RELATION_3 values(3, 1, 5);
    insert into RELATION_3 values(1, 2, 6);
    insert into RELATION_3 values(2, 2, 3);
    insert into RELATION_3 values(3, 2, 5);
    insert into RELATION_3 values(1, 3, 2);
    insert into RELATION_3 values(2, 3, 3);
    insert into RELATION_3 values(3, 3, 5);Now, I want to write a SQL that for a set of SRCs (lets say for 1,2,3) give me the top n (let's say top 10) TRGs and the SUM of all the VALUE across all the tables except for RELATION_2, i.e. RELATION_1 and RELATION 3, order by this SUM and exclude those TRGs that have entry for SRC-TRG combination in RELATION_2 table.
    Thanks
    Edited by: Vasif Shaikh on Sep 21, 2010 2:34 PM

    I didn't completely understand your requirement, but couldn't you UNION all the tables together? Then you could do your Top-n and sorting etc as if you were working with one table.

Maybe you are looking for