The USE of dynamic SQL clause

Hi all
I'm moving a table as a variable in dynamic SQl but with no result. Suppose that I it running on HR diagram example:
declare
sql_state varchar(100);
hire_date date;
temp_table varchar(9):='employees';

begin
sql_state:= 'select hire_date from :1 where employee_id=206';

execute immediate sql_state into hire_date using temp_table;
dbms_output.put_line('hire_date is '||hire_date);
end; 

declare
*
ERROR at line 1:
ORA-00903: invalid table name
ORA-06512: at line 9
I get this error of invalid table name without knowing what was read for the variable. Any advice?

Best regards
Val

Hi Valerie,

To add to what Peter, said

"Binding" values in a query is done for a specific purpose, and this purpose is so that the optimizer can use the same query as the previous execution plan runs the query, which prevent it from having to analyze the hard the query each time. A query execution plan is based on the tables and columns are presented in the query, but with respect to the actual "values" of these columns, they are unlikely to change the execution plan. So, to keep the same execution plan, the query must seem identical (in terms of a query string) like the previous series, so if you want the same query, but just with different values, they can be replaced with bind variables (these things have a ': ' character) and then the values passed in the query, when it is run.

Now, if Oracle were to allow you to link in the names of objects, such as tables, this means that it could not use the previous execution plans, because he doesn't know until run time what tables will be consulted. Therefore, it would be useless link in the values of the query and it would be just as quick to implement your query string by concatenating all the values inside rather than link them. Considering that a query is parsed first and then the values in it, then it cannot be analyzed if the tables are not known everything first. (Take a look at how queries are formed and variables when you use the DBMS_SQL package).

So the key thing to remember is that, when it comes to bind variables, you can bind only the 'values', not 'objects '.

Tags: Database

