Query Build problem in Native Dynamic SQL

I am writing a procedure to calculate the summary from the monthly salary table by dynamically building the query using ref cursor,open cursor using the bind variables and bulding the query statement.But the query is not returning any rows
vSQL := 'select a.ad_code,a.acc_code,m.jobtype,m.estbtype,'||'sum(m.'||vabsrec.vadsn||') from gencopayroll.pay_allowaccounthead a,'||
'gencopayroll.pay_monthly_paybill m where bill_type = :ptype and loc_id = :plocid '||
'and processing_period = :pprocmon and a.ad_code = :padcode group by a.acc_code,'||
'm.jobtype,m.estbtype,a.ad_code';

I am writing a procedure to calculate the summary
from the monthly salary table by
1) dynamically building the query using ref cursor
2) open cursor using the bind variables
3) bulding the query statement.Can you show us the code that performs these steps.
Once a cursor is opened you need to fetch the rows from it in order to get the data.
Also, have you checked that the query runs as plain non-dynamic SQL within SQL*Plus with the same parameters, to see that it returns data?
What is you purpose for using Dynamic SQL? If you clarify the requirement we may be able to show you how to do the same using non-dynamic SQL.

Similar Messages

  • What is the problem with native dynamic sql when counting rows in all table

    what is the problem with native dynamic sql when counting rows in all table?Giving an error "table or view does not exist". Thanks.
    DECLARE
    v_sql_string varchar2(1000);
    v_no_of_rows number;
    BEGIN
    for i in ( select table_name from all_tables )
    loop
    v_sql_string := ' select count(1) from ' || i.table_name;
    dbms_output.put_line( v_sql_string );
    --execute immediate v_sql_string into v_no_of_rows;
    end loop;
    END;

    Usually your problem can be described with 'Who cares'. I mean, for what reason do you do this? I doubt that there's a business need to get 100 % accurate answers for this. Normally such things are used to get a picture about the growth of data.
    Personally I would prefer to have up-to-date statistics for all tables and just query the number of rows from there. Sufficient for me in < 99 % of all cases.
    Just my $ .02...

  • Query Builder problem with saving to SQL text file

    When developing an SQL statement in Query Builder and saving it for later use, one has the option of saving in .SQL file extension. However, this file can not be used by the data wizard of Oracle*Reports because it contains non-ascii text. It appears that the Query Builder saves commands as binary tokens rather than in ascii text.
    This makes it impossible to use Query Builder in place of Oracle*Report's data wizard's query builder with which to build and save SQL statements.

    as i posted earlier .. queryBuilder as a stand alone product is neither supported nor available anymore. it is only available as part of the report data wizard.
    thanks,
    ph.

  • Workaround for opening a strongly typed cursor using native dynamic SQL

    Hi All,
    In reading the PL/SQL documentation for Oracle 9i, I noted that the OPEN-FOR
    statement with a dynamic SQL string only allows the use of weakly typed cursors.
    I have verified this limitation with my own experimentation as follows:
    DECLARE
    type rec_type is record(
    str     varchar2(40),
    num     number(22)
    type cur_type is ref cursor return rec_type;
    my_cur     cur_type;
    que     varchar2(100);
    tab     varchar2(40);
    BEGIN
    tab := 'dynamic_table_name';
    que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
    open my_cur for que;
    loop
    if my_cur%found then
    dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
    exit;
    end if;
    end loop;
    close my_cur;
    END;
    Running the above trivial example in an anonymous sql block yields the following
    errors as expected:
    ORA-06550: line 10, column 8:
    PLS-00455: cursor 'MY_CUR' cannot be used in dynamic SQL OPEN statement
    ORA-06550: line 10, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 13, column 54:
    PLS-00487: Invalid reference to variable 'MY_CUR'
    ORA-06550: line 13, column 7:
    PL/SQL: Statement ignored
    Is there a workaround to the situation? Since I do not know the table name at run
    time, I must use Native Dynamic SQL. I have a long and complex record type
    that I wish to return through JDBC using the REFCURSOR Oracle type in order to
    avoid having to register an inordinate number of OUT parameters. Moreover, I
    would like to return potentially one or more results in a ResultSet. Using the
    standard method of registering native SQL types for the IN and OUT bindings
    can only return one result. Hence the reason I would like to return a strong
    cursor type. Also, the type of query I am doing is complex, and needs to be
    executed in a PL/SQL procedure for performance reasons. Therefore simply
    executing a SELECT query dynamically built up on the the JDBC client won't
    do the trick.
    If anybody has experience with a similar problem and would like to volunteer
    information on their workaround, I would really appreciate it.
    Best Regards,
    J. Metcalf

    We can use strongly-typed REF CURSORs in DNS, but the typing derives from a table e.g.
    TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
    so the problem is your use of "return rec_type" bit.
    Forgive my bluntness but I think you have misunderstood strong and weak typing. You actually want to be using weakly-typed cursors. I mean this:
    Moreover, I would like to return potentially one or more results in a ResultSet. suggests that the structure of your resultset may vary, which is precisely what a weakly-typed ref cursor allows us to do. Then we can use the JDBC metadata methods to interrogate the structure of the resultset, innit.
    so try this:
    DECLARE
    type cur_type is ref cursor;
    my_cur cur_type;
    que varchar2(100);
    tab varchar2(40);
    BEGIN
    tab := 'dynamic_table_name';
    que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
    open my_cur for que;
    loop
    if my_cur%found then
    dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
    exit;
    end if;
    end loop;
    close my_cur;
    END;
    ras malai, APC
    Cheers, APC

  • Using Native Dynamic SQL in Forms

    Can Native Dynamic SQL be used in Forms 5.0 or Forms 6.0? (Database 8.1.6.0.0)
    I have tried the following code (examples below) from the PL/SQL User's Guide and Reference Release 8.1.6 and the Metalinks Note: 62592.1 and the trigger/procedure (in Forms) will not compile. I appreciate any help given.
    Example1:
    (I have a table named temp_jane with a column named companies and a value 'Hello'. When compiling, I receive the error: 'Error 103 at line 8, column 11 Encountered the symbol ''IMMEDIATE" when expecting one of the following :=.(@%; ')
    declare
    str varchar2( 200 );
    val varchar2( 20 );
    ret temp_jane%rowtype;
    begin
    str := 'select company from temp_jane where company = :b1';
    val := 'Hello';
    execute immediate str into ret using val;
    message('Value fetched from table: '&#0124; &#0124;ret.company);
    end;
    Example2:
    (Here is the real issue, I don't know what the select statement, so I need to be able to assign a variable. When compiling, I receive the error: 'Error 103 at line 28, column 21 Encountered the symbol "VSQLSTATEMENT" when expecting one of the following: select ').
    declare
    type ItemsControlCurTyp is ref cursor;
    ItemsCur ItemsControlCurTyp;
    ItemsRec Items%rowtype;
    vSQLStatement varchar2( 5000 );
    vExecuteSQL varchar2( 5000 );
    vNumRows integer;
    vValue varchar2( 2000 );
    vFirstOne varchar2( 1 ) := 'Y';
    vRetval varchar2( 2000 );
    begin
    -- Display the column prompts with the right text.
    set_item_property( 'ITEMS_AVAILABLE.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.AVAILABLE_LABEL );
    set_item_property( 'ITEMS_CHOSEN.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.CHOSEN_LABEL );
    -- Save the original version of CHOSEN_STRING in case the user reverts or cancels.
    :ITEMS_CONTROL.CHOSEN_STRING_ORIG := :ITEMS_CONTROL.CHOSEN_STRING;
    vSQLStatement := :ITEMS_CONTROL.SELECT_STATEMENT;
    vExecuteSQL := vSQLStatement;
    -- Open the cursor
    open ItemsCur for vSQLStatement;

    Hi JTaylor
    You cannot use NDS in Client side (Developer). You have to use DBMS_SQL only.
    Regards
    A K Srinivasan
    Oracle.

  • Alternative to native, dynamic sql to return a ref cursor to a client

    I'm on Oracle 8.0.4, and would like to pass a string of values like '1,2,7,100,104' that are the primary key for a table. Then use something like:
    procedure foo( MyCur RefCurType, vKey varchar2)
    begin
    open MyCur for
    'select names from SomeTable' &#0124; &#0124;
    ' where ID in (' &#0124; &#0124; vKey &#0124; &#0124; ')'
    end;
    This would return a recordset to (in this case) a Crystal Reports report.
    However, native dynamic SQL ain't available until 8.1.0. So can anyone think of a clever way to accomplish this, with a way to return a cursor? I can't figure out how to do this with DBMS_SQL, because open_cursor is just returning a handle, not a referene to a cursor that can be passed to a remote client.
    Thanks in advance.

    I'm on Oracle 8.0.4, and would like to pass a string of values like '1,2,7,100,104' that are the primary key for a table. Then use something like:
    procedure foo( MyCur RefCurType, vKey varchar2)
    begin
    open MyCur for
    'select names from SomeTable' &#0124; &#0124;
    ' where ID in (' &#0124; &#0124; vKey &#0124; &#0124; ')'
    end;
    This would return a recordset to (in this case) a Crystal Reports report.
    However, native dynamic SQL ain't available until 8.1.0. So can anyone think of a clever way to accomplish this, with a way to return a cursor? I can't figure out how to do this with DBMS_SQL, because open_cursor is just returning a handle, not a referene to a cursor that can be passed to a remote client.
    Thanks in advance.

  • Visual Query Builder problem

    I have the trail version of Flex Builder 2 IDE. I can run the
    RDS, and do manual SQL queries. But when I click on the Visual
    Query Builder button, nothing happens - not even an error message.
    When I try to use the ColdFusion/Flex application Wizard, I can get
    to the Page Layout and Design screen. Then when I click on the Edit
    Master Page or Edit Detail Page button, again, nothing happens. I
    think this also uses the Visual Query Builder, so maybe that's why
    it isn't working.
    Is there something extra I didn't download or setup?
    Thanks for your help.
    Scott

    Hi,
    I have the exact same problem and it is getting really
    annoying. I'm running Vista, maybe thats why?
    Regards
    //Morgan

  • Query Builder problem - query results from previous query

    Hi.
    I have a 100% repeatable problem in Oracle Query Builder (Version 6.0.7.1.0) where some rows from the results of a previous query appear in the results for the current query. The queries being run are saved in *.brw files. If I close down Query Builder completely between queries, there is no problem. If I run one query, export the results to a CSV file, close that query and then open a second query, when I run the second query there are rows in the results that shouldn't be there (they are remnants of the first query). Interestingly the total number of rows for the second query is correct, so the same number of rows are missing as shouldn't be there. Anyone come across this before? Problem is repeatable for different database users and on different computers.
    regards,
    Martin

    as i posted earlier .. queryBuilder as a stand alone product is neither supported nor available anymore. it is only available as part of the report data wizard.
    thanks,
    ph.

  • Query Builder Problem

    I don't know if this is a bug or not, but I just found this with 2.0 query builder. If you change the schema, you lose anything that was selected, which is a problem as our database (as I'm sure many others do) span several schema.
    -Scott

    as i posted earlier .. queryBuilder as a stand alone product is neither supported nor available anymore. it is only available as part of the report data wizard.
    thanks,
    ph.

  • Problem in executing Dynamic SQL in SYSTEM Schema

    Hi,
    I am trying to execute the below given dynamic sql from SYSTEM account.
    'SELECT cnt, SUBSTR(SYS_CONNECT_BY_PATH(column_name,'',''),2) AS COLS FROM
    ( SELECT b.column_name,b.position,COUNT(1) over (ORDER BY a.constraint_name) AS cnt
    FROM SYS.dba_Constraints a JOIN SYS.dba_Cons_Columns b ON (a.constraint_name = b.constraint_name)
    WHERE a.table_name = '''||UPPER(v_table)||''' AND a.owner = '''||UPPER(v_owner)||''' AND a.constraint_type = ''P'' ORDER BY b.position
    ) WHERE position = cnt START WITH position = 1 CONNECT BY PRIOR position = position -1';
    I am getting the error ORA-00942:table or view does not exist.
    If I execute the created SQL from SQLPlus it is getting executed without any errors. If I try the same from SYS account it is working fine without any issues.
    Could some one share some light on it.
    Thanks in Advance
    Sree.

    Hi Guys,
    I got the solution, for referening objects in DYNAMIC sqls need explicit grant on those objects (not through roles). That is the reason this SQL is working in SYS schema, since SYS owns these tables, but system grot the access to these tables through roles.
    Regards,
    Sree.

  • Native Dynamic SQL, PL/SQL

    Hi all,
    When I try the follwing block to perform a PL/SQL block, it gives the error ORA-06536: IN bind variable bound to an OUT position.
    DECLARE
    V_SQL VARCHAR2(4000);
    V_E_NAME VARCHAR2(100);
    BEGIN
    V_SQL := 'BEGIN
    SELECT EMP_NAME
    INTO :1
    FROM EMP
    WHERE EMP_CODE = :2;
    END;';
    EXECUTE IMMEDIATE V_SQL USING V_E_NAME, 101;
    DBMS_OUTPUT.PUT_LINE('EMP NAME - '||V_E_NAME);
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('ERR - '||SQLERRM);
    END;
    Please help me to overcome this.
    Thanks in advance.

    Yes, you can declaring V_E_NAME to be an OUT bind parameter...
    SQL> DECLARE
      2  V_SQL VARCHAR2(4000);
      3  V_E_NAME VARCHAR2(100);
      4  v_empno number := 7839;
      5  BEGIN
      6  V_SQL := 'BEGIN SELECT ENAME INTO :1 FROM EMP WHERE EMPNO = :2; END;';
      7  EXECUTE IMMEDIATE V_SQL USING OUT V_E_NAME,v_empno;
      8  DBMS_OUTPUT.PUT_LINE('EMP NAME - '||V_E_NAME);
      9  EXCEPTION
    10  WHEN OTHERS THEN
    11  DBMS_OUTPUT.PUT_LINE('ERR - '||SQLERRM);
    12  END;
    13  /
    EMP NAME - KING
    PL/SQL procedure successfully completed.Max
    http://oracleitalia.wordpress.com

  • I wnat to develop Query Builder

    Hi Dear All
    my requirement is to develop query builder because of genearting dynamic sql statement at run time. i'm using 9iDS and query builder is not provided with it as separate application. is there anyon who can help me how it should be get started. i'll be very thankful to u
    Best Regards!!!

    Query Builder was desupported as a product as part of the developer suite.
    see http://www.oracle.com/technology/products/forms/pdf/forms_upgrade_reference.pdf
    Regards
    Grant Ronald
    Forms product Management

  • Dynamic SQL Query count

    Hi,
    I need to retieve the number of records that will be retrieved by a query as follows.
    How can this be done?
    Is there a method to do it using native dynamic sql (open .. for .. using ) instead of DBMS_SQL (Because Native is faster than dbms_SQL )?
    The following block demostrates what I need to do where v_query will hold the query text.
    declare
    v_query varchar2(32000);
    v_count number;
    begin
    select query_text into v_query from groups_table where id =1;
    dbms_output.put_line('count = '||v_count);
    end;
    Thanks in Advance

    Is there a way to use sql%rowcount to do something similar?
    Afraid not
    I mean if there is a way to get better performance in case of very large query. Like for example in oracle forms, when using Query --> count records it retrieves the nubmer of records that will be fetched.
    I think you'll find forms simply does a select count(*) from the base table (adding and predicates where necessary).
    What are you going to use it for? Maybe there is an alternative route you can take...

  • Save layout of queries in SQL Developer query builder?

    Sometimes queries are very complex and moving tables around in the graphical view is really helpfull to better understand them.
    Unfortunately this layout does not get saved with "save" (because this is a simple text file).
    Once upon there was a query builder (included with designer 2000 and later vom 1991 to 1998) that had a proprietary format (.brw) to just do that: Save a query including layout.
    Any chance to save the layout of SQL Developer query builder queries?

    I dont think there is any way to save the layout for the query, you can request an enhancement on the Exchange for this http://sqldeveloper.oracle.com/
    But if you only need to restore the query you are working with later, or move it to another workstation and continue editing using the query builder, you only need the SQL code generated; when you paste it in an opened worksheet (on the same database or even a clone with the same structure) the query builder is able to resume working just fine with default positioning for the table objects.
    If you hand edit the query and insert some SQL manually then the query builder may stop working for particularly complex statements, in this case it will warn you and disable itself.

  • SQL Developer replacement for Query Builder?

    Our developers use query builder to quickly develop sql code w/conditions, joins, where clauses, etc. I just installed release 2 of SQL Developer and am trying to figure out if this is a viable replacement for query builder. Is there a graphical "query builder" component as part of SQL Developer?

    Barry, I would agree that it should be clean and easy to use. I started using Data Browser 2.0 and migrated to Query Builder 6.0.7.1.0 and while Query Builder is no longer it's own product it's integrated into Reports Developer 10g. The basic layout and operation has been consistent thru the life cycle and I would think you'd keep the "look and feel" consistent with what's currently available. (might simplify integrating it too). My biggest complaint with Query Builder 6.0.7 (se don't use the 10g version) is that it errors when opening a schema with more than 8192 objects. As an E-Business Suite 11.5.10 customer this is an issue for our developers when logging in as the standard APPS user.
    So here would be my "wish list"
    1. consistent look and feel with "older" versions of Browser/Query Builder
    2. removal of 8192 object limitation
    3. ability to open older .brw format files
    Certainly more improvements would be possible by integrating with SQL Developer and would be welcomed - this wish list is coming from a user who has MANY .brw files in the older 6.0.7 format.

Maybe you are looking for

  • Error vendor is not intended for p org

    HI, When an user ordered the shopping cart  anError " Vendor xxx is not intended for purchasing org.xxxx., came in. Vendor was existing in the vendor organization. Can some body let me know what could be the problem, and what are all the attributes t

  • HT1296 how do i sync my ipod touch with windows media player?

    so.....................any ideas????

  • TIME KF in the query??

    Hi all, I loaded data from ODS to Cube and have Time CHARs in my Cube. But I don't have any values for my TIME CHARS in the query. Can someone tell me how to fix it? Thanks J.

  • All pages in merged file blank?

    Has anyone had problems in Pro X where all pages in a merged file of all .pdfs are blank?

  • Finding hidden mailboxes On My Mac

    Important set of boxes under "Delivered" have disappeared since yesterday, without me deliberately making any change. Messages can still be searched for and shown individually. Show/hide doesn't work from pull-down or screen; nor does restarting mail