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.

Tags: Oracle Development

Similar Questions

  • Cannot bind the parameter "network card"

    I want to disconnect the network cards on 500 vm - I created a new 'Action' by using the command 'Set-NetworkAdapter.

    I checked the following

    Copy

    Network card

    NetworkName

    StartConnected

    WakeOnLan

    Whenever I try to run it I get the following error

    "Could not bind the parameter ' NetworkAdapter" cannot convert the value "(adaptateur de réseau 1)" type VMware.VimAutomation "" "

    I tried to enter the following text

    NIC 1

    "NIC 1.

    (NIC 1)

    Nothing works - what don't get me?

    Thank you

    I answered your original question on PowerGUI/VESI virtualization/PowerShell forum.

    http://thevesi.org/thread.jspa?MessageID=28105淉

    Scott

  • bind the parameter, Q1

    Hello everyone,
    We do great for user input parameters. We used the report wizard and changed the data by adding: where table.date BETWEEN: Enter_Start AND: Enter_End

    We received the message, "Note: the query"Q - 1 "has created the parameters bind"Date_Start","Date_End"."
    We didn't pay attention couples suite:
    1. ' Q - 1'
    2 bind the parameter (s)

    We just clicked OK, then, then buttons only. We were happy labels: Enter Start and End.

    Nothing is simple!
    We have some challenges when it comes to change: Enter_Start AND: Enter_End to: First_Date AND: Second_Date.

    where table.date BETWEEN: First_Date AND: Second_Date

    Now we have 4 labels: begin to enter, enter end, Date of the first and second Date. We want only 2 labels and 2 input parameters.

    If you have experience on the topic, please share with us.

    Thanks in advance,

    NY

    Arif Khadas wrote:

    If we do not like it?

    function boolean return AfterPForm is
    Start
    : order_by_clause: = "ORDER BY". : ID
    return (TRUE);
    end;

    Yes. Note that the ID parameter for valid column transmitted by the user name.

    I suppose that space must be in 'ORDER BY ' | : ID. What I mean like that...

    :order_by_clause := 'ORDER BY '|| :ID
    
  • 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 '.

  • pass the parameter in pl/sql block

    Hello

    I have to call anonymous pl/block block with the shell script parameter. It works fine as indicated below, the problem is - generated email after the creation of the table in step contains
    list of all directories and files, instead of "select * from". When I change * to the values of columns, everything works well, but I need to use ' * ' in select statement.
    Please let me know which remedy.
    set serveroutput on
    @${CREATE_STAGE_SQL} ${i}
    COMMIT;
    QUIT;
    EOF
    CREATE_STAGE_SQL. SQL
    declare
    begin
    ### some other processing###
     execute immediate 'create table T1_&1._STG as select * from t1_rpt_tmt where 1=2';
    end 
     
    Thank you
    Sandy

    Sandy310 wrote:

    Question - how to select * on my application, how to use * (special character) bulk pl/sql call?
    I used & 1. (dot) to pass parameter.

    Example:

    // the script
    /home/billy/sql> cat show-employees.sql
    --// usage: show-employees.sql 
    --//
    --// where:     sql-projection = comma delimited column list
    
    set verify off
    set define on
    define PROJECTION=&1
    
    select &PROJECTION from emp order by 1;
    
    exit
    
    // running script for single column
    /home/billy/sql> sqlplus scott/tiger @show-employees.sql ename
    
    SQL*Plus: Release 11.2.0.2.0 Production on Thu Apr 18 08:01:10 2013
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, Oracle Label Security,
    OLAP, Data Mining, Oracle Database Vault and Real Application Testing options
    
    ENAME
    ----------
    ADAMS
    ALLEN
    BLAKE
    CLARK
    FORD
    JAMES
    JONES
    KING
    MARTIN
    MILLER
    SCOTT
    SMITH
    TURNER
    WARD
    
    14 rows selected.
    
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, Oracle Label Security,
    OLAP, Data Mining, Oracle Database Vault and Real Application Testing options
    
    // running script for all columns using asterisk - and to prevent bash from processing
    // the asterisk as a file/dir listing parameter, we escape the character using a slash
    /home/billy/sql> sqlplus scott/tiger @show-employees.sql \*
    
    SQL*Plus: Release 11.2.0.2.0 Production on Thu Apr 18 08:01:17 2013
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, Oracle Label Security,
    OLAP, Data Mining, Oracle Database Vault and Real Application Testing options
    
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          7369 SMITH      CLERK           7902 1980/12/17 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 1981/02/20 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 1981/02/22 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 1981/04/02 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 1981/09/28 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 1981/05/01 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 1981/06/09 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7839 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 1981/09/08 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 1987/05/23 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 1981/12/03 00:00:00        950                    30
          7902 FORD       ANALYST         7566 1981/12/03 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 1982/01/23 00:00:00       1300                    10
    
    14 rows selected.
    
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, Oracle Label Security,
    OLAP, Data Mining, Oracle Database Vault and Real Application Testing options
    
  • 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.

  • pass the parameter in PL/SQL on UNIX "such what."

    Hello
    I need the 4 parameters of Oracle procedure through Unix Shell script...
    procedure signature :-
    PROCEDURE Builder(csvFileName OUT VARCHAR2,pdfFileName   OUT VARCHAR2, fileId IN NUMBER, csvresult OUT VARCHAR2,pdfresult OUT VARCHAR2);
    UNIX Shell script:
    BudResult=$(exec_Builder $fileId)  
    echo $BudResult | read csvfileName pdfFileName csvresult pdfresult
    Problem: 1 suppose pdffile pdfresult has Null values in the procedures of the Oracle, and unix shell will read parameters with spaces so
    I am incorrect parameter values in UNIX script.
                   
    Oracle Procedure result:                   Unix Shell Result
    csvfile = ABC.csv                         csvfile = ABC.csv
    pdfFile = NULL                            pdfFile = Success
    csvresult = Success                       csvresult = 
    pdfresult = NULL                          pdfresult = 
                   
    2. suppose csvresult has value "Userdefined Exception" in oracle procedure but Unix reads it as following
    
    Oracle Procedure result:                 Unix Shell Result
    csvfile = ABC.csv                         csvfile = ABC.csv
    pdfFile = XYZ.pdf                         pdfFile = XYZ.pdf
    csvresult = Userdefined Exception         csvresult = Userdefined
    pdfresult = Success                       pdfresult = Exception Success
    In nut shell how to pass the parameter "like what" PL/SQL in UNIX...

    Thank you
    Sandy

    So, what kind of problem you know now? What output do you get it?

    echo oenResult=$oenResult
    
  • 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;
    
  • drop and re-create the table using dynamic sql

    The following procedure should drop the table and re-create it. Currently, I get the dbms_output of the query. If I run the query only, it works well. but through the procedure, it does not work. Please help me

    PROCEdure emp_backup is
    sql_txt varchar2(10000);
    begin
         begin
         EXECUTE IMMEDIATE 'drop table emp_backup ' ;
         exception
         when others then
         null;
    
         sql_txt:= 'CREATE TABLE emp_backup as ' ||
                     'select * from emp  '||
                     'where dep_no=10 ' ;
         dbms_output.put_line(sql_txt);
         EXECUTE IMMEDIATE sql_txt;
    Exception
    when others then
    Null;
    
    End;

    Daniel wrote:
    I'm getting following error ORA-01031: insufficient privileges

    What is the command to grant privileges to this

    GRANT CREATE TABLE TO <>
    

    Detaching Frank, however, and echoing my previous comment, let them down and to re-create the tables makes no sense. It is logical to truncate a table if you test a load. If you build a data warehouse, it makes sense to delete and re-create a partition if you rerun a load for a particular date and that you have daily partitions. Deletion and recreation of a table in a stored procedure is not a reasonable way to test a system (nor is there a reasonable way to approach change control issues that will inevitably produce when you need to change the structure of a table).

    Justin

  • 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.

  • 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().

  • 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> 
    
  • 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.

  • Change the parameter [] strings in a sub - bound dynamically VI

    I'm in a situation where I need to use the sub-panels to dynamically bind subVIs for data entry. I also like having the calling VI to change the [] parameter strings several enumerations in the Subvi, but this doesn't seem to be possible, as the Subvi is not in edit mode. Does anyone know of a way around this?

    I read data from a file to initialize the enums, so that I can have the Sub - VI read the file instead, but I was hoping to do it once in the main VI and send strings to the subVIs to speed up execution.

    Thank you!

    derekemuff wrote:

    I read data from a file to initialize the enums, so that I can have the Sub - VI read the file instead, but I was hoping to do it once in the main VI and send strings to the subVIs to speed up execution.

    It's impossible.  Enums are set in stone at run time.  Oh wait, you try to use the script running.  Sorry, it does not work.  Note that the property for the [Strings] node for the enum is blue?  That tells you it is a script node and is useful for mounting screws over time edit.

    As RavensFan said, you use a ring.  Their data type is a real number.

  • How the date can be filled with timestamp in dynamic sql

    Hi all

    Below we have sql

    v_stmt: = ' MERGE IN MTH_EQUIPMENTS_EXT_B ED

    WITH THE HELP OF)

    SELECT TAG_DATA,

    EQUIPMENT_FK_KEY,

    WORKORDER_FK_KEY,

    SEGMENT_FK_KEY,

    SHIFT_WORKDAY_FK_KEY,

    HOUR_FK_KEY,

    ITEM_FK_KEY,

    READ_TIME,

    ATTR_GROUP_ID,

    RECIPE_NUM,

    RECIPE_VERSION,

    NVL (FND_GLOBAL. User_Id,-1) l_updated_by,.

    NVL (FND_GLOBAL. Login_Id,-1) l_last_update_login

    OF MTH_TAG_READINGS_T_STG

    WHERE DB_COL = ' | " ' || v_colname | " ' ||') TS

    WE (';)

    v_stmt: = v_stmt | "ED. EQUIPMENT_PK_KEY = TS. EQUIPMENT_FK_KEY AND

    ED. READ_TIME = TS. READ_TIME AND

    ED. ATTR_GROUP_ID = TS. ATTR_GROUP_ID)

    WHEN MATCHED THEN

    UPDATE

    GAME ED.'. v_colname |' = TS. TAG_DATA,

    ED. LAST_UPDATED_BY = 1, ";

    v_stmt: = v_stmt | "ED. LAST_UPDATE_LOGIN = TS.l_last_update_login

    WHEN NOT MATCHED THEN

    INSERT ('| v_colname |', EXTENSION_ID, EQUIPMENT_PK_KEY, WORKORDER_FK_KEY, SEGMENT_FK_KEY, SHIFT_WORKDAY_FK_KEY, HOUR_FK_KEY, ITEM_FK_KEY, READ_TIME, ATTR_GROUP_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY,';)

    v_stmt: =.

    v_stmt | ("LAST_UPDATE_LOGIN, CREATED_BY, CREATION_DATE, RECIPE_NUM, RECIPE_VERSION)

    VALUES (TS. TAG_DATA, EGO_EXTFWK_S.NEXTVAL, TS. EQUIPMENT_FK_KEY, TS. WORKORDER_FK_KEY, TS. SEGMENT_FK_KEY, TS. SHIFT_WORKDAY_FK_KEY, TS. HOUR_FK_KEY, TS. ITEM_FK_KEY, TS. READ_TIME,';

    v_stmt: = v_stmt | "TS. ATTR_GROUP_ID,' | '''|| SYSDATE | "'| ', 1, TS.l_last_update_login, TS.l_updated_by,'|"' | SYSDATE | " ' ||', TS. RECIPE_NUM, TS. RECIPE_VERSION)';

    EXECUTE IMMEDIATE v_stmt;

    After you run the above SQL last date of update in MTH_EQUIPMENST_EXT_B is filled with sysdate but timestamp is not its always 00:00:00. Can we have timestamp also populated through dynamic sql in the last update date

    Kind regards

    Amrit

    Values to hardcode in the dynamic SQL - never use bind variables:

    v_stmt: = ' MERGE IN MTH_EQUIPMENTS_EXT_B ED

    WITH THE HELP OF)

    SELECT TAG_DATA,

    EQUIPMENT_FK_KEY,

    WORKORDER_FK_KEY,

    SEGMENT_FK_KEY,

    SHIFT_WORKDAY_FK_KEY,

    HOUR_FK_KEY,

    ITEM_FK_KEY,

    READ_TIME,

    ATTR_GROUP_ID,

    RECIPE_NUM,

    RECIPE_VERSION,

    NVL (FND_GLOBAL. User_Id,-1) l_updated_by,.

    NVL (FND_GLOBAL. Login_Id,-1) l_last_update_login

    OF MTH_TAG_READINGS_T_STG

    WHERE DB_COL =: 1) TS

    WE (';)

    v_stmt: = v_stmt | "ED. EQUIPMENT_PK_KEY = TS. EQUIPMENT_FK_KEY AND

    ED. READ_TIME = TS. READ_TIME AND

    ED. ATTR_GROUP_ID = TS. ATTR_GROUP_ID)

    WHEN MATCHED THEN

    UPDATE

    GAME ED.'. v_colname |' = TS. TAG_DATA,

    ED. LAST_UPDATED_BY = 1, ";

    v_stmt: = v_stmt | "ED. LAST_UPDATE_LOGIN = TS.l_last_update_login

    WHEN NOT MATCHED THEN

    INSERT ('| v_colname |', EXTENSION_ID, EQUIPMENT_PK_KEY, WORKORDER_FK_KEY, SEGMENT_FK_KEY, SHIFT_WORKDAY_FK_KEY, HOUR_FK_KEY, ITEM_FK_KEY, READ_TIME, ATTR_GROUP_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY,';)

    v_stmt: =.

    v_stmt | ("LAST_UPDATE_LOGIN, CREATED_BY, CREATION_DATE, RECIPE_NUM, RECIPE_VERSION)

    VALUES (TS. TAG_DATA, EGO_EXTFWK_S.NEXTVAL, TS. EQUIPMENT_FK_KEY, TS. WORKORDER_FK_KEY, TS. SEGMENT_FK_KEY, TS. SHIFT_WORKDAY_FK_KEY, TS. HOUR_FK_KEY, TS. ITEM_FK_KEY, TS. READ_TIME,';

    v_stmt: = v_stmt | "TS. ATTR_GROUP_ID,: 2, 1, TS.l_last_update_login, TS.l_updated_by,: 3, TS. RECIPE_NUM, TS. RECIPE_VERSION)';

    V_stmt EXECUTE IMMEDIATE

    With the HELP of v_colname,.

    SYSDATE,

    SYSDATE;

    SY.

Maybe you are looking for

  • Firefox does not go to all pages

    I went to work today and when I opened Firefox my homepage came to the fine. Now, whenever I type a website in html bar I get this. A record of the AUP Cable Acceptable Use Policy/equipment agreement In order to complete the registration a process ca

  • Oberon Media games does not work

    I have 2 games Oberon Media, that run is no longer. Despite having been advised to do various things by Oberon, I always get the message "launch exe - unidentified publisher wants to access your computer". When I allow it and click the 'Play now' gam

  • Array of strings to a menu control

    Hello I want to display my name of the worksheet in Excel as a menu choice for the user. How to make an array of strings as a menu control? Example I got 5 journal name and how can I do as a control?

  • advice antivirus

    Hello I have an itsa windows vista computer and Im having problems mind virus can give u me more information, where can I go to download free antivurus so tat my computer can get cleaned up please I really need your advice and so your answer

  • Windows Media Player will play is no longer my local computer .wmv videos.

    Windows Media Player will play is no longer my local computer .wmv videos. There is no error message. The circle just keeps going around and around and after as long as 9 minutes, the video still has not played.