Similar Questions

  • Tables created in a stored procedure cannot be used with dynamic SQL? The impact?

    There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?

    If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).

    In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?

    Thank you and best regards,
    Amedeo.

    Published by: AGF on March 17, 2009 10:51

    AGF says:
    Hi, Frank.

    Thank you for your response. I understand that the dynamic SQL is required in this context.

    Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.

    In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.

    I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.

    The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).

    If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.

    With the TWG, you have none of these issues.

    Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)

    When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.

    Another risk of dynamic query is SQL injection which may result in a security risk on the database.

    Good programming will have little need for the tables of dynamically created dynamically or SQL.

  • Error when using native dynamic SQL

    Please can someone help me understand what's wrong with my code.

    Code:

    create or replace procedure p1 (name varchar2)

    as

    Start

    run immediately "select * from ' |" name;

    end;

    /

    Goal: Just to test the native dynamic SQL code using a placeholder.

    COmpliation:

    SQL > create or replace procedure p1 (name varchar2)

    2 as

    3

    4 start

    5 run immediately "select * from ' |" name;

    6 end;

    7.

    Created procedure.

    Error:

    SQL > exec p1 ('employees');

    BEGIN p1 ('employees'); END;

    *

    ERROR on line 1:

    ORA-00923: THE KEYWORD not found where expected

    ORA-06512: at "HR. "P1", line 5

    ORA-06512: at line 1

    SQL >

    You need a space after the clause 'from', like this:

    run immediately "select * from ' |" name;

  • Zero error of iteration - the treatment of dynamic sql statements in dbms_xmlgen

    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    881575 wrote:
    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing to EXECUTE IMMEDIATE.
    COPY the statement & PASTE in sqlplus to validate its correctness.

  • help on the use of dynamic action to update the items in a table (more precisely, the radio button) based on the collection

    Hi everyone, I posted this question in the past and made huge strides with the help of Denes Kubicek: https://apex.oracle.com/pls/apex/f?p=31517:294:115851992029365: based on my previous question posted: https://forums.oracle.com/forums/thread.jspa?threadID=2537494

    I'm fighting with a single element in my tabular presentation.  There is a radio button.  The choices all seem correctly, but the value is not saved in the collection (and therefore not recorded in the table).  All the other elements in the form of tables to record properly.

    Here's what I have for the query.   This is element c024 (which maps to;) ("F03'), which is defined as a radio based on an existing LOV LOV.

    Currently I have:

    2 items on the page:

    P110_ID

    P110_VALUE

    Dynamic action called COLUMN of CHANGE:

    event: CHANGE

    selection type: jQUERY Selector

    jQuery:

    Select jQuery = input [name = "f03"], select [name "f08"], select [name = "f09"], input [name = 'f10'], input [name = 'f11'], input [name = 'f12'], select [name = "f40"], input [name = "f21"], input [name = 'f22'], input [name = "f23"], input [name = 'f50']

    scope of the event: Dynamics

    real action #1: set the P110_ID javascript expression this.triggeringElement.id

    real action #2: set the P110_VALUE javascript expression this.triggeringElement.value

    action 3: run pl/sql code

    declare
      v_member number;
      v_seq number;
    begin 
      v_member := TO_NUMBER (SUBSTR (:p110_id, 2, 2));
      select ltrim(substr(:p110_ID,5,4),'0') into v_seq from dual;
      safis_collections.update_column(v_seq,
                                    v_member,
                                    :p110_value);
    
    
    

    refreshment area true creation #4: LANDINGS_COLLECTION

    the tabular presentation is based on the query:

    SELECT
    apex_item.text(1,seq_id,'','','id="f01_'||seq_id,'','') "DeleteRow",
    seq_id,
    seq_id display_seq_id,
    apex_item.text_from_LOV(c004,'SPECIES')||'-'||apex_item.text_from_LOV(c005,'GRADE')||'-'||apex_item.text_from_LOV(c006,'MARKETCODE')||'-'||apex_item.text_from_LOV_query(c007,'select unit_of_measure d, unit_of_measure r from species_qc') unit,
    apex_item.select_list_from_LOV(8,c008,'DISPOSITIONS','onchange="getAllDisposition('||seq_id||')"','YES','0','  -- Select Favorite --  ','f08_'||seq_id,'') Disposition,
    apex_item.select_list_from_LOV(9,c009,'GEARS','style="background-color:#FBEC5D; "onFocus="checkGearPreviousFocus('||seq_id||');"onchange="getAllGears('||seq_id||')"','YES','3333','-- Select Favorite --','f09_'||seq_id,'') Gear,
    apex_item.text(10,TO_NUMBER(c010),5,null, 'onchange="setTotal('||seq_id||')"','f10_'||seq_id,'') Quantity,
    apex_item.text(11,TO_NUMBER(c011),5,null,'onchange="getPriceBoundaries('||seq_id||')"','f11_'||seq_id,'') Price,
    
    apex_item.text(12, TO_NUMBER(c012),5,null, 'onchange="changePrice
    ('||seq_id||')" onKeyDown="selectDollarsFocus('||seq_id||',event);"','f12_'||seq_id,'') Dollars,
    decode(c013,'Y',apex_item.text(14, c014,30,null,'style="background-color:#FBEC5D;" onClick="onFocusAreaFished('||seq_id||');"','f14_'||seq_id,''),'N','N/A') Area_Fished,
    decode(c017,'Y',apex_item.text(18, c018,4,null,'style="background-color:#FBEC5D; "onBlur="setUnitQuantity('||seq_id||')"','f18_'||seq_id,''),'N','N/A') UNIT_QUANTITY,
    decode(c017,'Y',apex_item.text(19,'CN',3,null,'readOnly=readOnly;','f19_'||seq_id,''),'N','N/A') UNIT_COUNT,
    c024 hms_flag,
    decode(c050,'Y',apex_item.checkbox(21,'Y','id="f21_'||seq_id||'" style="background-color:#FBEC5D; " onClick="alterYes('||seq_id||');" onKeyPress="alterYes('||seq_id||');"',c021),'N','N/A') FinsAttached,
    decode(c050,'Y',apex_item.checkbox(22,'N','id="f22_'||seq_id||'" style="background-color:#FBEC5D;" onClick="alterNo('||seq_id||');" onKeyPress="alterNo('||seq_id||');"',c022),'N','N/A') FinsNotAttached,
    decode(c050,'Y',apex_item.checkbox(23,'U','id="f23_'||seq_id||'" style="background-color:#FBEC5D;" onClick="alterUnk('||seq_id||');" onKeyPress="alterUnk('||seq_id||');"',c023),'N','N/A') FinsUnknown,
    decode(c050,'Y',apex_item.textarea(28,c028,3,null,null,'f28_'||seq_id,''),'N','N/A') Explanation,
    decode(c024,'N',apex_item.select_list_from_LOV(29,c029,'HMSNATURE','onchange="saveNature('||seq_id||')"','YES','A','-- Select Nature of Sale --','f29_'||seq_id,''),'U',apex_item.select_list_from_LOV(29,c029,'HMSNATURE','onchange="saveNature('||seq_id||')"','YES','A','-- Select Nature of Sale --','f29_'||seq_id,''),'Y','N/A') Nature_Of_Sale,
    decode(c020,'Y',
    apex_item.select_list_from_LOV(40,c040,'HMS_AREA_CODE','style="background-color:#FBEC5D;"',null,null,null,'f40_'||seq_id,''),
    'N','N/A') HMS_AREA_CODE,
    c020,c050,
    decode(c020,'Y',
    apex_item.text(41,TO_NUMBER(c041),5,null,null,'f41_'||seq_id,''),
    'N','N/A') Sale_Price
    from apex_collections
     where collection_name = 'SPECIES_COLLECTION' order by seq_id
    
    
    
    
    
    

    I noticed the following:

    When I change the column C011 (price) the following values are defined in dynamic action:

    P110_ID = f11_1

    P110_VALUE is everything that I change the price.

    When I change the column C024 (hms_flag), the following values are defined:

    P110_ID = f03_0001

    P110_VALUE = change everything what I hms_flag to.

    the region is updated in my dynamic action, and change of hms_flag does not take.  I tested the SQL query that generates the value of v_SEQ in the dynamic action.   Both a change of price and HMS_FLAG, it seems valid

    Select ltrim (substr(:p110_ID,5,4),'0 ') in the double v_seq;

    If f11_1, v_seq: = 1

    If f03_0001, v_seq: = 1

    Thank you!

    solved.  sort of.

    domain c024 references f03.

    dynamic ACtion, step 4 calculated v_member as a substring of P110_ID... and in all other areas, the column and the field (fxx) displayed the same value... otherwise c024.

    I'm not exactly sure how solve it, but see the problem.

  • Helps with the syntax of dynamic sql statements

    Hi all
    How can I pass the value of the result of my dynamic select statement to a Ref Cursor?
    I try the following statement but does not work, I get this error:
    ORA-00932: inconsistent data types: expected - was - ORA-06512: at
    Procedure getItems(v_first In number, v_second In Number, arg_Cursor IN OUT CUSTOM_REF_CURSOR) is
         sqlString varchar(3000);
         Begin
           sqlString := 'select* from bla where o.arg_1 = :1 and arg_2 = :2'; 
       
           execute immediate sqlString 
           into arg_Cursor
           using v_first, v_second;
       End getItems;
    Any ideas?
    Thank you

    Johnny
    PROCEDURE getitems (v_first IN NUMBER, v_second IN NUMBER, arg_cursor IN OUT sys_refcursor)
    IS
      sqlstring   VARCHAR (3000);
    BEGIN
      sqlstring := 'select* from bla where o.arg_1 = :1 and arg_2 = :2';
    
      OPEN arg_cursor FOR sqlstring USING v_first, v_second;
    END getitems;
    
  • The use of dynamic text with Actionscript

    I have a variable called "managername. My film requires data in a text document. The problem is that my flash variable name is also part of the name of the entry in the text document. Like this:

    myText_district = 109
    & myText_Ian = 189
    & myText_Dave = 8
    & myText_Ray = 14

    Y at - it a syntax that I can use in the field of the Var of the property Panel to get the variable equivalent to something like "myText"+ _root.managername? ".

    OR

    Is there an example somone can show me how to load variables from a text file in a dynamic text field SPECIFIC completely into the action script?

    Any help is greatly appreciated.

    Well, you will have to wait until the content of districtmanager.txt load in. All about the right time for the file to load interent. Flash is not wait until what the code load, it just not the loadVariablsNum and then continues on the trace that there no variables (again) with the name myText_Ian or what you have.

    If you are publishing for Flash 6 or higher, you should probably use the LoadVars class. This gives you the onLoad event so you can then put your code in there and make sure that variables are loaded before you try to use them.

    Another question, is what happens when you get a new Manager? You should put in another variable and make the entire file again. That's why I think you should consider possibly develop this with XML or another way of not having to hard-code these things.

  • bind the parameter to dynamic sql

    Dear user

    I want to bind the variable at run time

    the problem is as follows:-

    I have a table like this: -.

    type_id, rule_dtls, rule_id, using_paramter

    rule_id and type_id is an idea just to the rule and object

    using_paramter:-is parameters used to bind the variable to the rule, it may be different

    as examples of data the spouse;

    using_paramter can be different parameter as AREA, BOARD_NO or face_no,

    rule_id, board_type, rule_dtls using_paramter
    17CASE WHEN: BOARD_NO < 1000 then 10 when: BOARD_NO > 1000 then CEIL (: BOARD_NO/5000) * 5 endBOARD_NO,BOARD_NO,BOARD_NO
    25
    WHEN BOX: AREA < 3 then 15 when : AREA > 3 then (: SPACE - 3 * 2) + 15 end
    BOX, BOX, BOX

    and I have the function of database 10g as follows:-

    CREATE OR REPLACE FUNCTION    get_bord_price(area number,face_no number,BOARD_NO number,BOARD_TYPE_v varchar2) RETURN number  IS
    amt number:=0;
    sql_v varchar2(500);
    BOARD_RULE varchar2(500);
    using_clom varchar2(500);
    price number;
    ERR varchar2(500);
    ERR_CODE NUMBER;
    BEGIN
    price:=0;
    select rule_dtls ,using_paramter into BOARD_RULE,using_clom from BOARD_RULE where BOARD_TYPE=BOARD_TYPE_v;
    sql_v:='select '||BOARD_RULE  ||' from dual';
    execute immediate sql_v 
    INTO price
    using using_clom;
    RETURN price;
    exception when others THEN
    ERR:=SQLERRM;
    return 0;
    END;
    
    
    

    the error is in

    using using_clom;

    How can I bind varable this:

    or is there another solution

    Hello

    Bind variables cannot be a variable.

    Identify the parts to be replaced (e.g.,: BOARD_NO,: AREA) and write statements to REPLACE to replace those.

    Manu.

  • Dynamic SQL in APEX

    Hey everyone, I'm trying to understand how to use dynamic sql statements in Application Express. Specifically, I'm trying to write a query using substitution/bind variables. I don't know if you need a description of the application or not, but here's the query that will run in sqlplus:
    ACCEPT     file_id     PROMPT     "Enter the file_id (a number, e.g. 3): "
     
    -- Preliminary Query, to set table_name
     
    COLUMN     reference_id_col     NEW_VALUE     reference_id
    COLUMN     table_name_col     NEW_VALUE     table_name
     
    SELECT  f.reference_id          AS reference_id_col
    ,           t.reference_table       AS table_name_col
    FROM      aa_files     f
    JOIN     aa_type     t     ON     f.file_type     = t.type_id
    WHERE     f.file_id     = &file_id
    ;
     
    --     Main Query
     
    SELECT  * 
    FROM     &table_name
    WHERE      reference_id     = &reference_id
    ;
    There are three substitution variables, reference_id & file_id and & table_name. My basic setup is that I have a table full of table names, so I ask her to get a table name in a variable, then query this table for my data.

    I work inside the window of SQL commands to try to find the proper syntax to make this work in the APEX. I'm pretty sure that APEX does not allow the use of substitution variables, because they are one thing on the side of client SQL more right?

    I'm still a student, so I'm not known and Oracle Application Express, but reading the documentation of the APEX and the Googling, I tell myself that bind variable should be able to do this for me, but I don't know how. I searched for some examples or documentation on the use of dynamic SQL statements in the APEX, but I could not find anything. I'm sure I could do this using a PL/SQL block, but I'd rather do it in pure SQL if possible.

    So if someone could help me or giving me an example of syntax I would have to use to write a query that is running in Application Express, or could direct me to the literature on the use of dynamic sql statements in Application Express, it would be greatly appreciated!

    If you need more information on my application, I can post my create table statements and some inserts sample data, if that would be helpful.

    Thank you!

    Published by: username, June 21, 2010 07:34

    OK, so one of the great things about SQL is your ability to choose what columns you want to include in your result set. You don't have to use all of them. You can do this in two ways: with dynamic SQL or individual areas for each type of file. This will depend on your use as to how many types different files will be added each day on which you want to go with.

    If you go with dynamic SQL (and because you don't know until run time what columns you want to use, it is an appropriate use), you will need to build your query based on the file type. Something like this:

    declare
      qry_type  VARCHAR2(10);
      sql_qry    VARCHAR2(4000);
      qry_select  VARCHAR2(500);
      qry_from   VARCHAR2(100);
      qry_where  VARCHAR2(400);
      qry_order   VARCHAR2(100);
    begin
      qry_type  :=  :PX_QRY_TYPE;
      --Build the SELECT clause
      qry_select   := 'select a.FILE_NAME, a.FILE_NAME, a.FILE_TYPE, a.LOCATION';
      CASE qry_type
         WHEN 'PDF' THEN qry_select   := qry_select || ', pdf.DATE_MODIFIED, pdf.SUMMARY, pdf.AUTHOR';
         WHEN 'XLS' THEN qry_select   := qry_select || ', xls.DATE_MODIFIED, xls.SUMMARY, xls.TOTAL_VALUE';
         ...
      END CASE;
      --Build the FROM clause
      qry_from    := ' from AA_FILE a, AA_FILETYPE_PDF pdf, AA_FILETYPE_XLS xls, AA_FILETYPE_PHOTO p';
      --Build the WHERE clause
      qry_where  := ' where a.FILE_ID = pdf.FILE_ID (+)';
      qry_where  := qry_where || ' and a.FILE_ID = xls.FILE_ID (+)';
      qry_where  := qry_where || ' and a.FILE_ID = p.FILE_ID (+)';
      --Build the ORDER BY clause
      qry_order  := '';
      --Put it all together
      sql_qry   := qry_select || qry_from || qry_where || qry_order;
      EXECUTE IMMEDIATE sql_qry;
      ...
    end;
    

    Now this does not cover the addition of new file types. I still think you're going to be better off planning for as much as you can and handle manually creating additional tables, but this is going to be to you. I know you are trying to generate code to do everything for you, but when it comes to databases, I found that the creation of objects can quickly become uncontrolled if you're not very careful. These are going to be permanent, not temporary memory built database objects. Just a word of warning.

    If you decide to go with a region and by file type, it does not require nearly as much work. Simply create a report region based on the view and set the conditional display based on your file type.

      select * from V_FILES_PHOTO
       where FILE_ID = :PX_FILE_ID;
    
    condition:  FILE_TYPE = 'PDF'
    

    While you will need to add a region again every time that you add a new file type, once again, the question that arises is: file types how are you really going to have to worry? If you're talking about a dozen, I would like to do things manually. If you're talking about a hundred, it's maybe worth trying to find a method of programming. It is your call to make.

  • How to use Bulk collect in dynamic SQL with the example below:

    My Question is

    Using of dynamic SQL with collection in bulkif we pass the name of the table as "to the parameter' function, I want to display those

    An array of column names without vowels (replace the vowels by spaces or remove vowels and display).

    Please explain for example.

    Thank you!!

    It's just a predefined type

    SQL> desc sys.OdciVarchar2List
     sys.OdciVarchar2List VARRAY(32767) OF VARCHAR2(4000)
    

    You can just as easily declare your own collection type (and you are probably better served declaring your own type of readability if nothing else)

    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE
      2     PROCEDURE TBL_COLS_NO_VOWELS(
      3                                  p_owner VARCHAR2,
      4                                  p_tbl   VARCHAR2
      5                                 )
      6  IS
      7     TYPE vc2_tbl IS TABLE OF varchar2(4000);
      8     v_col_list vc2_tbl ;
      9  BEGIN
     10      EXECUTE IMMEDIATE 'SELECT COLUMN_NAME FROM DBA_TAB_COLUMNS WHERE OWNER = :1 AND TABLE_NAME = :2 ORDER BY COLUMN_ID'
     11         BULK COLLECT
     12         INTO v_col_list
     13        USING p_owner,
     14              p_tbl;
     15      FOR v_i IN 1..v_col_list.COUNT LOOP
     16        DBMS_OUTPUT.PUT_LINE(TRANSLATE(v_col_list(v_i),'1AEIOU','1'));
     17      END LOOP;
     18*  END;
    SQL> /
    
    Procedure created.
    
    SQL> exec tbl_cols_no_vowels( 'SCOTT', 'EMP' );
    MPN
    NM
    JB
    MGR
    HRDT
    SL
    CMM
    DPTN
    
    PL/SQL procedure successfully completed.
    

    Justin

  • dynamic SQL to drop the indexes on the table

    Hello world

    Please tell me how to remove the indexes on a table by using a dynamic sql code

    for example, I have a dummy table with two index idx1, idx2

    I need a procedure or a function where I will be passing in the name of the table, the function/procedure should remove the indexes on the table

    Thank you

    Not tested:

    create or replace
    procedure drop_indexes_of_table(p_table_owner varchar2,
                                    p_table_name varchar2)
    as                              
    
    cursor c_drop_statements is
    select 'drop index '||owner||'.'||index_name stmt
    from all_indexes
    where table_owner=p_table_owner
    and table_name=p_table_name;
    
    begin
      for r in c_drop_statements loop
        execute immediate r.stmt;
      end loop;
    end;
    
  • The best recovery PL/SQL methods

    do you have advice on certain situations of recovery? such as the whole line, use select in... or to bind number of variables at runtime using native dynamic sql or dbms_sql for more uncertain... etc.

    because I need a solution that does the same thing on no_data_found or the value does not match my condition. I don't want to call the proc even with the same settings, but I want to just do the same thing on no_data_found or value does not match. do you have any advice?

    for example.

    declare

    Start

    Serial_number SELECT in v_serial customer_equip where account_number = in_account_number;

    If v_serial <>'1557788' then

    call_proc2(param1,param2,param3,...);

    exception when no_data_found then

    call_proc2(param1,param2,param3,...);

    end if;

    end;

    For general approaches, I tend to browse answers asktom.oracle.com/pls/apex/f?p=100:1:0 of Tom Kyte

    For your specific case, a common approach is:

    declare

    v_found boolean;

    Start

    Start

    Serial_number SELECT in v_serial customer_equip where account_number = in_account_number;

    v_found: = true;

    exception when no_data_found then

    v_found: = false;

    end;

    If v_serial <> ' 1557788' or NOT v_found then

    call_proc2(param1,param2,param3,...);

    end if;

    end;

  • Dynamic SQL code generation

    I'm having a problem with the generation of dynamic SQL code.

    Specifically when I use single quotes in my SQL statements, they end by showing as quotes when the query is run.

    Any ideas on how I can remdey it?

    When I view my dynamic SQL code, it looks and works fine if I run it

    AND (External_Group_Members LIKE ' % 1% ' OR External_Group_Members LIKE ' %, 3, %'))

    but when these data are transmitted to the SQL, it looks at and I get an error

    SELECT * FROM External_Groups WHERE 1 = 1 AND (External_Group_Members LIKE '% 1% ' OR External_Group_Members LIKE "%, 3, %'') ORDER BY External_Group_Name)

    PreserveSingleQuotes().

  • Is it possible to keep all static?   (vs dynamic SQL)?

    Hi all

    I have existing MS who after db Exchange should work with newly partitioned table partition name = date of entry both inside AND date_param, something like:

    sql_string: =' select * tt partition (P_'| date_param |') the problem of configuration required, I can't use any dynamic SQL and it really put me in the corner, do you think it is at all possible? I was thinking about a lot of things that may work, but date_param is just date < 12 - 7.-10. > and partition is preceded with PRT_?

    I can to with str_part: = ('(P_'|| date_param ||'') ') "), but it is already dynamic...

    Even after I create the temporary table and for sure, I know that the DDL inside the procedure should be ONLY dynamic?
    What is the dead end? There is a way to CREATE static? or simply to use kind of temp table created outside MS and clean it before use? or...

    I actually try to see why customer site cannot manage NDS or they just don't want it, but can't argue with that for now.
    I've got enough new to Oracle and couldn't do bad things on the SQL dynamic (NDS)?

    Thank you all
    TR

    Trento wrote:
    Hi all

    I have existing MS who after db Exchange should work with newly partitioned table partition name = date of entry both inside AND date_param, something like:

    sql_string: =' select * tt partition (P_'| date_param |') the problem of configuration required, I can't use any dynamic SQL and it really put me in the corner, do you think it is at all possible? I was thinking about a lot of things that may work, but date_param is just <12-Sep-10>and partition is preceded with PRT_?

    I can to with tmp_part: = ('(PRT_'|| date_param ||'') ') "), but it is already dynamic...

    Even after I create the temporary table and for sure, I know that the DDL inside the procedure should be ONLY dynamic?
    What is the dead end? There is a way to CREATE static?

    I actually try to see why customer site cannot manage NDS or they do not want, cannot buy with that for now. I'm pretty new to Oracle and could not do bad things on dynamic SQL?

    Thank you all
    TR

    Why the hell wouldn't you just query the table and apply the predicate? Oracle would then partition elimination for you.

    No need for anything either dynamics based on what you posted.

  • The use of bind variables (in &amp; out) with sql dynamic

    I have a table that contains code snippets to make postings on a set of pl/sql database. what the code does is basically receives an ID and returns a number of errors found.
    To run the code, I use dynamic sql with two bind variables.

    When codes consists of a simpel query, it works like a charm, for example with this code:
    BEGIN
       SELECT COUNT (1)
       INTO :1
       FROM articles atl
       WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL;
    END;
    However when I get to post more complexes that must perform calculations or run several queries I run into trouble.
    I have boiled down the problem into that:
    DECLARE
       counter   NUMBER;
       my_id     NUMBER := 61;
    BEGIN
       EXECUTE IMMEDIATE ('
          declare 
             some_var number;
          begin
          
          select 1 into some_var from dual
          where :2 = 61; 
          
          :1 := :2;
          end;
    ')
          USING OUT counter, IN my_id;
    
       DBMS_OUTPUT.put_line (counter || '-' || my_id);
    END;
    This code is not really make sense, but it's just to show you what is the problem. When I run this code, I get the error
    ORA-6537 ON bind variable linked to a position IN

    The error doesn't seem wise,: 2 is the only one IN bind variable and it is only used in a where clause clause.
    As soon as I remove this where clause, the code works again (giving me 61-61, in case you want to know).

    Any idea what goes wrong? I just use bind variables in a way that you're not supposed to use it?

    I'm using Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit

    Correction. With immediate execution , the binding is in position, but binds do not need to be repeated. My statement above is incorrect...

    You must link only once - but bind by position. And the connection must correspond to the use of the variable binding.

    If the connection never variable assigns a value in the code, link by in.

    If the binding variable assigns a value in the code, link as OUTPUT.

    If the binding variable assigns a value and is used a variable in another statement in the code, link as IN OUT.

    For example

    SQL> create or replace procedure FooProc is
      2          cnt     number;
      3          id      number := 61;
      4  begin
      5          execute immediate
      6  'declare
      7          n       number;
      8  begin
      9          select
     10                  1 into n
     11          from dual
     12          where :var1 = 61;       --// var1 is used as IN
     13
     14          :var2 := n * :var1;     --// var2 is used as OUT and var1 as IN
     15          :var2 := -1 * :var2;    --// var2 is used as OUT and IN
     16  end;
     17  '
     18          using
     19                  in out id, in out cnt;  --// must reflect usage above
     20
     21          DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id);
     22  end;
     23  /
    
    Procedure created.
    
    SQL>
    SQL> exec FooProc
    cnt=-61 id=61
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

Maybe you are looking for

  • Where to buy the video and cable and antenna for Qosmio F30 adapter?

    Salvation on a trip I lost the software plug-in component video cable and antenna adapter provided with my Qosmio laptop.Anyone know where I can get replacement cables for?

  • HP 23xi monitor calibration

    I own a PC Toshiba laptop p875-7102-i7-3630qm Windows 8 with a brilliant display of 17.3 "1920 x 1080. It uses the integrated graphic chip Intel HD 4000.  I bought the HP 23xi based monitor very there comments.  Here's the thing, though: no matter wh

  • No HELP with OE6 file dbx missing no bak file

    Hi hope someone can help! my computer is old w/decrease storage and OE inbox has suddenly lost most of the emails. I know the old routine in what concerns the use of the .bak folder in the trash, but I did not!  I see the huge dbx file, but I can't r

  • Visual styles in Windows 7

    Please keep in mind that I'm not the most experienced computer scientist out there, as you can probably vocabulary I use. If excuse ahead for any errors I will probably do that. I was trying to download some programs that required me to turn the Visu

  • BlackBerry Smartphones blackberry torch 9800 - slow

    my blackberry 9800 runs very slowly - the ' clock (hourglass) lights up as soon as I make a entry any. " all recommendations and the upgrade of a flashlight to 9810 blackberry would solve the problem- How can I make sure that applications are not run