ADF based on dynamic query table

I am new to JDeveloper and ADF.

I want to add an editable on a JSF page ADF table, but I want to use
criteria of Dynamics for the query on which the table is based on.


The user will fill some fields, then press a button. Then a daynamic
where class will be created and the table
will fill.

How can I do this?

Hello
You should become familiar with the ViewCriteria for your ViewObject.

Tags: Java

Similar Questions

  • dynamic query for package does not work

    Dear members,

    I have problems with a package in the creation and analysis of a dynamic query in the WHERE clause. Here is an example of what I'm trying to do:

    PROCEDURE test_status_proc)
    wtd_cursor ON cur_type
    date_1 IN date
    date_2 IN DATE
    status in VARCHAR2,
    flag in VARCHAR2)

    IS

    status_sql VARCHAR2 (250): = NULL;
    flag_sql Varchar2 (100): = NULL;

    BEGIN


    Status of the IF = 'A' THEN
    lv_status_sql: = 'A ';
    lv_flag_sql: = 'Y ';
    END IF;
    Status of the 'I' = IF THEN
    lv_status_sql: = 'A ';
    lv_flag_sql: = 'n';
    END IF;

    Status of the 'R' = IF THEN
    lv_status_sql: = "R";
    lv_flag_sql: ='* ';
    END IF;

    Status of the IF = n THEN
    lv_status_sql: = 'n';
    lv_flag_sql: ='* ';
    END IF;

    IF status_code = 'IRN' THEN
    "lv_status_sql: = '('' N'','' R'');
    lv_status_sql: = lv_status_sql | ' OR (s.status = s.flag = "A" AND "N")';
    lv_usecalc_sql: ='* ';
    END IF;

    Status of the = IF'* ' THEN
    lv_status_sql: ='* ';
    lv_flag_sql: ='* ';
    END IF;

    OPEN FOR Test_cursor

    SELECT * from test_status s
    WHERE
    s.Daytime BETWEEN date_1 AND date_2
    S.status AND decode (lv_status_sql,'* ', s.status, lv_status_sql)
    S.flag AND decode (lv_flag_sql,'* ', s.flag, lv_flag_sql);

    The problem I have is especially with the condition 'IRN '. The suite WHERE the part of the clause looks like the following in the lv_status_sql, but the query returns all the values:

    -(', 'R') OR (s.status = 'A' AND s.flag =' only)

    Any help would be much appreciated.

    Kind regards

    dreporter wrote:

    Thanks for your reply and I completely understand your frustration. The problem is sometimes it is very difficult to describe all of the problem due to several reasons. Please take a look at my last post to see if that makes sense.

    If you really need SQL dynamic - true dynamic SQL which includes dealing with dynamic number of bind variables - then DBMS_SQL are an excellent interface to use.

    You can generate the dynamic SQL statement based on the question of whether the filter criteria is null (do not use) or not null (use as a predicate). For example

    if someParam10 is not null then
      // someParam10 needs to be used as a filter predicate
      dynamicSQL := dynamicSQL || ' and some_col_10 = :someParam10 ';
    end if;
    

    This statement can then be analyzed using the DBMS_SQL interface. The binding of values uses the same logic that was used to create predicates. For example

    if someParam10 is not null then
      // someParam10 is used and needs to be bound
      DBMS_SQL.Bind( myCursor, 'someParam10', someParam10 );
    end if;
    

    So, with this approach simplistic, you can easily create a dynamic SQL with variable predicates, dynamically bind these and run the slider.

    Bind variables are used in the dynamic SQL statements, as there are very few threats of SQL injection. And the basic principles observed for shareable SQL creation - the same set of parameters not null to filter, will result in the same SQL statement, which allows the cursor within the Pool shared for this SQL statement to be reused.

    So, technically, dynamic SQL is not a major problem (if used correctly). The major problem is that if really necessary to address the requirements of the business at hand.

    The problem I have with many comments here want to use dynamic SQL statements, is that it is used as one would use a file i/o interface.

    For file IO you want standard Open(), Read(), Write() and Close() calls. And you, the appellant, simply pass the name of the file and the data to write or to receive the data read.

    Similarly, these posters want to use SQL to open a table and read and write the data column - and do it by calling simply (and dynamically) by specifying the name of the table and column. Approaches to dynamic SQL based on one such concept is wrong. And shows that much of the ignorance of what a RDBMS is and how to use an RDBMS.

  • Produce reports based on dynamic queries

    Hi all
    I have a basic question that I found no answer after a search through topics BI.
    I want to produce our reports based on dynamic queries, so that the final query could be transferred by application of the ADF. Is there an idea tho this? Use other tools to integrate with BI Publisher?

    Thank you for your attention,
    Nasser

    Using Datatemplate, we can do it very dynamic reports.

    I worked on usign dynamic reports very very complex, these

  • dynamic query send multiple values dynamically

    Hi all

    I'm trying to run a dynamic query. Is it possible to send dynamically deptno and ename?

    declare
    v_sql varchar2 (4000);
    v_resultCol varchar2 (100): = 'ename ';
    v_col varchar2 (100): = "deptno";
    number of v_num: = 30;
    number of v_count;
    Start
    -v_sql: = 'select'. : v_resultCol |' from emp where ' | : v_col | '= '|| : v_num;

    v_sql: = ' select count (ename) from emp where deptno =: a ';

    run immediately v_sql in v_count using v_num;
    dbms_output.put_line (v_count);
    end;
    /

    Thank you

    You can not choose a column dynamically by passing as a bind value because the binding for the name of the column would be simply considered as a string, in this case a count of the a non-empty string would be the same as count (*), a separate of a non-empty string account would be 1, and an empty string County 0 , which is not a lot get you if you try to count the number of records with non-null to a column values.

    As a dynamically selected column you must can dynamicaly would build the SQL, but opens you up to SQL Injection attacks:

    DECLARE
      v_col varchar2(100) := 'null)+max((select empno from emp where ename=''CLARK'')';
      v_sql VARCHAR2(4000);
      v_count number;
    begin
      v_sql := 'select count('||v_col||') from emp where deptno = :a';
      execute immediate v_sql into v_count using 30;
      dbms_output.put_line(v_count);
    end;
    /
    

    a better approach would be to first make sure that the value of v_col is actually a column in the table:

    DECLARE
      v_col varchar2(100) := 'null)+max((select empno from emp where ename=''CLARK'')';
      v_sql VARCHAR2(4000);
      v_count number;
    begin
      begin
        select column_name into v_col from all_tab_cols
         where owner = 'SCOTT' and table_name='EMP' and column_name = v_col;
      exception when NO_DATA_FOUND then
        v_col := '*';
      end;
      v_sql := 'select count('||v_col||') from scott.emp where deptno = :a';
      execute immediate v_sql into v_count using 30;
      dbms_output.put_line(v_count);
    end;
    / 
    

    Use a box or decode statement in your selection to determine which column to use based on a variable binding:

    DECLARE
      v_col varchar2(100) := 'COMM';
      v_sql VARCHAR2(4000);
      v_count number;
    begin
      v_sql := 'select count(case :col_name '||
                            'when ''ENAME'' then ename '||
                            'when ''COMM'' then to_char(COMM) '||
                            'end) '||
                 'from scott.emp where deptno = :a';
      execute immediate v_sql into v_count using v_col, 30;
      dbms_output.put_line(v_count);
    end;
    /
    

    Published by: Sentinel on October 16, 2008 14:48

  • Collection of the dynamic query

    Hi All-

    I'm trying to get the value of the collection through the dynamic query but I am facing some problem please let me know that I hurt.

    Created a function like below to run the dynamic query to select statement

    create or replace FUNCTION rfunGetColumnValue (
                  ColumnName VARCHAR2,
                  TableName  VARCHAR2,
                  DefaultValue OUT VARCHAR2,
                  Criteria VARCHAR2)
           RETURN VARCHAR2
    IS
           ReturnValue VARCHAR2 (32767 byte) ;
           Stmt        VARCHAR2 (32767 byte) ;
    BEGIN
           stmt := 'begin        
    select '|| ColumnName || ' into  :1  from table(:2) ' ||NVL
           ( Criteria, ' ') ||
           '       
    Fetch First Row only ;        
    EXCEPTION                                   
    WHEN OTHERS THEN                                          
    :2 := SQLERRM;
    end;'
           ;
           dbms_output.put_line (stmt) ;
           EXECUTE IMMEDIATE stmt USING OUT ReturnValue, OUT DefaultValue;
           --select Valueinto into Returnvalue from dual;
           RETURN ReturnValue;
    END;
    

    Now, I created a folder in the Package

    create or replace PACKAGE Collection_PKG
    is
    type Bank_rec is RECORD
    (
    SNO           NUMBER(10),    
    BANKID        NUMBER(5),    
    BANKNAME       VARCHAR2(50),    
    BANKSC         VARCHAR2(50),    
    ADDEDIT       varchar2(1),    
    COMPID        number(5),    
    ISBULK        number(1),    
    ROWNO         number(10),    
    ERROR         VARCHAR2(500)  
    );
    
    
    TYPE Bank_tbl IS TABLE OF Bank_rec;
    --type Bank_cur is ref cursor return Bank_rec;
    
    
    end Collection_PKG;
    
    end Collection_PKG;
    end Collec
    tion_PKG;
    

    Now, when I'm Trying the code below

    DECLARE
      V_EXECQUERYPARAM XMLTYPE:= XMLTYPE('<QueryParam>
      <BankXML>
        <Bank>
          <BankID>0</BankID>
          <BankSC><![CDATA[RCB]]></BankSC>
          <BankName><![CDATA[Royal challenger Bank]]></BankName>
          <IsBulk>0</IsBulk>
          <AddEdit>A</AddEdit>
        </Bank>
      </BankXML>
    </QueryParam>');
    BEGIN
     Rspbanksave(
        v_SPParamList => V_EXECQUERYPARAM  );
    
    
    END; 
    

    create or replace PROCEDURE rspBankSave (
                  v_SPParamList XMLTYPE DEFAULT NULL)
    IS
           V_Addedit VARCHAR2 (1 CHAR) ;
           Bank_tbl Collection_PKG.BANK_TBL := Collection_PKG.BANK_TBL () ;
    BEGIN
           
           SELECT Row_number () OVER (ORDER BY 1),
                  XT.BankID,
                  XT.BankName,
                  XT.BankSC,
                  XT.AddEdit,
                  v_CompID,
                  XT.IsBulk,
                  CAST (0 AS NUMBER (5)),
                  CASE
                         WHEN MBank.BankID IS NOT NULL
                         THEN
                                CASE
                                       WHEN XT.BankSC     = MBank.BankSC
                                          AND XT.BankName = MBank.BankName
                                       THEN 'R104|Entry Already Exist,R114|Short Code Already Exist'
                                       WHEN XT.BankSC = MBank.BankSC
                                       THEN 'R114|Short Code Already Exist'
                                       WHEN XT.BankName = MBank.BankName
                                       THEN 'R104|Entry Already Exist'
                                END
                         ELSE NULL
                  END Bulk collect
           INTO   Bank_tbl
           FROM   XMLTABLE ('//QueryParam/BankXML/Bank' PASSING v_SPParamList COLUMNS BankID NUMBER (5)
                  PATH 'BankID', BankName                                                    VARCHAR2 (
                  50) PATH 'BankName', BankSC                                                VARCHAR2 (
                  50) PATH 'BankSC', AddEdit                                                 VARCHAR2 (
                  1) PATH 'AddEdit', IsBulk                                                  NUMBER (1)
                  PATH 'IsBulk') XT
           LEFT JOIN MBank
           ON     XT.BankID   != MBank.BankID
              AND v_CompID     = MBank.CompID
              AND (XT.BankSC   = MBank.BankSC
               OR XT.BankName  = MBank.BankName) ;
           v_TotalRowCount    := SQL%ROWCOUNT;
    
    
    
    
    
    
           IF (v_TotalRowCount > 0) THEN
                  
                         BEGIN
                               V_Addedit:=rfunGetColumnValue (ColumnName=> 'Upper(AddEdit)',TableName=>'table(Bank_tbl)',DefaultValue=>'',Criteria =>'');
                         END;
                         --SQL Code here
                  
           END IF;
           
    END rspBankSave;
    
    
    
    
    
    
    
    

    As I've suggested before:

    To get the name of the table the column

    and as others have:

    Type global temporary Tables vs. table

    If you give more context, more information about the bigger picture, more information about what you're trying to do and why you're going down the road you go down, you can return more useful information. But you seem reluctant to do.

    For the moment, your recent posts seem to just raise the same type of question - why are you doing this?

    The normal way to return data to a client is a refcursor.

    It is the most effective way.

    Not through collections that you seem to be put on the must-do approach.

  • dynamic query problem

    Hello

    I am trying to understand the procedure and on the inside, I have a dynamic query with where clause:

    "Select."

    tables

    where 1 = 1

    and instr (decode (nvl (' | nvl(pCATEG,'') |))) (("*"), "*", pb.categ, upper (' | nvl(pCATEG,'') |), pb.categ) > 0'

    || NVL(pEMP_GROUP_CODE,'') |

    "and p.emp_group_code = g.emp_group_code';"

    For it, clause make sense (parameter pEMP_GROUP_CODE is not connected to any condition, or I missed something)?

    The procedure is works and connected to the application.

    Please notify

    Thank you

    Daniel

    Has been confused by "p.emp_group_code".

    What you see is probably a lexical parameter, for example the value passed on s pEMP_GROUP_CODE a condition itself as 'and table.column = 'constant', which can be zero, so if you have a value, it adds a condition, otherwise just empty space and the condition is spared.

  • Need help tuninng a dynamic query

    Hello

    We have following question

    Select s.* s bose_sites.registration_crm_serial_number

    R2 bose_sites.registration_crm_serial_number left on join

    s.serialnr = r2.shipserialnr

    where s.shipserialnr is null

    and (r2.serialnr = ' 052378332000138AE' or (s.serialnr =)

    (( "052378332000138AE" and s.shipserialnr is null))

    which takes about 40 seconds to execute with the values highlighted in bold being dynamic values

    If anyone can help reduce the run time on this request.

    There are indexes created on table

    INDEX_NAME INDEX_TYPE

    ------------------------------ ---------------------------

    IDX_REG_CRM_SER_NUM_CPC NORMAL

    IDX_REG_CRM_SER_NUM_SHIPDATE NORMAL

    IDX_REG_CRM_SER_NUM_PARENT_ID NORMAL

    IDX_REG_CRM_SER_NUM_ID NORMAL

    is it possible that we can capture a dynamic query using DBMS_SQLTUNE

    all suggestions will be useful.

    Hello

    You have one table here

    -------------------------------------------------------------------------------

    Schema name: SYS

    SQL ID: cf2875zz4q4nd

    SQL text: select s.* bose_sites.registration_crm_serial_number s

    R2 bose_sites.registration_crm_serial_number left on join

    s.serialnr = r2.shipserialnr

    where s.shipserialnr is null

    and (r2.serialnr = '052378332000138AE' or (s.serialnr =

    S.shipserialnr and "052378332000138AE" is null))

    -------------------------------------------------------------------------------

    then why don't you go for a simple query

    HTH

  • How create/update files when the original Version is based on a query of outer join?

    Hi gurus,


    I created a custom page where I use a table-style area where I question my VO records, based on a query of outer join. This query contains my table looks, where I would like to insert/update records, and joined the table of standard elements, which is external with my custom table.

    When I now question my files in the t, I have a record for each record in the table section, which is ok, but when I 'Refresh' some fields of my custom table and attempt to commit, I get the message "unable to complete the transaction on record. Cause: The record has been deleted by another user. "Action: cancel the transaction and re - query records to get new data.
    The reason why because a record is to be inserted rather than updating because in fact there is not yet in my custom table.

    The reason why I'm using the outer join, is because I don't want the user to create a record for each item one by one.
    There is no work around for this?

    Thanks in advance!


    BR
    Guy

    Hello
    You can try this.

    In your EntityImpl.java to extend OAPlsqlEntityImpl.

    Override the updateRow() method and coding your insert statement to insert into a table custom here.
    Don't forget, you must ignore the lines for which your custom table columns are null

    -Idris

  • loop chart - the chart is based on another query

    I'm working on a report of BI Publisher. The report displays information for a list of stores (store group, by store - each store page break is a page). Now, we want to add a chart (weekly sales - group per week) for each store, we know there is "table within the group" box, we can use, but our problem is that the chart is based on another query, not the original group by query parent store. Could you please help? Detailed information can be provided if required.

    Please check your Inbox.
    I sent you the answer.

    See you soon

    Jorge
    p.s if this answers your question please give the points and close the message

  • Help! &gt; How to send a dynamic HTML table as an email?

    Hello


    I want to send a dynamic html table as an email


    I'm using php/mysql and I have a mysql database


    I have a table dynaimc restrained some data from the database


    I have a form with a text box to write the email and a button "submit"


    I want to send the picture (or the information in the table) when I send the form


    is this possible?


    Help, please!

    OK, now I have you.  You create a queary to select the data you want, and then copy the following code

    $data = mysqli_query ($dbc, $query) or die (mysqli_error ($dbc));

    While ($row = {mysqli_fetch_array ($data))}

    Mail to the owner of the form

    $header = "from: [email protected]\n".

    . "Reply-To: $email\n";

    $subject = 'DB in emails data';

    $email_to = "[email protected]";

    $message =

    $row ["FirstName"].

    $row ['last_name']

    ;

    }

    mail ($email_to, $subject, $message, $header);

    So, for each column, you will enter in this

    $row ["FirstName"].

    So if the column reported, you would put

    $row ["State"].

    I hope this is the answer you are looking for.

    Gary

  • Help needed dynamic query

    Hai I want dynamic query for framing
    CREATE TABLE PI4 (COR varchar2(1),dep varchar2(3),cod_rc varchar2(2))
    
    insert into pi4(dep,cod_rc) values('A01','5C')
    
    insert into pi4(dep,cod_rc) values('DAC','5L')
    HORN must be updated using dynamic query
    as below
    UPDATE PI4         
            SET
         PI4.COR = ’O’
    WHERE
         PI4.DEP IN ('A01','A02','A03')
    OR
         (
         PI4. dep IN ('DAC','FTS','G12')
         AND
         PI4.COD_RC = '5L'
         )
    sql_stament is that the variable must be set to above code.

    Pls help


    S

    Check below the code where the CO value is assigned dynamically to a p_cor variable

    DECLARE
    v_sql_statement VARCHAR2(32767) := NULL;
    p_cor VARCHAR2(10) := 'O';
    BEGIN
    v_sql_statement := 'UPDATE PI4 SET PI4.COR ='||p_cor||' WHERE (PI4.DEP IN (''A01'',''A02'',''A03'') OR (PI4. dep IN (''DAC'',''FTS'',''G12'') AND PI4.COD_RC = ''5L''))';
    EXECUTE IMMEDIATE v_sql_statement;
    END;
    

    If you do not need dynamic query to perform the update:

    See the code below:

    DECLARE
    p_cor VARCHAR2(10) := 'O';
    BEGIN
    UPDATE PI4 SET PI4.COR =p_cor WHERE PI4.DEP IN ('A01','A02','A03') OR (PI4. dep IN ('DAC','FTS','G12') AND PI4.COD_RC = '5L'));
    END;
    

    Published by: AP on July 27, 2010 03:39

    Published by: AP on July 27, 2010 04:51: end tag code included

  • Dynamic query with wildcard

    Hello

    I have a table1 as below

    ID (NUMBER), keyword (VARCHAR2)
    ----------------------------------------------------
    1, HAS
    2, B
    3, C

    Another table2

    Name (VARCHAR2)
    --------------------------
    Alice
    Bob
    Jack

    I need to write a stored procedure to check if the 2 mactched of the char keyword table1 table name. How to write the dynamic query in my PL/SQL in a stored procedure so that I can generate query similar to

    SELECT * from table2 where name like '%x %' where I need to replace X by the tank in table1

    Help, please.

    Thanks in advance,
    Marry

    I need to write a stored procedure to check if the 2 mactched of the char keyword table1 table name

    You could simply join the tables:

    SQL> with table1  as
    (
     select 1 id, 'A' keyword from dual union all
     select 2 id, 'B' keyword from dual union all
     select 3 id, 'C' keyword from dual
    ),
    table2 as (
     select 'Alice' name from dual union all
     select 'Bob' name from dual union all
     select 'Jack' name from dual
    )
    --
    --
    select * from table1, table2 where name like '%' || keyword  || '%'
    
            ID KEYWORD NAME
    ---------- ------- -----
             1 A       Alice
             2 B       Bob  
    
    2 rows selected.
    
  • How to map Dynamic Query columns on variables of forms.

    Dear all,
    This is a correct code for executing a dynamic query and display data.
    In this program that I have defined variables ("BOLD" of police) later I binds these with the query (in the second code "BOLD").

    How I can map a column in the query, in which case I don't know that the surveyed fields type?



    GetData PROCEDURE IS
    EXEC_SQL connection_id. PORT;
    cursorID EXEC_SQL. CURSTYPE;
    sqlstr VARCHAR2 (1000);

    loc_ename VARCHAR2 (30);
    loc_eno NUMBER;
    loc_hiredate DATE;

    nIgn PLS_INTEGER;

    BEGIN
    connection_id: = EXEC_SQL. DEFAULT_CONNECTION;
    cursorID: = EXEC_SQL. OPEN_CURSOR (connection_id);
    --
    -assuming empno is a primary key for the table emp, where clause ensures
    -only 0 or 1 row is returned
    --
    sqlstr: = "select ename, empno, hiredate from emp;
    -sqlstr: = sqlstr. 'where empno =' | input_empno;

    EXEC_SQL. PARSE (connection_id, cursorID, sqlstr, exec_sql. V7);
    -EXEC_SQL. Bind_variable (connection_id, cursorID, ': bn', input_empno);

    EXEC_SQL. DEFINE_COLUMN (connection_id, cursorID, 1 loc_ename, 30);
    EXEC_SQL. DEFINE_COLUMN (connection_id, cursorID, 2, loc_eno);
    EXEC_SQL. DEFINE_COLUMN (connection_id, cursorID, 3, loc_hiredate);

    --
    -do execute_and_fetch after the analysis of the statement and calling bind_variable and
    -If necessary define_column
    --

    nIgn: = EXEC_SQL. EXECUTE_AND_FETCH (connection_id, cursorID);
    IF (nIgn = 0) THEN
    TEXT_IO. Put_line ('not Rec');
    ELSE IF (nIgn = 1) THEN
    TEXT_IO. Put_line ('found an employee');

    END IF;
    --
    -get the values of this line
    --
    WHILE (EXEC_SQL. FETCH_ROWS (connection_id, cursorID) > 0) LOOP
    -nRows: = nRows + 1;
    EXEC_SQL. COLUMN_VALUE (connection_id, cursorID, 1, loc_ename);
    EXEC_SQL. COLUMN_VALUE (connection_id, cursorID, 2, loc_eno);
    EXEC_SQL. COLUMN_VALUE (connection_id, cursorID, 3, loc_hiredate);

    MESSAGE(loc_ename||) e '|| loc_eno | » '|| loc_hiredate);

    END LOOP;
    END IF;
    END;

    If you want to use EXEC_SQL and a dynamic query with unknown data types, but the known table name,
    Then you can declare a rowtype variable
    for example;

     NOT TESTED ---A ROUGH IDEA
    m_emp_row employee_master%rowtype;
    m_col_cnt number := 0;
    So when you define collumn, create a procedure to find the column name and its width if it is varchar2 with respect to the column name .
       Find the column details from the user_tab_columns table ...
    ---------------------------------------------------------------------------------------------------------------------------------------------------
      while m_col_cnt < 3 loop
           m_col_cnt  := m_col_cnt +1;
           proc_find_col_name_width(p_qry ,p_col_no=>m_col_cnt , p_col_name,p_col_width);
    
          If p_col_name = 'EMPCODE' then
             EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, m_col_cnt , m_emp_row.empcode , p_col_width);
          elsif p_col_name ='EMPNAME' then
             EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, m_col_cnt , m_emp_row.empname , p_col_width);
           -----
            -------
           end if;
      end loop;
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    --Your procedure will look like this
     procedure proc_find_col_name_width(p_qry  varchar2,p_col_no number, p_col_name out varchar2,p_col_width out number) is 
    
     m_col_name varchar2(30);
     Cursor c1 is
     Select  data_length
     from user_tab_columns
     where table_name = 'yr_tab_name'
     and column_name = m_col_name;
     m_lastpos number ;
     m_nxtpos number ;
     Begin
      m_lastpos := instr(p_qry,',',1,p_col_no-1);
      m_nxtpos := instr(p_qry,',',1,p_col_no);
      If m_lastpos = 0 then --- if only one col
         m_col_name := substr(p_qry,instr(upper(P_QRY),'SELECT') + 6, instr(upper(P_QRY),'FROM') -1);
      else
           If m_nxtpos = 0 then ---if last column
                 m_nxtpos := instr(upper(P_QRY),'FROM') -1;
           end if;
    
        m_col_name := substr(p_qry,m_lastpos+1,m_nxtpos);
      End if;
      m_col_name := ltrim(rtrim(m_col_name));
      open c1;
      fetch c1 into p_col_width;
      close c1;
      p_col_name := m_col_name;
    END;
    

    same thing you must apply when retrieving values using exec_sql.column_value
    concerning
    Dora

    Published by: Dora on December 7, 2009 12:20

    Published by: Dora on December 7, 2009 12:20

  • Get the dynamic query alias name

    Hi all

    I have a plsql function using a dynamic query.
    And the function takes an entire sql query as a parameter.

    The main problem is that the function must get what aliases or columns were interviewed.

    For example,.
    FUNCTION_GET_QUERY_ALIAS ('SELECT 1 AS col1, col2 FROM DUAL 2 AS')
    Inside the function, he must find the alias name COL1 and COL2.

    I would be grateful for any help.

    I modified print_table as fact and function to meet your needs.

    SQL> CREATE OR REPLACE TYPE my_column_object AS OBJECT(ruw_number integer, column_name VARCHAR2(1000), column_val VARCHAR2(1000))
      2  /
    
    Type created.
    
    SQL> CREATE OR REPLACE TYPE my_table_type AS TABLE OF my_column_object
      2  /
    
    Type created.
    
    SQL> CREATE OR REPLACE FUNCTION print_table( p_query in varchar2 ) RETURN my_table_type PIPELINED
      2  AS
      3      l_theCursor     INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
      4      l_columnValue   VARCHAR2(4000);
      5      l_status        INTEGER;
      6      l_descTbl       DBMS_SQL.DESC_TAB;
      7      l_colCnt        NUMBER;
      8      l_rcount           INTEGER := 0;
      9  BEGIN
     10      DBMS_SQL.PARSE(  l_theCursor,  p_query, dbms_sql.native );
     11
     12      DBMS_SQL.DESCRIBE_COLUMNS( l_theCursor, l_colCnt, l_descTbl );
     13
     14      FOR i IN 1 .. l_colCnt
     15      LOOP
     16          DBMS_SQL.DEFINE_COLUMN(l_theCursor, i, l_columnValue, 4000);
     17      end loop;
     18
     19      l_status := DBMS_SQL.EXECUTE(l_theCursor);
     20
     21      WHILE ( DBMS_SQL.FETCH_ROWS(l_theCursor) > 0 )
     22      LOOP
     23             l_rcount := l_rcount + 1;
     24          FOR i IN 1 .. l_colCnt
     25          LOOP
     26              DBMS_SQL.COLUMN_VALUE( l_theCursor, i, l_columnValue );
     27
     28              PIPE ROW(my_column_object(l_rcount,l_descTbl(i).col_name,l_columnValue));
     29          END LOOP;
     30      END LOOP;
     31
     32     RETURN;
     33  end;
     34  /
    
    Function created.
    
    SQL> select * from table(print_table('select * from emp'))
      2  /
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             1 EMPNO                7369
             1 ENAME                SMITH
             1 JOB                  CLERK
             1 MGR                  7902
             1 HIREDATE             17-DEC-80
             1 SAL                  800
             1 COMM
             1 DEPTNO               20
             1 DIV                  10
             2 EMPNO                7499
             2 ENAME                ALLEN
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             2 JOB                  SALESMAN
             2 MGR                  7698
             2 HIREDATE             20-FEB-81
             2 SAL                  1600
             2 COMM                 300
             2 DEPTNO               30
             2 DIV                  10
             3 EMPNO                7521
             3 ENAME                WARD
             3 JOB                  SALESMAN
             3 MGR                  7698
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             3 HIREDATE             22-FEB-81
             3 SAL                  1250
             3 COMM                 500
             3 DEPTNO               30
             3 DIV                  10
             4 EMPNO                7566
             4 ENAME                JONES
             4 JOB                  MANAGER
             4 MGR                  7839
             4 HIREDATE             02-APR-81
             4 SAL                  2975
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             4 COMM
             4 DEPTNO               20
             4 DIV                  10
             5 EMPNO                7654
             5 ENAME                MARTIN
             5 JOB                  SALESMAN
             5 MGR                  7698
             5 HIREDATE             28-SEP-81
             5 SAL                  1250
             5 COMM                 1400
             5 DEPTNO               30
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             5 DIV                  10
             6 EMPNO                7698
             6 ENAME                BLAKE
             6 JOB                  MANAGER
             6 MGR                  7839
             6 HIREDATE             01-MAY-81
             6 SAL                  2850
             6 COMM
             6 DEPTNO               30
             6 DIV                  10
             7 EMPNO                7782
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             7 ENAME                CLARK
             7 JOB                  MANAGER
             7 MGR                  7839
             7 HIREDATE             09-JUN-81
             7 SAL                  2450
             7 COMM
             7 DEPTNO               10
             7 DIV                  10
             8 EMPNO                7788
             8 ENAME                SCOTT
             8 JOB                  ANALYST
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             8 MGR                  7566
             8 HIREDATE             19-APR-87
             8 SAL                  3000
             8 COMM
             8 DEPTNO               20
             8 DIV                  10
             9 EMPNO                7839
             9 ENAME                KING
             9 JOB                  PRESIDENT
             9 MGR
             9 HIREDATE             17-NOV-81
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             9 SAL                  5000
             9 COMM
             9 DEPTNO               10
             9 DIV                  10
            10 EMPNO                7844
            10 ENAME                TURNER
            10 JOB                  SALESMAN
            10 MGR                  7698
            10 HIREDATE             08-SEP-81
            10 SAL                  1500
            10 COMM                 0
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            10 DEPTNO               30
            10 DIV                  10
            11 EMPNO                7876
            11 ENAME                ADAMS
            11 JOB                  CLERK
            11 MGR                  7788
            11 HIREDATE             23-MAY-87
            11 SAL                  1100
            11 COMM
            11 DEPTNO               20
            11 DIV                  10
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            12 EMPNO                7900
            12 ENAME                JAMES
            12 JOB                  CLERK
            12 MGR                  7698
            12 HIREDATE             03-DEC-81
            12 SAL                  950
            12 COMM
            12 DEPTNO               30
            12 DIV                  10
            13 EMPNO                7902
            13 ENAME                FORD
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            13 JOB                  ANALYST
            13 MGR                  7566
            13 HIREDATE             03-DEC-81
            13 SAL                  3000
            13 COMM
            13 DEPTNO               20
            13 DIV                  10
            14 EMPNO                7934
            14 ENAME                MILLER
            14 JOB                  CLERK
            14 MGR                  7782
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            14 HIREDATE             23-JAN-82
            14 SAL                  1300
            14 COMM
            14 DEPTNO               10
            14 DIV                  10
    
    126 rows selected.
    
    SQL>
    

    Thank you
    Knani.

    Published by: Karthick_Arp on September 23, 2008 12:11 AM

  • Unit test: is there a way to make the dynamic query of the value of running after the boot process?

    I wonder why the dynamic value query is executed before the boot process? Logically, it makes sense to run after them.

    For example, I test a stored procedure that is supposed to delete a record, and I'd like to create this test report should be deleted as part of the startup process before execution of the stored procedure call to delete this test record. Apparently the dynamic query of value not returns not the test report in as long as the query parameter to call the stored procedure under test, which makes me think that is executed before the startup process of design...

    Please advise...

    Thank you

    Val

    As this thread does no traction/attention of the team of SQL Developer for a while, I had to submit a request for formal improvement on metalink:

    RE: 19834977 - IN THE UNIT TEST REQUEST TO ALLOW TO CHANGE THE ORDER OF EXECUTION OF THE START OF THE PROCESS

    Thank you

    Val

