Using variables in sql, unexpected results queries coldfusion.

I came across a somewhat embarrassing problem. I'd be interested to see if the following works for other people:

< cfset sql_var "'something', 'something'" is >
< = 'test' datasource cfquery name = "db" >
Select id from table where unnom (#sql_var #)
< / cfquery >

Because it is that which produces a sql error - coldfusion tries to run the query in the form

Select id from table where unnom in ("something", "thing")

It is with the double quotes around each of the strings, even if it has not been specified in the sql_var variable.

So I tried this:

< cfset sql_var = "something","something else" > ".
< = 'test' datasource cfquery name = "db" >
Select id from table where unnom in (' #sql_var # ')
< / cfquery >

Where the sql_var variable has that single quotes between the two strings, and I added the quotes to the select statement. It produces no error, but no results either. Running sql is

Select id from table where unnom ('something', 'something')

Which is exactly as it should. I copy and paste the exact same query into the database and it produces results - but when coldfusion runs the query it doesn't. Executes the query with without product quotes a sql error, which is what I expect wopuld.

Which leaves me somewhat at a loss. Anyone got any ideas?

Running CF 6.1 (I think) using a database MySQL, if that makes a difference to anything.

It is with the double quotes around each of the strings, even if it has not been specified in the sql_var variable.

In Coldfusion, 'something' and 'something' are the same thing. You should expect that Coldfusion could pass from one to the other.

Where the sql_var variable has that single quotes between the two strings, and I added the quotes to the select statement. It produces no error, but no results either. Running sql is
Select id from table where unnom ('something', 'something')

I don't think that it is running the query. Before moving on to the string, "something", "something else" to the Coldfusion query will automatically escape the single quotes on either side of the comma. This is the default behavior. The resulting query is

Select id from table where unnom in (' something "," something else "")

To avoid these complications, use the PreserveSingleQuotes() function. Therefore,.



Select id from table where unnom in (#preservesinglequotes (sql_var) #)

Tags: ColdFusion

Similar Questions

  • ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    Hello!

    I have a simple object type and a proecdure in which I am trying to use it to insert into another table

    -object

    CREATE ORREPLACETYPEmt_mtg ASOBJECT

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    CREATE ORREPLACETYPEREF_MTG ASTABLEOFMt_MTG ;

    -same structure as the use of sampletbl target table in the cursor query

    create table tbl_MT_MTG

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    -procedure

    CREATE ORREPLACEINTERIORTEST_PROCEDURE1

    AS

    ref_cur sys_refcursor ;

    REFR ref_mtg ;

    BEGIN

    OPEN ref_cur FOR

    Select acol,

    BCOL

    DE sampletbl rownum<10;

    Fetch ref_cur in bulk collectintorefr;

    Insert intotbl_MT_MTG(acol,bcol)selectacol,bcol fromtable(refr);

    commit;

    CLOSE Ref_cur;

    END;

    /

    When I run this procedure fails with

    ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    ORA-06512: at "TEST_PROCEDURE1", line 10

    ORA-06512: at line 2

    Any help on this please...

    Thanks to an OLD POST below

    so perfect helped me! Thank you

    Tubby

    After 5 years of more :-)

    How to store refcursor in collection How to store refcursor in collection

  • How can I use variable presentation logic SQL

    Hi Experts,

    How can I use variable SQL logical presentation. I need the exact syntax. Kindly help me to achieve this goal.

    "Time". "" Date "between the Date of 2014 '-1-17 'and Date' ' 2014-2-16

    Thanks in advance

    Asim

    It's done... We can use it in the logical query with the same syntax where we use in converting this filter as SQL...

  • Default presentation variable used in the SQL filter expression

    Hello
    I am trying to use a default value for a variable used in a sql expression in a filter presentation and could use assistance on why obiee stifles the syntax.

    I have a report prompted with a prompt on the name of the month (variable presentation framework - pres_month_name). The value read is used in a filter as an sql expression. The sql expression is a DEAL on the variable of presentation and its conversion to a number based on business rules.

    In the sql expression, I give you the presentation variable a default value for a variable of repository - rep_default_month_name. Repository variable is correct and no, based on business rules, returns an appropriate default month name.

    Now, if I hard code the value by default, there is no problem. Here is a sample of the filter:
    The month number less than or equal to * DEAL "{pres_month_name} {OCT}" WHEN "NOV" THEN 10 WHEN... END *.

    Notice that the variable of presentation is between single quotes, because this is an area of character. Once more, it works fine, but I don't want to hardcode the default, I want it based on the variable repository, therefore:

    The month number less than or equal to * DEAL '{pres_month_name} {ValueOf (rep_default_month_name)}' WHEN 'NOV' THEN 10 WHEN... END *.

    By having this syntax for default of the variable of the presentation, I receive a message from the incorrect values in a filter.

    This report is not only used on a dashboard, but used in a briefing book as well. Whenever a briefing book is updated, by default the presentation variable is used, because obviously, the presentation is not available in a briefing, and I don't want to use a hard-coded value.

    I could duplicate the report and adjust the sql to not use the presentation variable, but always use the repository variable that returns a month by default, but I would be duplication of effort and I have to do this on several requests.

    Thanks for the help!

    Try this syntax described in the blog of Shiva that follows...

    http://shivabizint.WordPress.com/2008/10/02/Oracle-BI-EE-variables-overview/

  • Error using variable presentation of Expression SQL

    Hi all

    I get an error - '... Error to break information... "due to a variable used in a SQL Expression. It probably has something to do with a problem of data type. I have reduced the use of the presentation of the error variable.

    I'll put a variable pres_mth_nme_to, presentation, from a prompt of dashboard. The line contains a month name.
    I use the variable of presentation as part of a SQL Expression in a filter. Most of the SQL Expression is to use the
    presentation in ONE variable and assign a value accordingly. For example:

    Column: kind of month value
    Operator: between
    Value: * 10 *.
    SQL expression: * case @{pres_mth_nme_to} {a few default} WHEN "NOV" THEN '10' WHEN 'DEC' THEN '11' WHEN 'JAN' THEN '12' WHEN 'FEB' THEN '13' WHEN... END *.

    The name of the month is in character. If I was in this hard-coding, I don't get the error. For example:
    CASE 'SEP' WHEN 'NOV' THEN '10' WHEN 'DEC '... END

    It is something to do with the data type of the command prompt and to be used in the comparison. If I use a CAST, the problem persists.

    CASE DROPS (@{pres_mth_nme_to} as char (3)) WHEN 'NOV' THEN... END

    If I'm in the responses, the problem does not exist, I guess because of default values. If I'm on the dashboard, there is not, I guess because of the reception of the prompt value.

    I don't know what I'm missing. Any suggestions?

    Thank you.

    DJ,

    If the formula presented by you is exactly true, I mean that it was not made to present as an example in the forum, you must include the variable presentation between apostrophes.
    either your formula should look something like
    Case ' @{pres_mth_nme_to} {a few default}' WHEN 'NOV' THEN '10' WHEN 'DEC' THEN '11' WHEN 'JAN' THEN '12' WHEN 'FEB' THEN '13' WHEN... END

    Let me know if it solved the problem...

    -bifacts
    http://www.obinotes.com

    Published by: bifacts on October 25, 2010 13:50

  • Retrieve and display a result set using the dynamic sql?

    Hi all

    How would display a result set in Oracle using the dynamic SQL? Reason being, the table where I'd retrieve and display the result set is a GLOBAL TEMP TABLE created in a stored procedure. If I try to use the loop as usual, the compiler complains that the table does not exist. This makes sense because the compiler does not recognize the table because it is created dynamically. Here is an example:

    create or replace PROCEDURE maketemptab IS
    sql_stmt VARCHAR2 (500);
    OutputString VARCHAR2 (50);

    BEGIN
    -create temporary table
    sql_stmt: = ' CREATE of TABLE TEMPORARY GLOBAL globtemptab (id NUMBER, col1 VARCHAR2 (50))';
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... created table ');

    -Insert a row into the temporary table
    sql_stmt: = "INSERT INTO globtemptab values (1, 'some data of a test')';"
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Insert a row into the temporary table
    sql_stmt: = ' INSERT INTO globtemptab values (2, "some more test data");
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Select the row on temporary table
    sql_stmt: = 'SELECT col1 FROM globtemptab WHERE id = 1';
    EXECUTE IMMEDIATE sql_stmt INTO outputstring;
    dbms_output.put_line ('... selected line: ' | outputstring);

    -drop temporary table
    sql_stmt: = 'DROP TABLE globtemptab;
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... moved table ');

    -display the result set
    for tabdata loop (select col1 from globtemptab)
    dbms_output.put_line ('... test of recovered data are' | tabdata.col1)
    end loop;
    end;


    In short, how to rewrite the SQL below the comment "to display the result set" using the dynamic sql?

    Thank you
    Amedeo.

    Hello

    Try this:

    CREATE OR REPLACE PROCEDURE maketemptab IS
       sql_stmt     VARCHAR2(500);
       outputstring VARCHAR2(50);
       v_cursor     SYS_REFCURSOR;
       v_col1       VARCHAR2(30);
    BEGIN
       -- create temp table
       sql_stmt := 'CREATE GLOBAL TEMPORARY TABLE globtemptab(id NUMBER, col1 VARCHAR2(50))';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table created');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (1, ''some test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (2, ''some more test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- select row from temp table
       sql_stmt := 'SELECT col1 FROM globtemptab WHERE id=1';
       EXECUTE IMMEDIATE sql_stmt
          INTO outputstring;
       dbms_output.put_line('...row selected: ' || outputstring);
    
       OPEN v_cursor FOR 'SELECT col1 FROM globtemptab';
    
       LOOP
          FETCH v_cursor
             INTO v_col1;
          EXIT WHEN v_cursor%NOTFOUND;
          dbms_output.put_line('...test data retrieved is' || v_col1);
       END LOOP;
       CLOSE v_cursor;
    
       -- drop temp table
       sql_stmt := 'DROP TABLE globtemptab';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table dropped');
    END;
    /
    

    Kind regards

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

  • variable with sql reuse various clauses

    Hello

    Is it possible to reuse the same variable with sql different queries in the packages...

    Example:

    I have a Word to say variable

    name of the variable 1): filename

    (2) in variable query: select 'emp.txt' of the double

    so using the name of this variable in the data store, I'm passing filename dynamically, but I need to change the file name to dept.txt emp.txt missing emp.txt food.

    A solution on my side uses a table dump with the file name. more without the use of db tables

    Please share views

    See you soon,.
    Surya

    You will then need the help of beanshell java technology. Variable2 take the second query in cooling mode. Now, create a procedure. At the 1st step of technology will be java beanshell with below codes.

    <>
    String xtr = "#variable2";
    @>

    Now in ko-> step use variable1 in assign mode

    Variable1 =<@=xtr@>

    It will certainly work.

    Thank you.

  • Using variables on localization files

    Hi all!

    I would like to know if it is possible to use variables on the HR files, so they could be replaced by a dynamic text while the application is running.

    My point is, I need to post this message on an alert:

    "Hi Carlos, the pleasure of you review", "Carlos" is the user name and of course it's different for each installation.

    Must be something like this:

    key: GREETINGS_MSG

    value: Hi %s, the pleasure to see you

    And then.

    Dialog.Alert (_res.getString (GREETINGS_MSG, "Carlos").

    So, is it possible to do this?

    Thank you!

    According to what you're asking, it's what I found.

    See if you can try this:

    http://www.BlackBerry.com/developers/docs/5.0.0api/NET/rim/device/API/i18n/MessageFormat.html

    http://Java.Sun.com/J2SE/1.3/docs/API/Java/text/MessageFormat.html

    Example:

    Object[] arguments = {     new Integer(7),     new Date(System.currentTimeMillis()),     "a disturbance in the Force" };
    
     String result = MessageFormat.format(     "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",     arguments);
    
  • Delete duplicate of PL/SQL command result values

    Hi all

    I am working on SQL Developer 4.1 and using sub PL/SQL command to retrieve the unique values of Batch_No with matching data:

    Row_ SELECT TO_NUMBER (ROW_NUMBER () (IN Batch_No ORDER)),

    Batch_No,

    Record_Source,

    Create_Date,

    Submitter

    Of

    (SELECT DISTINCT Batch_No,

    RecSource Record_Source,

    Get_Date_From_Remedy (Create_Date) Create_Date,

    Submitter

    OF VOD_SEET_Invoices

    WHERE (Batch_No <>"NA")

    ) batch

    UNION

    Row_ SELECT TO_NUMBER (ROW_NUMBER () (IN Batch_No ORDER)),

    Batch_No,

    Record_Source,

    Create_Date,

    Submitter

    Of

    (SELECT DISTINCT Batch_No,

    'Penalties' Record_Source,

    Get_Date_From_Remedy (Create_Date) Create_Date,

    Submitter

    OF VOD_SEET_Penalties

    WHERE (Batch_No <>"NA")

    ) batch

    The output of the above query has many duplicates in Batch_No, no idea how to rewrite the above query so that only unique values of Batch_No to the associated data are retrieved without duplicates?

    Thanks in advance,

    Kind regards

    Mona Fathy

    For example...

    If your logic is that "Penalties" must have priority over the other record (assuming another in this scenario) of the first query, if there is a record of penalties, then by doing the following:

    Select row_number() (order Batch_No) Row_

    Batch_No

    Record_Source

    Create_Date

    Author

    de)

    Select row_number() over (partition by order of batch_no to decode (record_source, 'Penalties', 0, 1)): the nurse

    batch_no

    record_source

    create_date

    author

    de)

    Select Batch_No

    Record_Source

    Create_Date

    Author

    to select (separate Batch_No

    RecSource Record_Source

    Get_Date_From_Remedy (Create_Date) Create_Date

    Author

    of VOD_SEET_Invoices

    where (Batch_No <> 'NA')) batch

    Union

    Select Batch_No

    Record_Source

    Create_Date

    Author

    to select (separate Batch_No

    "Penalties" Record_Source

    Get_Date_From_Remedy (Create_Date) Create_Date

    Author

    of VOD_SEET_Penalties

    where (Batch_No <> 'NA')) batch

    )

    )

    where rn = 1

    determines a row_number in each batch_no, ordering sanctions first duplicate records, and other records.

    Then the outer query takes just the first records of each batch_no by applying the "where rn = 1" clause.

    The outer query then applies his own row_number compared to results sorted by batch_no.

  • Need to check delays in update of 1000 lines using the PL/SQL procedure.

    Hi all

    I'm new to PL/SQL. I need your help to build a procedure that executes the following statement and follows the time of update of 1000 rows. This is to check the performance of the database. I need to print the timestamp of start before the update and end timestamp after update. I need to do for the 1000 lines. The statement that will be used in the procedure is:

    SELECT

    'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').

    ', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').

    ', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').

    "', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').

    "', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | NVL (TO_CHAR (START_TS), 'NULL').

    ', END_TS =' | NVL (TO_CHAR (END_TS), 'NULL') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').

    "', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').

    ', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').

    ', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | NVL (TO_CHAR (LAST_UPD), 'NULL') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').

    "', W_INSERT_DT = ' | NVL (TO_CHAR (W_INSERT_DT), 'NULL') |', W_UPDATE_DT = ' | NVL (TO_CHAR (W_UPDATE_DT), 'NULL').

    ', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |

    NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; »  OF XXAFL_MON_FACTS_F;

    The above query creates instructions of update that must be executed 1000 times and the time required to update the 1000 lines should be followed.

    Thanks in advance!

    Code horribly wrong!

    Why this approach?

    Dynamic SQL is almost NEVER needed in PL/SQL. And if you think it's necessary and taking into account what is displayed as being problems here, you have a 99% chance of being wrong.

    This 1% where dynamic SQL is necessary, he will WITH bind variables to create shareable SQL, decrease memory requests, decrease the likelihood of a fragmented shared reel and decrease the burning CPU cycles on hard analysis.

    An example below. Your approach is the 1st. One that is slower than the correct approach to 37 (x_!) ...

    SQL> create table t ( n number );
    
    Table created.
    
    SQL>
    SQL> var ITERATIONS number;
    SQL> exec :ITERATIONS := 100000;
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using Hard Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ('||i||')';
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Hard Parsing
    Elapsed: 00:02:00.33
    SQL>
    SQL> TIMING START "INSERTs using Soft Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ( :1 )' using i;
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Soft Parsing
    Elapsed: 00:00:06.06
    SQL> drop table t;
    
    Table dropped.
    
    SQL> create table t( n number );
    
    Table created.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using a single parse and repeatable statement handle "
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  insert into t values ( i );
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using a single parse and repeatable statement handle
    Elapsed: 00:00:04.81
    SQL>
    
  • error in pseudo-column "DECODE" can be used within an SQL statement

    Hi gurus,

    Your help is grealty appreciated. Please help me.


    I'm trying to see if I can use the function decode as below and get the error, here below vPlatformfrom value would be QA or MTS


    vDataBase1 :='@'|| Decode (vPlatformfrom, 'STD', 'STD', 'QA', 'QA')


    Before we check function NVL to a single platform, but now we need the database based on the platform is here.

    -vDataBase1 :='@'|| NVL (vPlatformto, 'MTS');

    Error:

    PLS-00204: pseudo-column "DECODE" or function may be used within an SQL statement

    > So, here, instead of the decode function, I can use this case as below:

    Well... you can, but why?  In your CASE, you simply return the same value as the variable.

    You might as well use: vDataBase1: = vPlatformfrom;  It would reach exactly the same thing.

    If vPlatformfrom can be a null value, you will need to decide what database to use or an exception.  I think you're original code (NVL) were probably more correct, but I can't decide which.

    (and don't bother selecting double, it is an unnecessary sql statement which must be analysed, etc..)

  • Use business function: SQL profile

    SQL profile is only a function of Enterprise edition as in, just by using a profile that was not created in this database?

    I have a development environment, which is available for all.  I create a SQL profile for a bad statement on this database of the company, then I transfer in a database standard edition to help:

    How to copy one database to another SQL profile. | David Marcos & amp; #039; Blog

    When I now run the statement, I see that he is using the profile, but the following statement returns without success for me after using this feature:

    name of the pass for a50

    ALTER session set nls_date_format = "DD month yyyy";

    Select ' # use features of Enterprise Edition: "of the double;

    SELECT name, version, first_usage_date, last_usage_date of dba_feature_usage_statistics, whose name in ("Advanced Replication", "AWR report", "Basic AWR", "Automatic repository of workload", 'Encryption ","backup ZLIB Compression', "Block Media Recovery", "Database Replay: workload Capture ',' Database Replay: Replay of the workload ', 'Diagnostic Pack', em Page Performance", "Flashback Database" ") ","Security label"," OLAP - analytic workspaces, "OLAP - Cubes", "Oracle Secure Backup", "Parallel Execution of DDL SQL" 'Parallel DML SQL performance', "Parallel Execution of SQL query", "Partitioning (user)", "Real Time SQL Monitoring", "Result Cache", "SQL Monitoring and Tuning pages", 'SQL Plan Management', 'SQL Tuning Set (user)', "SecureFile encryption (user)", "Space", 'MView Tune', 'Tuning Pack', 'Automatic Maintenance - Setup SQL', 'SQL Profile. (, "SQL Tuning Advisor", "SQL Tuning Set (user)") and first_usage_date is not null order by ASC first_usage_date;

    So my question is: if I haven't created the profile in the database Standard Edition... it is just been imported from another data base... Am, I violated my license?

    Hello

    > So my question is: if I haven't created the profile in the database Standard Edition... it is just been imported from another data base... I'm violating my license?

    You break even your EE Oracle license, if you do not have a valid diagnostic + Tuning package for it. You can reproduce this very easily, as described by Kerry Osborne here: requirements for licenses for SQL profiles

    SQL Plan Management is included in Oracle EE as an alternative, for example: the use of SQL Plan Management and database DBMS_SPM package require a license pack tuning or diagnostic?

    Concerning

    Stefan

  • Oracle 12 c - unexpected result with the insertion of the DBA_VIEWS view

    Hello

    I try inserting the DBA_VIEWS fields in a table belonging to a common C a PDB file ##SA user:

    (a) the PDB PDBORCL using user C ##SA connection:

    SQL * more: Production of liberation 12.1.0.1.0 kills him Sep 10 16:21:39 2013

    Copyright (c) 1982, 2013, Oracle.  All rights reserved.

    Enter the password:

    Last successful login time: kills Sep 10-2013 16:18:26 + 02:00

    Connected to:

    Database Oracle 12 c Enterprise Edition Release 12.1.0.1.0 - 64 bit Production

    With the options of partitioning, OLAP, advanced analytics and Real Application Testing

    C##SA@pdborcl 10.09.2013 > see the con_name

    CON_NAME

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

    PDBORCL

    C##SA@pdborcl 10.09.2013 > see the con_id

    CON_ID

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

    3

    (b) I create the table user SA_VIEWS_V

    C##SA@pdborcl 10.09.2013 > select count (*) in the dba_views;

    COUNT (*)

    ----------

    6220

    1 selected line.

    C##SA@pdborcl 10.09.2013 > create table sa_views_v (owner varchar2 (128), view_name varchar2 (128));

    Table created.

    (c) the insertion in the table SA_VIEWS_V gave me only 65 rows at the same time lines of content 6220 dba_views:

    C##SA@pdborcl 10.09.2013 > INSERT INTO SA_VIEWS_V (OWNER, VIEW_NAME) SELECT MASTER, VIEW_NAME DBA_VIEWS;

    65 lines were created.

    C##SA@pdborcl 10.09.2013 > commit;

    Validation complete.

    C##SA@pdborcl 10.09.2013 > SELECT MASTER, VIEW_NAME DBA_VIEWS;

    ...

    IX

    IX

    IX

    SH

    6220 selected lines.

    (d) you will find above the executed plan of the insert and the single select statement:

    C##SA@pdborcl 10.09.2013 > select * from table (dbms_xplan.display_cursor ('aj3vkggtvv9d9'));

    PLAN_TABLE_OUTPUT

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

    SQL_ID, aj3vkggtvv9d9, number of children 0

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

    INSERT INTO SA_VIEWS_V (OWNER, VIEW_NAME) SELECT VIEW_NAME, MASTER OF

    DBA_VIEWS

    Hash value of plan: 1585970530

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | INSERT STATEMENT.                  |       |       |   136 (100) |          |

    |   1.  LOAD TABLE CLASSIC |                  |       |       |            |          |

    |*  2 |   FILTER                         |                  |       |       |            |          |

    |*  3 |    HASH JOIN |                  |    65.  6045.   136 (0) | 00:00:01 |

    |*  4 |     HASH JOIN |                  |    65.  4875.   132 (0) | 00:00:01 |

    |   5.      NESTED LOOPS |                  |       |       |            |          |

    |   6.       NESTED LOOPS |                  |    65.  3315 |   131 (0) | 00:00:01 |

    |   7.        INDEX SCAN FULL | I_VIEW1 |    65.   325.     1 (0) | 00:00:01 |

    |*  8 |        INDEX RANGE SCAN | I_OBJ1 |     1.       |     1 (0) | 00:00:01 |

    |   9.       TABLE ACCESS BY INDEX ROWID | OBJ$             |     1.    46.     2 (0) | 00:00:01 |

    |  10.      INDEX SCAN FULL | I_USER2 |   131.  3144 |     1 (0) | 00:00:01 |

    |  11.     TABLE ACCESS FULL | USER$ |   131.  2358.     4 (0) | 00:00:01 |

    | * 12 |    TABLE ACCESS FULL | USER_EDITIONING$ |     1.     6.     2 (0) | 00:00:01 |

    |  13.    SEMI NESTED LOOPS.                  |     1.    29.     2 (0) | 00:00:01 |

    | * 14 |     INDEX SKIP SCAN | I_USER2 |     1.    20.     1 (0) | 00:00:01 |

    | * 15 |     INDEX RANGE SCAN | I_OBJ4 |     1.     9.     1 (0) | 00:00:01 |

    | * 16.    TABLE ACCESS FULL | USER_EDITIONING$ |     1.     6.     2 (0) | 00:00:01 |

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

    Information of predicates (identified by the operation identity card):

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

    2 filter (((IS NULL AND "O". ("TYPE #" <>88) OR BITAND ("O". ("" FLAGS ", 1048576) = 1048576 OR

    BITAND ("U". "" SPARE1»(, 16) = 0 OR (((SYS_CONTEXT ('userenv', 'current_edition_name') = ' ORA$ BASE ", AND)))"

    "U"." TYPE #"(<>2) OR ('U'." ' TYPE # '= 2 AND 'U'. "SPARE2" = TO_NUMBER (SYS_CONTEXT ('userenv ',' current_e)) "

    dition_id'))) or IS NOT NULL) AND IS NOT NULL)))

    3 - access("O".") SPARE3 '=' U '. ("" USER # ")

    4 - access("O".") "OWNER # '=' U '. ("" USER # ")

    8 - access("O".") ' OBJ # '=' V '. (' ' OBJ # ")

    12 filter (("TYPE #" =: B1 ET "UE".)) "THE USER #" =:B2))

    14 - access("U2".") TYPE # "= 2, AND"U2"." SPARE2 "= TO_NUMBER (SYS_CONTEXT ('userenv ',' current_editi))"

    on_id')))

    filter (("U2". "TYPE #"= 2, AND "U2"."" SPARE2 "= TO_NUMBER (SYS_CONTEXT ('userenv ',' current_edit))"

    ion_id')))

    15 - access("O2".") DATAOBJ #"=: B1 AND 'O2'." ' TYPE # '= 88 AND 'O2'. "OWNER #"= "U2". ("" USER # ")

    16 filter ((' EU'. "TYPE #" =: B1 AND 'EU '. "THE USER #" =:B2))

    47 selected lines.

    C##SA@pdborcl 10.09.2013 > select * from table (dbms_xplan.display_cursor ('bc4f1jh1snwdp'));

    PLAN_TABLE_OUTPUT

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

    SQL_ID, bc4f1jh1snwdp, number of children 0

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

    SELECT THE OWNER, DBA_VIEWS NOM_DE_VUE

    Hash value of plan: 1508506130

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Pstart. Pstop |

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

    |   0 | SELECT STATEMENT |                  |       |       |     1 (100) |       |       |

    |   1.  PARTITION LIST ALL |                  | 10000 |  1289K |     0 (0) |     1.     2.

    |   2.   TABLE FIXED FULL | X$ COMVW$ 5885ef62 | 10000 |  1289K |     0 (0) |       |       |

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

    14 selected lines.

    You have an idea about this result?

    Thank you in advance,

    Arnaud.

    Arnaud,

    This has a fairly simple explanation.

    In 12cR1, there are common objects, and there are local objects. The definition of a common object is stored in the ROOT, and only a stub for the object is stored in the PDB. The definition of a local object is stored in the PDB.

    When DBA_VIEWS is questioned in a PDB file, so we must return to lines of views both as common as the result of the query. If views Commons are not returned, then several views that a client is used to see in the result of a query DBA_VIEWS to 11.2 and earlier versions not will be seen in paragraph 12.1. For example, ALL_TABLES, DBA_OBJECTS, etc.

    When DBA_VIEWS is questioned in a PDB file, then we extraction of lines for local opinions of PDB and common views of ROOT lines. The first has value ORIGIN_CON_ID equal to the ID of the container of the PDB to which you are connected, and they value ORIGIN_CON_ID equal to the ID of the ROOT container. Given that the recovery of these lines should be done in two different containers, we go through a fixed table X$ COMVW$ *.

    The gap that you are experiencing is because this fixed table based assessment is used only to SELECT and not for etc. SELECT, INSERT AS SELECT, CREATE TABLE AS.

    Let me know if that makes sense.

    Thank you

    Thomas

  • How to pass a list as a bind variable in SQL Developer?

    How can I pass a list as a bind variable in SQL Developer?

    The following query in SQL Developer so work I put ": prmRegionID = 2.

    SELECT COUNTRY_ID,
    COUNTRY_NAME
    OF HUMAN RESOURCES. COUNTRY
    WHERE IN REGION_ID (: prmRegionID);

    The problem is that I can't find how to set ": prmRegionID = 2, 3.

    I know that I can replace ": prmRegionID" by a proxy '& prmRegionID '. The above query will work well with"& prmRegionID = 2" and with "& prmRegionID = 2, 3". "

    But with this solution, I lost all the benefit of the use of bound variables (analysis hard against soft parse, possibility of SQL injection, etc.).

    I'm learning how to do this in SQL, as well as the use of UDT in this thread: How to move a list as a bind variable?

    But with this solution, I've lost nice SQL Developer user interface. In SQL developer, it is easy to test a query using the standard binding variable. When we start the application, a pop up asking for a value of the variable binding.

    With the UDT, the interface request always variable binding standard. You have an idea on how I can get a variable string binding (such as 1, 2, 10) in a set of NUMBER or VARCHAR2? This way I would be able to launch a standard query in SQL Developer to test my application.


    Can someone tell me what is the best approach to this?

    Thank you in advance,


    MB

    Hi Blais,

    Thank you for trying the SQL and PL/SQL instance before coming here - it was definitely the right approach, and you've got some very good suggestions there. Your needs for a invite only bind to the value in the clause list, I think I have a possible solution. I'll introduce you to a list of characters, so you'll have to tweak it for other types of data. First, add the following to your schema:

    create or replace
    TYPE bind_tab_typ AS TABLE OF VARCHAR2(4000);
    
    create or replace
    FUNCTION comma_to_table(iv_raw IN VARCHAR2)
    RETURN bind_tab_typ
    PIPELINED
    IS
       ltab_lname dbms_utility.lname_array;
       ln_len     BINARY_INTEGER;
    BEGIN
       dbms_utility.comma_to_table(list   => iv_raw
                                  ,tablen => ln_len
                                  ,tab    => ltab_lname);
       FOR i IN 1 .. ln_len LOOP
          PIPE ROW (ltab_lname(i));
       END LOOP;
    END;
    

    Now you can write a query, say for scott.dept, as follows, and have executed statement ask the value list in the clause as a single binding variable:

    select *
    from dept
    where dname in (
      select * from table( comma_to_table( :BNDS ))
    );
    

    When you are prompted, provide the list of values separated by a single comma without any extra spaces.

    I don't know if the Varchar2 (4000) really needs to be which is great. I use it because that's what dbms_utility.lname_array uses.

    Kind regards
    Gary
    SQL development team

Maybe you are looking for