What is Dynamic query object ?

Hi All,
I want to know what is the exact purpose of a Dynamic Query object ?
Why cant we use a simple Query object instead ?
Regards,
Ashish

Hello experts,
i modified the method EH_ONSEARCH in the class ZL_BT111S_O_SEARCH_IMPL. This is the opportunity search.
We want to exclude the process type ZCRA. I realized this with following code snippet:
CALL METHOD lr_qs->add_selection_param
      EXPORTING
        iv_attr_name = 'PROCESS_TYPE'
        iv_sign      = 'I'
        iv_option    = 'NE'
        iv_low       = 'ZCRA'.
There is also a field in the search mask for selecting the process type. For example, i select the process type ZOPP in the mask. If i do this, i get ALL opportunites. I found the reason. The search query looks like this:
PROCESS_TYPE      I      NE     ZCRA
OR <--- this is the error
PROCESS_TYPE     I       EQ      ZOPP
How can i make an AND-conjunction? The dynamic search object BTQOPP has an parameter MATCH_TYPE but i dont know how to fill out this parameters?
Best regards
Sascha Federau

Similar Messages

  • How to enhance Dynamic Query Object TerrSearch (Territory Management)?

    Hello Friends,
    In the TerrSearch dynamic query object, There are 2 fields Territory_ID and Level_ID. Now i have a requirement to Enhance the Search object using the new field called TERRITORY PATH ID. using which we can search all the entities not only for the terrritory level which we have selected (for example we have assigned the value '01' to LEVEL_ID) but also all the below territory levels of selected territory level.
    If we enhance the search object structure CRMST_TMIL_SEARCH (structure of TerrSearch object) using AET to add the Z field called TERRITORY_PATH_ID then which is the suitable BADI where we can add the necessary code to select all the entities based on all the territory levels below the selected territory level.
    Please guide me friends how to enhance the TerrSearch object.

    Hi friend,
    Try using MACRO and dynamic WHERE condition.
    Group simialr Select statements under a Macro.
    Build a dynamic where by checking conditions
    Call macro passing dynamic where condition.
    TABLES afpo.
    DATA: str TYPE string.
    *Macro definition
    DEFINE operation.
      select single *
           from afpo into afpo
           where (&1).    " Dynamic condition
    END-OF-DEFINITION.
    *Build dynamic WHERE by checking some conditions
    *If conditon 
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
    *Else
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
    *Endif.
    *Call Macro passing dynamic WHERE condition
    operation str.

  • Enhancing a Dynamic Query Object

    Hi All,
    I've added a new field to the contract header using the EEWB, I then added the field to an append on the dynamic query object BTQSrvCon. The entry in CRMC_REPDY and the BADI implementation of BADI CRM_RF_SEARCH_EEW have been created automatically.
    This is working fine when I use the 'IS' separator on the search screen and enter the field exactly.
    I would like to use the dynamic query separators (contains, starts with etc.) but when I try I get the error message
    Search contains fields where wild card search is not allowed
    Has anyone implemented this functionality?
    Thanks,
    Gregor

    The range operator is in the generated code:
    method IF_EX_CRM_RF_SEARCH_EEW~EXTEND_RF_QUERY.
    INCLUDE crm_object_names_con.
    DATA: lv_fieldname       TYPE name_komp,
           ls_qupart          LIKE LINE  OF ct_quparts,
           ls_qupart_and      LIKE LINE  OF ct_quparts,
           ls_range_value     TYPE crmt_bsp_range.
    READ TABLE it_range_value INDEX 1
       INTO ls_range_value.
    IF sy-subrc <> 0.
       RETURN.
    ENDIF.
    CHECK NOT ls_range_value-low IS INITIAL.
    CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
       EXPORTING
         iv_token  = 'AND'
       IMPORTING
         ev_qupart = ls_qupart_and-querypart.
    lv_fieldname = flt_val.
    CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
       EXPORTING
         iv_entityname = gc_objectname_reporting-ORDERADM_H
         iv_fieldname  = lv_fieldname
         iv_token      = 'RAN'
         it_rangetab   = it_range_value
       IMPORTING
         ev_qupart     = ls_qupart-querypart.
    APPEND ls_qupart     TO ct_quparts.
    APPEND ls_qupart_and TO ct_quparts.
    endmethod.
    I've put a break in the code which is not being triggered so something may be up with the BADI implementation.

  • Change the attribute structure of a dynamic query object

    Hi,
    As seen below, the attribute structure is a Z structure..
    I want to revert/change it to the std structure CRMT_BUPA_IL_HEADER_SEARCH
    I don't find any display/change buttons there...how do I achieve it?
    Thanks
    Madhukar

    HI Deepika,
    Thanks For your reply...
    My component - BT116S_SRVO.
    I have added Customer appointment date and customer appointment time and prodcut delivery statud date and prodcut delivery time in service order reslut screen.By using AET i have created all the feilds and ihave added same fields in result screen...
    Now in component - BT116S_SRVO , ihave implemented the logic of getter method of CUSTOMER appointment date is as follows.,Now date and time is coming..but it is perfromance problem na..so for avoid this issue we need to do in BADI implementation rite?could you please tell me the steps and how to implement the logic..please help
    GETTER METHOD
    DATA: current TYPE REF TO if_bol_bo_property_access.
    DATA: dref TYPE REF TO data,
    lv_guid TYPE crmt_genil_object_guid.
    value = ' '. "#EC NOTEXT
    IF iterator IS BOUND.
    current = iterator->get_current( ).
    ELSE.
    current = collection_wrapper->get_current( ).
    ENDIF.
    lv_guid = current->get_property_as_string( iv_attr_name = 'GUID' ).
    DATA : lr_current TYPE REF TO cl_crm_bol_entity,
    lr_parent TYPE REF TO cl_crm_bol_entity.
    * lv_guid TYPE crmt_genil_object_guid.
    DATA : lv_appt_type TYPE string.
    DATA : lv_time_from TYPE string.
    DATA:
    lt_header_guid TYPE crmt_object_guid_tab,
    lt_orderadm_h TYPE crmt_orderadm_h_wrkt,
    lt_orderadm_i TYPE crmt_orderadm_i_wrkt,
    ls_requested TYPE crmt_object_name,
    lt_requested TYPE crmt_object_name_tab,
    lt_appointment_wrk TYPE crmt_appointment_wrkt,
    ls_appointment_wrk TYPE crmt_appointment_wrk.
    INSERT lv_guid INTO TABLE lt_header_guid.
    ls_requested = 'APPOINTMENT'.
    INSERT ls_requested INTO TABLE lt_requested.
    * append ls_requested to lt_requested.
    CALL FUNCTION 'CRM_ORDER_READ'
    EXPORTING
    it_header_guid = lt_header_guid
    it_requested_objects = lt_requested
    IMPORTING
    * et_orderadm_h = lt_orderadm_h
    et_appointment = lt_appointment_wrk
    * CHANGING
    * CV_LOG_HANDLE =
    EXCEPTIONS
    document_not_found = 1
    error_occurred = 2
    document_locked = 3
    no_change_authority = 4
    no_display_authority = 5
    no_change_allowed = 6
    OTHERS = 7.
    IF sy-subrc <> 0.
    * Implement suitable error handling here
    ENDIF.
    READ TABLE lt_appointment_wrk INTO ls_appointment_wrk WITH KEY appt_type = 'ZCST_APT'.
    IF sy-subrc EQ 0.
    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
    EXPORTING
    date_internal = ls_appointment_wrk-date_from
    IMPORTING
    date_external = value
    EXCEPTIONS
    date_internal_is_invalid = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    * Implement suitable error handling here
    ENDIF.
    ENDIF.
    Thanks
    Kalpana

  • Is there any way to create Dynamic Query??

    Hi All,
    Can we create a Dynamic Query object for Z-Table.
    Thanks in Advance.
    Regards,
    Ravi Teja

    Hi Jotsaroop,
    We have created a Simple object to create a custom table view in the Appointment page.
    Now client wants a search help pop-up for one of the attribute in the view.
    By creating a simple object we are having normal query object.
    But we required dynamic query for the same.
    Thanks in advance for your inputs.
    Regards,
    Ravi

  • What is the search object for activityH?

    Hello,
    I need to display a list of activity with some custom filter logic from the table crmd_activity_h. I think i am enhancing the component CRM_ICM_ACT_H / HeaderEOF (or make new one by copying it). There is no search functionality here, so I will be adding logic in a new inbound plug to search activityH to retrieve data fro the context node BTACTIVITYH. However I could NOT find any query object that returns ACTIVITYH object.
    I know there are components like BT126S-APPT and BT126P_appt, with query BTQACT or query BTquery10, but those query objects return BO that do not fit my requirement. I need query object that returns BO for table crmd_activity_h.
    Anyone can help for this? or anyone think other component should be enhanced instead of CRM_ICM_ACT_H / HeaderEOF?
    Thanks
    Jayson

    Hi Jayson,
                      Please have a look at Dynamic Query Object BTQAct  and Query Result Object BTQRAct with Attribute Structure CRMST_QUERY_R_ACT_BTIL
    It's corresponding Genil class for Query is CL_CRM_QACT_RUN_BTIL, method: IF_CRM_QUERY_RUNTIME_BTIL~GET_DYNAMIC_QUERY_RESULT
    It has been implemented in Component: BT126S_APPT
    View:BT126S_APPT/ApptSQ
    Method: EH_ONSEARCH
    I hope it helps.
    Thanks,
    Rohit

  • How to create custom BOL object for dynamic query in CRM 7.0

    Hi,
    Could anyone please explain me with steps that how to create the custom BOL object for dynamic query in CRM 7.0, I did it in previous version but its throwing exception when i try to create the object of my dynamic query class. I just defined the entry of my in crmv_obj_btil to create the dynamic query BOL object. do i need to do any other thing also to make it work?
    Regards,
    Kamesh Bathla
    Edited by: Kamesh Bathla on Jul 6, 2009 5:12 PM

    Hi Justin,
    First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
    In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
    Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
    Thanks in Advance,
    mallikj2.

  • Query a stored procedure that exec's a dynamic query. Error Linked server indicates object has no columns

    I have a stored procedure that dynamically creates a pivot query.  The procedure works and returns the correct data.  Now I have a requirement to show this data in reporting system that can only pull from a table or view.  Since you can not
    create a dynamic query in a view I tried to do a select from using openquery. 
    Example 'Select * from OpenQuery([MyServername], 'Exec Instance.Schema.StoredProcedure')
    I get the error back "the linked server indicates the object has no columns".  I assume this is because of the first select statement that is stuffing the variable with column names. 
    CODE FROM PROCEDURE
    Alter PROCEDURE [dbo].[Procedure1]
    AS
    BEGIN
    SET NOCOUNT ON
    Declare @cols nvarchar(2000),
      @Tcols nvarchar(2000),
      @Sql nvarchar (max)
    select @cols = stuff ((
          Select distinct '], ['+ModelName + '  ' + CombustorName
           from CombustorFuel cf
           join Model m on cf.modelid = m.modelid
           join Combustors cb on cf.CombustorID = cb.CombustorID
           where cf.CombustorID > 0
           for XML Path('')
          ),1,2,'')+']'
    Set @Tcols = replace(@Cols, ']', '] int')
    --Print @Tcols   
    --Print @Cols
    Set @Sql = 'Select GasLiquid, FuelType, '+ @Cols +'
    from
     Select GasLiquid, FuelType, ModelName+ ''  '' +CombustorName ModelCombustor, CombFuelStatus+''- ''+CombFuelNote CombFuelStatusNote
      from Frames f
      join Family fa on f.Frameid = fa.frameid
      join Model m on fa.FamilyID = m.FamilyID
      join CombustorFuel cf on m.Modelid = cf.modelid
      Join Combustors c on cf.CombustorId = c.CombustorID
      join FuelTypes ft on cf.FuelTypeID = ft.FuelTypeID
      where cf.CombustorFuelID > 0
        and CombustorName <> ''''
     ) up
    Pivot
     (max(CombFuelStatusNote) for ModelCombustor in ('+ @Cols +')) as pvt
    order by FuelType'
    exec (@Sql)

    Then again, a good reporting tool should be able to do dynamic pivot on its own, because dynamic pivoting is a presentation feature.
    SSRS Supports dynamic columns: Displaying Dynamic Columns in SSRS Report
    SQL Reporting Services with Dynamic Column Reports
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
    Displaying and reading are two very different things.
    #1) SSRS Needs a fixed field list on the input side to know what what to make available in the designer.
    #2) SSRS cant read "exec (@Sql)" out of a proc, even if there is a fixed number of columns (at
    least it can't use it to auto build the field list from the proc)
    I use dynamic SQL in my report procs on a fairly regular basis and I've found it easiest to simply dump
    the results of my dynamic sql into a temp table at the end of the procs and then select from the temp table.
    Basically, Erland is correct. Stop trying to pivot in the query and let SSRS (or whatever reporting software you're using) handle it with a Martix.
    Jason Long

  • What are the query types,Objects CRM provides for third party

    What are the query types,Objects provided by the CRM so that it can be called by third party for integartion pupose.

    First, that statement - and those materials - refer to the "legacy" StreamInsight query/adapter model. They do not refer to how things work with the Reactive model introduced in version 2.1. Specifically, it talks about Dynamic Query Composition (DQC).
    You cannot use a deployed Observable in another instance of StreamInsight. You may be able to use them across applications in the same instance - off the top of my head, I'm not sure. I'm getting ready to get on a plane but will take a look at it later.
    Typically, however, applications act as containers (comparable to .NET AppDomains) so I don't think that you'd be able to do this easily. That said, the code and assemblies
    can be reused across multiple instances/applications. You would have separate instances of the classes involved but you would be able to reuse the query logic. That's a common use case.
    Can you be more specific about your use case and what you are trying to accomplish here? It's possible that there are alternative ways to do what you are trying to do.
    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)
    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

  • Issue in attaching dynamic Query to the View Object

    Hi,
    We are having a View Object attached to the JRAD page.
    The View object is build thru as Expert mode. There is no any CDATA
    SQLQUERY stored in the VO.xml file.
    We are building the query dynamically and attaching it to the VO in
    RUNTIME.
    The code is as below
    // getFcstQuery() is method used to return the dynamic query
    String query = getFcstQuery();
    // Setting the Query to View Object
    getViewDef().setQuery(query);
    setQuery(query);
    The JRAD page has sorting option on 5 columns. so when a sorting is
    done the data are interchanged between the clients.
    For example how the query will be build id
    Say for the first user the query will be as
    "select ename,eno,dno from emp where eno=1 "
    for the second user the query may be
    "select ename,eno,dno from emp where eno=2 "
    Now if both the user hit the sorting on any of the column the data is
    interchagned between this both users.
    Please provide solution if possible.
    Thanks in advance
    Balamohan

    Hi Steve,
    We are using 5 tables in building the query.
    Say,
    1) summary
    2) transactions
    3) transactions_history
    4) rules
    5) rules_temp
    but only 2 tables are used at a time
    for read only we are using
    summary table
    for edit only mode we are using
    1) transactions and
    2) rules
    tables
    for edit and recalculate mode we are using
    1) transactions and
    2) rules_temp
    tables
    for one more condition we are using
    1) transactions_history and
    2) rules
    tables
    From all the above combination we are getting 5 columns. All the columns are defined the above combination tables. So using the same region. based on the conditions the combination of tables will change.
    Becoz of this we are building the query dynamically.
    Thanks
    Balamohan

  • How to create dynamic View Object and Dynamic Table

    Dear ll
    I want to create a dynamic view object and display the output in a dynamic table on the page.
    I am using Jdeveloper 12c "Studio Edition Version 12.1.2.0.0"
    This what I did:
    1- I created a read only view object with this query "Select sysdate from dual"
    2- I added this View object to the application module
    3- I created a new method that change the query of this View object at runtime
        public void changeVoQuery(String dbViewName) {
            String sqlstm = "Select * From " + dbViewName;
            ViewObject dynamicVo = this.findViewObject("DynamicVo");
            if (dynamicVo != null) {
                dynamicVo.remove();
            dynamicVo = this.createViewObjectFromQueryStmt("DynamicVo", sqlstm);
            dynamicVo.executeQuery();
    4- I run the application module for testing the method and I passed "Scott.Emp" as a parameter and the result was Success
    5- Now I want to show the result of the view on the page, so I draged and dropped the method from the data control as a parameter form
    6- I dragged and dropped the view Object "DynamicVo" as a table and I choose "generate Column Dynamically at runtime". This is the page source
    <af:panelHeader text="#{viewcontrollerBundle.SELECT_DOCUMTN_TYPE}" id="ph1">
            <af:panelFormLayout id="pfl1">
                <af:inputText value="#{bindings.dbViewName.inputValue}" label="#{bindings.dbViewName.hints.label}"
                              required="#{bindings.dbViewName.hints.mandatory}"
                              columns="#{bindings.dbViewName.hints.displayWidth}"
                              maximumLength="#{bindings.dbViewName.hints.precision}"
                              shortDesc="#{bindings.dbViewName.hints.tooltip}" id="it1">
                    <f:validator binding="#{bindings.dbViewName.validator}"/>
                </af:inputText>
                <af:button actionListener="#{bindings.changeVoQuery.execute}" text="changeVoQuery"
                           disabled="#{!bindings.changeVoQuery.enabled}" id="b1"/>
            </af:panelFormLayout>
        </af:panelHeader>
        <af:table value="#{bindings.DynamicVo.collectionModel}" var="row" rows="#{bindings.DynamicVo.rangeSize}"
                  emptyText="#{bindings.DynamicVo.viewable ? 'No data to display.' : 'Access Denied.'}"
                  rowBandingInterval="0" selectedRowKeys="#{bindings.DynamicVo.collectionModel.selectedRow}"
                  selectionListener="#{bindings.DynamicVo.collectionModel.makeCurrent}" rowSelection="single"
                  fetchSize="#{bindings.DynamicVo.rangeSize}" filterModel="#{bindings.DynamicVoQuery.queryDescriptor}"
                  queryListener="#{bindings.DynamicVoQuery.processQuery}" filterVisible="true" varStatus="vs" id="t1"
                  partialTriggers="::b1">
            <af:iterator id="i1" value="#{bindings.DynamicVo.attributesModel.attributes}" var="column">
                <af:column headerText="#{column.label}" sortProperty="#{column.name}" sortable="true" filterable="true"
                           id="c1">
                    <af:dynamicComponent id="d1" attributeModel="#{column}"
                                         value="#{row.bindings[column.name].inputValue}"/>
                </af:column>
            </af:iterator>
        </af:table>
    when I run the page this error is occured
    <Nov 13, 2013 2:51:58 PM AST> <Error> <oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter> <BEA-000000> <ADF_FACES-60096:Server Exception during PPR, #1
    javax.el.ELException: java.lang.NullPointerException
    Caused By: java.lang.NullPointerException
    Can any body help me please
    thanks

    Have you seen Shay's video https://blogs.oracle.com/shay/entry/adf_faces_dynamic_tags_-_for_a
    All you have to do is to use the dynamic table to get your result.
    Timo

  • Paging issues using a dynamic view object...

    I am working on an application that uses JAG to generate JSP pages, i had the requirement to use dynamic view objects where the view object query is generated at runtime. The rest of the application is more or less the same... I used the defult functionality provided by TableScrollButtons.jsp file for paging. Now the problem im facing is that while the '>' and '<' buttons are working fine, i cant seem to navigate to the pages using the drop down...
    With the default handler, whenever i select the range the range displayed remains the same ie 1-10, 10 being the rangesize, but the rows are refreshed with values from the next page. Also, if the next page is the last and is incomplete, then the rows are pushed in from the bottom, so that the last page is always full...I tried the tuning panel in the view object edit dialogue and all settings are fine (i think)...could anyone please tell me what i am doing wrong??

    could it be because i am using a dynamic view object with dynamic bindings? i am using the preparemodel() method in the action as follows...
    protected void prepareModel(DataActionContext ctx) throws Exception {
    inferRangeBindingIfUnset(ctx);
    ctx.getBindingContainer().setEnableTokenValidation(false);
    String sql = ctx.getHttpServletRequest().getParameter("sql");
    String cost=ctx.getHttpServletRequest().getParameter("CostCostCent");
    String event=ctx.getHttpServletRequest().getParameter("event");
    if (sql != null && event == null) {
    setupDynamicQueryAndDynamicBindings(ctx,sql.substring(1),cost);
    if (retrieveOnlyCurrentPageFromDatabase()) {
    ViewObject vo = getIterForPaging(ctx).getViewObject();
    if (vo.getAccessMode() != ViewObject.RANGE_PAGING) {
    vo.setAccessMode(ViewObject.RANGE_PAGING);
    // if(event==null)
    super.prepareModel(ctx);
    ctx.getBindingContainer().setEnableTokenValidation(true);
    if (ctx.getEvents() == null || ctx.getEvents().size() ==0) {
    setPage(ctx,1);
    setLastPage(ctx,getIterForPaging(ctx).getRowSetIterator().getEstimatedRangePageCount());
    else if(event.equals("setRangeStart")) {
    setPageFromRequest(ctx);
    }

  • Using 2 tables framing of dynamic query wherein columns are decided runtime

    Hi Team,
    I had a requirement could anyone help me out or suggest your views. we are using Adf faces as UIlayer and Toplink for dataaccess. In that we had 2 tables systemdefinedTable and userdefinedTable which has one-to-one relation. Userdefinedtable has columns col1,col2,col3.......col50 and this comes at runtime from xml like col1 as Lastname,col2 as firstname.
    Now we need to generate a dynamic query that joins the systemdefinedTable and userdefinedTable to produce the result for the UI layer. Now suppose if the xml has 2 cols tag.
    The dynamic query may look like this:
    Select S.ID, S.NAME, S.STATUS, U.COL1 as FirstName, U.COL2 as LastName
    From userdefinedTable U, systemdefinedTable S
    Where S.QID = U.QID
    Next if the xml has 3 more column tags then COL1,COL2,COL3 ...like wise columns will be decided runtime..So please share your views or any related blogs to achieve this.
    Thanks in Advance for your help.

    Hello,
    If you are using TopLink and need dynamically generated queries, why not use TopLink Expressions for your queries, and return java objects back. Then you can display which ever fields from the fully populated objects that you need.
    See the docs for TopLink queries here:
    http://docs.oracle.com/cd/E17904_01/web.1111/b32441/qryun.htm#autoId28
    A simple example returning all systemdefinedObjects would be:
    ReadAllQuery query = new ReadAllQuery(systemdefinedObject.class);
    query.addJoinedAttribute(query.getExpressionBuilder().get("user"));
    Collection<systemdefinedObject> results = session.executeQuery(query);
    This allows populating the cache and for caching the statements and the query results.
    But I'm not sure exactly what you are after.
    Best Regards,
    Chris

  • Get alias name from dynamic query

    Hi All,
    I would make a plsql function using dynamic query.
    And the function takes a whole sql query as a parameter.
    The main issue is that the function should get what alias or columns were queried.
    For example,
    FUNCTION_GET_QUERY_ALIAS('SELECT 1 AS col1, 2 AS col2 FROM DUAL')
    Inside the function, it should find the alias name COL1 and COL2.
    I'd appreciate for any help.

    I have modified print_table as function and made it to satisfy 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>Thanks,
    Karthick.
    Edited by: Karthick_Arp on Sep 23, 2008 12:11 AM

  • How to find table name(s) in a dynamic query

    In one of our (9iAS PORTAL)applications, any user can able to run their query statment and get output. All queries will be executed as dynamic SQL thru' a common shema/user who has 'SELECT' privilege on all tables but all users don't have this privilege on all tables. Now, before executing any query I need to find out what are the table name(s) used in this query to check the privilege for the respective user. How do I extract all table names being used in a dynamic query?.
    Thanks
    -Krishnamurthy

    I guess that his users log in to application first, then application uses one account to log in to database, so application are not direct database user since all users share the same account to database. If so, when a user lgins in, you may write it down from application to a database audit table, and you need to write down the dynamic query to the database audit table too, then you may query that audit table to find out. up to here, it looks that your application has to do more to assign what role to a user running the application, since database does not know what user is assessing it.

Maybe you are looking for