Maybe you are looking for

  • How to delete photos stored in macbook air any of iPhone

    I am on my Macbook Air storage as whenever I backed up my iPhone, I also chose to "import" all the new photos in the iPhone. I think this is redundant with as backup iTune keeps pictures of the iPhone (from thousands of them since 2007)! Now my quest

  • How to make a web page to get the new tab page?

    I go to a web page a lot, but it does not appear as a tile on the new tab page. I got it in the past, but he went. I would like to get back into my tiles.

  • Satellite A500-1GL - Driver NVIDIA GeForce GT300m for Windows 7 32 bit

    Hi, I'm French, I bought this phone 2 weeks ago, and I did a new install of Windows7 32 bit.I'm looking for the display driver (for my Nvidia GeForce GT 300 m), but the only one I found is for Windows 7 64 bit :'( Do you know if Toshiba will realease

  • No tcp connection in tcp Server

    I'm doing labview program to replace a java program on a pc (192.168.1.88). The first step is that the program starts a tcp server, then a (192.168.1.44) client will connect to. The java program works very well, but my program of all time of waiting

  • Mismatch in number of brother COD files

    I'm developing an application of BB. Because my application size is more than 64 k, compiler generates a zipped file of COD. When I check the JAD file it has reference to 8 records of COD brother named in the order as "MyApp.COD", "MyApp - 1.COD '...