Using number as bind varilable in PLSQL block

Hello, I need to use number for below bind variable. How can i achieve this? I am not in the situation that i can not use apha numeric vailable.
Any help is appreciated.
SQL> set serveroutput on
SQL> declare
2 var 1 varchar2(20);
3 var 2 varchar2(20);
4 exec :1 := 100
5 exec :2 := 200
6 begin
7 select count(*) into v_cnt from temptable where no = :1 or no = :2;
8 dbms_output.put_line(v_cnt);
9 end;
10 /
SP2-0552: Bind variable "2" not declared.
SQL>

>
Hello, I need to use number for below bind variable. How can i achieve this? I am not in the situation that i can not use apha numeric vailable.
>
I have no idea what you are saying. You say you 'need to use number' but hen say that you 'can not use apha numeric'. That doesn't make any sense.
You only wrote 11 lines altogether and only half of them are correct.
SQL> set serveroutput on
SQL> declare
2 var 1 varchar2(20);
3 var 2 varchar2(20);
4 exec :1 := 100
5 exec :2 := 200
6 begin
7 select count(*) into v_cnt from temptable where no = :1 or no = :2;
8 dbms_output.put_line(v_cnt);
9 end;
10 /#2 and #3 are wrong for two reasons. First because you put them AFTER the declare and you need to put them before it. They are sql*plus declarations. Second because var names cannot begin with a number.
#4 and #5 are wrong for two reasons. First the assignments need to go AFTER the BEGIN statement. Second you dont' use 'exec' you just assign the value.
#7 is wrong because you never declare 'v_cnt' any where.
If you correct ALL of the above it should work. Don't have your table so can't test.
set serveroutput on
var a varchar2(20);
var b varchar2(20);
declare
v_cnt number;
begin
:a := 100;
:b := 200;
select count(*) into v_cnt from temptable where no = :a or no = :b;
dbms_output.put_line(v_cnt);
end;
/

Similar Messages

  • Using sql type with cursor in plsql block

    I wanted to bulk collect columns in a table into a sqltype .I cannot use plsql type here since I am using it with table function in a merge statement.
    Sample code is like this
    create type t_type as object(empno number);
    create type tab_type as table of t_type;
    1 declare
    2  t1 tab_type;
    3 begin
    4  select empno bulk collect into t1 from emp;
    5 end;
    /I get an error like
    ERROR at line 4:
    ORA-06550: line 4, column 8:
    PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got NUMBER
    ORA-06550: line 4, column 1:
    PL/SQL: SQL Statement ignored
    Pls suggest some alternative

    Hi,
    You cannot bulk collect into a table of objects like this.
    Are you going to use some DML operations on this SQL collections. If yes then you need SQL collections and objects. Otherwise simple PL/SQL objects and collections will do.
    Anyway, to give an alternative.
    This is one way of doing things;
    create table emp(emp_no number(10),emp_name varchar2(100));
    INSERT INTO EMP ( EMP_NO, EMP_NAME ) VALUES (
    1, 'A');
    INSERT INTO EMP ( EMP_NO, EMP_NAME ) VALUES (
    2, 'B');
    INSERT INTO EMP ( EMP_NO, EMP_NAME ) VALUES (
    3, 'C');
    commit;
    create type t_type as object(empno number(10),empname varchar2(100));
    create type n_type as table of number(10);
    create type v_type as table of varchar2(100);
    create type tab_type as table of t_type;
    declare
    t1 tab_type := tab_type();
    t2 n_type := n_type();
    t3 v_type := v_type();
    begin
    select emp_no,emp_name bulk collect into t2,t3 from emp;
    t1.extend(t2.count);
    for cnt in t2.first..t2.last
    loop
    t1(cnt):=t_type(t2(cnt),t3(cnt));
    end loop;
    for cnt in t1.first..t1.last
    loop
    dbms_output.put_line(t1(cnt).empno||'---'||t1(cnt).empname);
    end loop;
    end;
    Now if you do not require the DML operations then you can do the following;
    declare
    type n_type is table of number(10);
    type v_type is table of varchar2(100);
    type rec_type is record(empno n_type,empname v_type);
    t1 rec_type;
    begin
    select emp_no,emp_name bulk collect into t1.empno,t1.empname from emp;
    for cnt in t1.empno.first..t1.empno.last
    loop
    dbms_output.put_line(t1.empno(cnt)||'---'||t1.empname(cnt));
    end loop;
    end;
    regards,
    Dipankar.

  • Using Execute Immediate in PLSQL block Vs Stand alone procedure

    I am facing very unusual ( atleast unusual to me ) with usage of "Execute Immediate" statement.
    I have a table dynamic_sql with one column plsql_block as VARCHAR2(4000);
    I have stored some PLSQL blocks ('DECLARE ..... BEGIN.... END.... ) in this column .
    Now I want to execute these PLSQL blocks one after other depending on certain conditions .
    In order to archive this I wrote a PLSQL block as below
    DECLARE
    Cursor c1 is
    select plsql_block from dynamic_sql
    begin
    for irec in c1
    loop
    <<< Condition >>>
    begin
    execute_immediate(irec.plsql_block);
    exception
    when others then
    raise_application_error(-20001,'error ' ||irec.plsql_block||' '||sqlerrm);
    end loop ;
    end ;
    With above PLSQL block , "execute immediate" is executing PLSQL block successfully without any error
    But When I converted above PLSQL block into standalone procedure as shown below , I am getting error .
    CREATE OR REPLACE procedure test AS
    Cursor c1 is
    select plsql_block from dynamic_sql
    begin
    for irec in c1
    loop
    <<< Condition >>>
    begin
    execute_immediate(irec.plsql_block);
    exception
    when others then
    raise_application_error(-20001,'error ' ||irec.plsql_block||' '||sqlerrm);
    end loop ;
    end ;
    BEGIN
    test;
    end ;
    It is showing the value of irec.plsql_block but not showing sqlerrm...
    I found this is very unusual as I am able to execute "execute immediate" statement with PLSQL block but not with similar procedure .
    can anybody explain me why this is happening?
    Thanks in Advance
    Amit

    Hello,
    It doesn't make any sense to add SQLERRM for user defined exception, unless you want to raise application error for already defined error (e.g NOT_DATA_FOUND, ..)
    Check following piece of code and its output,
    CREATE OR REPLACE PROCEDURE myinsert1
    AS
       v_count   NUMBER;
       v_sql     VARCHAR2 (300);
    BEGIN
       v_sql :=
          'INSERT INTO ENTITY_EMPLOYEE VALUES(0,''TIM'',''LASTNAME'',10000)';
       BEGIN
          EXECUTE IMMEDIATE v_sql;
          COMMIT;
       EXCEPTION
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.PUT_LINE (SUBSTR (SQLERRM, 1, 300));
             RAISE_APPLICATION_ERROR (-20002, 'My Error ' || SQLERRM, TRUE);
             RAISE;
       END;
    END;
    Output._
    ORA-20002: My Error ORA-00001: unique constraint (ENTITY_EMPLOYEE_PK) violated
    ORA-06512: at "MYINSERT1", line 21
    ORA-00001: unique constraint (ENTITY_EMPLOYEE_PK) violated
    ORA-06512: at line 2
    Regrds

  • Can I use Count, Max function in PLSQL BLOCK.

    Can U help me to use count, max function in PLSQL BLOCK.
    Because it is giving me error "It is a SQL function"

    SELECT COUNT(*)
    INTO l_variable
    FROM dual;
    Will work inside PL/SQL

  • Output parameter in plsql Block fails

    Hello. I am testing using an anonymous Plsql block with one in and out parameter. The in parameter work fine but when I add the out, the plsql block fails.
    This is my environment on a Windows 7 client attaching to a Solaris server. I am using Powershell 3.0, but it is very similar to #c. I have a .net framework of 4.5.
    PS L064217>    $GAC = $Env:Oracle_Home + "\" + "ODP.NET\bin\4\Oracle.DataAccess.dll"
    PS L064217>    [Void] [Reflection.Assembly]::LoadFile($Gac)
    PS L064217> [Reflection.Assembly]::LoadFile($Gac)
    GAC    Version        Location
    True   v4.0.30319     C:\windows\Microsoft.Net\assembly\GAC_64\Oracle.DataAccess\v4.0_4.112.3.0__89b4
    SQL*Plus: Release 11.2.0.3.0 Production on Wed Nov 28 19:09:57 2012
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing optionsHere is a sample of my test code:
    # Define Plsql Anonymous Block
    $Table1 = 'AdvSearch_Statutes'
    $Table2 = ($Table1).Substring(0, $Table1.Length-1) + '_Docs'
    $Caml_Doc_Id = 'CHP201500010'
    $Sql =  " DECLARE "
    $Sql += "   vCamlId      VARCHAR2(30)  := ':Param1' "
    $Sql += "   vPath_Tx     VARCHAR2(200); "
    $Sql += "   vDelRows_Nr  PLS_INTEGER := 0; "
    $Sql += "   CURSOR Docs_Cur IS "
    $Sql += "       SELECT XPath "
    $Sql += "       FROM $Table2 "
    $Sql += "       WHERE Caml_Doc_Id = vCamlId; "
    $Sql += " BEGIN "
    $Sql += "   OPEN Docs_Cur; "
    $Sql += "   LOOP "
    $Sql += "     FETCH Docs_Cur INTO vPath_Tx; "
    $Sql += "     EXIT WHEN Docs_Cur%NOTFOUND; "
    $Sql += "     IF (DBMS_XDB.ExistsResource(vPath_Tx)) "
    $Sql += "     THEN "
    $Sql += "       DelRows_Nr := DelRows_Nr + 1; "
    $Sql += "       DBMS_XDB.DeleteResource(vPath_Tx, DBMS_XDB.DELETE_RECURSIVE_FORCE); "
    $Sql += "     END IF; "
    $Sql += "   END LOOP; "
    $Sql += "   DELETE FROM $Table2 WHERE Caml_Doc_Id = vCamlId; "
    $Sql += "   vDelRows_Nr := vDelRows_Nr + SQL%ROWCOUNT; "
    $Sql += "   DELETE FROM $Table1 WHERE Caml_Doc_Id = vCamlId; "
    $Sql += "   vDelRows_Nr := vDelRows_Nr + SQL%ROWCOUNT; "
    $Sql += "   SELECT vDelRows_Nr INTO :Param2 FROM Dual; "
    $Sql += " EXCEPTION "
    $Sql += "   WHEN OTHERS THEN ROLLBACK; "
    $Sql += " END; "
    # Set up the Connection and command objects using the prior defined information.  Ensure that
    # Bind by name is used.
    $Conn = New-Object Oracle.DataAccess.Client.OracleConnection($Connect_Str)
    $Cmd  = New-Object Oracle.DataAccess.Client.OracleCommand($Sql, $Conn)
    $Cmd.BindByName = $True
    #Set up the parameters for use with the Sql command.
    $Param1 = New-Object Oracle.DataAccess.Client.OracleParameter
    $Param2 = New-Object Oracle.DataAccess.Client.OracleParameter
    $Param1.DbType = 'AnsiString'
    $Param1.OracleDbType = 'Varchar2'
    $Param1.Direction = 'Input'
    $Param1.ParameterName = ':Param1'
    $Param1.Value = $Caml_Doc_Id
    $Param2.DbType = 'Int32'
    $Param2.OracleDbType = 'Int32'
    $Param2.Direction = 'Output'
    $Param2.ParameterName = ':Param2'
    [Void] $Cmd.Parameters.Add($Param1)
    [Void] $Cmd.Parameters.Add($Param2)
    # Open connection to database and execute the command
    Try
       $Conn.Open();
       $Result = $Cmd.ExecuteNonQuery();
       If ($Param2.Value -Eq $Null) {$Counts = 0}
       Else {$Count  = ($Param2.Value).ToString()}
       Write-Host "Return Code:  $Result"
       Write-Host "Rows Deleted:  $Counts"
    Catch [System.Exception]
      $Param2
      Write-Host $_.Exception.ToString() -ForeGroundColor "Red"
    Finally
      $Conn.Close();
      $Conn.Dispose();
      "`nSuccessful end of script"
    }I have some output. It all seems to be okay. I am following a book rather closely, but after several attempts changing one thing or another, I still cannot find a way to send an out value. I have commented out the " SELECT vDelRows_Nr INTO :Param2 FROM Dual; " and that is the problem statement. Thank you for your help. The first portion is the plsql being echoed back, then I list out what Param2 is defined at. The last bit is the error returned.
    PS L064217> .\Test_Odp_PLsqlBlock.ps1
    DECLARE    vCamlId      VARCHAR2(30)  := ':Param1'    vPath_Tx     VARCHAR2(200);    vDelRows_Nr  PLS_INTEGER := 0;
    CURSOR Docs_Cur IS        SELECT XPath        FROM AdvSearch_Statute_Docs        WHERE Caml_Doc_Id = vCamlId;  BEGIN
      OPEN Docs_Cur;    LOOP      FETCH Docs_Cur INTO vPath_Tx;      EXIT WHEN Docs_Cur%NOTFOUND;      IF (DBMS_XDB.ExistsR
    esource(vPath_Tx))      THEN        DelRows_Nr := DelRows_Nr + 1;        DBMS_XDB.DeleteResource(vPath_Tx, DBMS_XDB.DEL
    ETE_RECURSIVE_FORCE);      END IF;    END LOOP;    DELETE FROM AdvSearch_Statute_Docs WHERE Caml_Doc_Id = vCamlId;    v
    DelRows_Nr := vDelRows_Nr + SQL%ROWCOUNT;    DELETE FROM AdvSearch_Statutes WHERE Caml_Doc_Id = vCamlId;    vDelRows_Nr
    := vDelRows_Nr + SQL%ROWCOUNT;    SELECT vDelRows_Nr INTO :Param2 FROM Dual;  EXCEPTION    WHEN OTHERS THEN ROLLBACK;
    END;
    DbType                  : Int32
    SourceColumnNullMapping : False
    Direction               : Output
    IsNullable              : False
    Offset                  : 0
    OracleDbTypeEx          : Int32
    OracleDbType            : Int32
    ParameterName           : :Param2
    Precision               : 0
    Scale                   : 0
    Size                    : 0
    ArrayBindSize           :
    SourceColumn            :
    SourceVersion           : Current
    Status                  : Success
    ArrayBindStatus         :
    CollectionType          : None
    Value                   :
    UdtTypeName             :
    Oracle.DataAccess.Client.OracleException ORA-01036: illegal variable name/number    at Oracle.DataAccess.Client.OracleEx
    ception.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object sr
    c, String procedure, Boolean bCheck)
       at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
       at CallSite.Target(Closure , CallSite , Object )Edited by: CRoberts on Nov 28, 2012 7:30 PM

    As test
    use NUMBER instead of PLS_INTEGER in PL/SQL
    and
    use Decimal instead of Int32 for Oracle parameter datatype

  • Default form value using sql with bind variable

    I wish to create a form based upon a table with a foreign key. I wish to add a field to the form that is an uneditable text field with a default value using sql of 'select name from other_table where other_table_id = ?' where ? is a bind variable defined by a hidden field which is the value of the foreign key identified at runtime. How can this be done?
    null

    I don't think that will work. I have multiple people accessing the Portal at the same time with the same login (or lack of as public will be the most common user). I could set it easily enough as the value is passed to the form by a link object, so I could add it to the before page plsql block and set the value. But I am uncertain how it will behave in a multi-user mutlitasking environment.
    Maybe I should describe what I am looking to accomplish. I want to create a display above a form that will list static details from other tables (i.e. when editing a user's phone number, which is in one table, you want the user to see the person's name, which is in another table, and the form is based upon the phone table) ...
    Just as I am thinking about it, I thought of an idea. I could put some specific code in the before displaying page plsql section to query the database and use htp to output the information for data not in the table the form is based upon. I will try this and see how it works. It would have been nice to have just created a field that is not editable and had a default value, but this should work as well.
    Let me know if you see any problem with this or if you have any better suggestions.
    Thanks for the fast response.

  • Plsql block error

    I have small PLSQL block with a bind variable in it which throws an error on its execution.
    declare
    cursor c1 is select product_name from PRODUCTS where month=:m;
    begin
    for i in c1 loop
    dbms_output.put_line(i.product_name);
    end loop;
    end;
    It thows the error
    ORA-01008: not all variables bound
    Is it not possible to have a bind variable in a cursor?
    Please help
    Regards

    If you're using SQL*Plus you need to declare and set the bind variable...
    SQL> set serverout on;
    SQL> var d number;
    SQL> exec :d := 20;
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.07
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    cursor c1 is select ename from emp where deptno=:d;
      3  begin
      4    for i in c1 loop
      5      dbms_output.put_line(i.ename);
      6    end loop;
      7* end;
    SQL> /
    SMITH
    JONES
    SCOTT
    ADAMS
    FORD
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.06
    SQL>

  • Need to write a plsql block for calling another procedure.

    Hi Guys,
    I have a requirement to write a plsql block and to call another procedure which is having 5 parameters (each parameter having multiple values). Calling procedure generates one SQL query and it needs to be generated all combinations and print in another table.
    I need to pass multiple values for first three parameters from my PLSQL block and run.
    call sample proc:
    procedure(
    param1 varchar2,
    param2 p_varchar2,
    param3 p_varchar2,
    param4 in varchar2,
    param5 in number
    is
    begin
    ls_sql_query := 'with client_query as (select * from table)';
    end;
    Thanks in advance!
    Rgds,
    LRK

    This article is on exactly your subject. It is worth a careful read.
    Ask Tom: On Popularity and Natural Selection
    I paraphrase: "Always code a reference to every possible bind variable but do so in such a way that the optimizer removes the bind variable for us if we aren't going to actually use it in that particular execution of the SQL statement."
    P.S. This is the same answer I gave when you asked the same question earlier.

  • Execute immediate issue while calling a procedure from plsql block

    Hi all,
    I have the following simple code ,my execute immediate is not working(I am pasting the error below as well)
    CREATE OR REPLACE PROCEDURE CALL_RAHUL_PROCEDURES
    AS
    strng varchar2(1000);
    BEGIN
    for i in (select proc_name,flag,id from rahul_procedures order by id)
    loop
    if (i.flag = 'Y')
    then
    strng := 'exec '||i.proc_name||'(''rahul'')';
    dbms_output.put_line(strng);
    execute immediate strng;
    end if;
    end loop;
    END CALL_RAHUL_PROCEDURES;
    Error:
    Connecting to the database INQDWD.
    ORA-00900: invalid SQL statement
    ORA-06512: at "ETLADMIN.CALL_RAHUL_PROCEDURES", line 17
    ORA-06512: at line 2
    exec RAHUL_HELLO_WORLD2('rahul');
    Process exited.
    Disconnecting from the database INQDWD.
    data in rahul_procedures table :
    Proc_name flag Id
    RAHUL_HELLO_WORLD     N     1
    RAHUL_HELLO_WORLD2     Y     2
    RAHUL_HELLO_WORLD     N     3
    RAHUL_HELLO_WORLD3     N     4
    please help.
    Regards
    Rahul

    Mac_Freak_Rahul wrote:
    Well I have to call 26 procedures one by one and the names of the procedures would be in a table'rahul_procedures' Which is 100% wrong.
    Data is stored in tables, program code is stored in procedures or view defintions.
    http://en.wikipedia.org/wiki/Data_%28computing%29
    >
    Data vs programs
    Typically, different files are used to store programs vs data. Executable files contain programs; all other files are data files.
    >
    So you have just violated the primary distinction between data and program code.
    I dont find anything strange in my question,Only because you do not appear to know what you are doing or the difference between data and program code.
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1943344500346351703
    >
    ugh, what an ugly "design". I can see your life will be full of performance issues, strange 'bugs', and other unpleasant side effects. I mean, it all looks "so cool", but it'll be a nightmare to maintain and enhance.
    but then you have the issue of binds, which will be intractable. You'd have to know the binds at compile time, but you have hidden all of your sql in a magic generic table - so you cannot possibly know your binds at compile time.
    I would suggest you discard all of this code (I am DEAD SERIOUS) and start over. This is a bad idea from the get go. Or at least do me a favor and do not use plsql (you make it look like a good database implementation, but it isn't)
    The objective here is to store SQL Statements in a Table(a sql repository) and just call the required SQL from the application using the sqlid using the sql_execute procedure. ...
    CHANGE YOUR OBJECTIVE.
    How about this for a good objective:
    the objective here is to store sql statement in a plsql routine (a sql repository, you call a procedure and we run sql) and just call the required sql form the applicatoin using the STORED PROCEDURE
    sorry, can I think of hacks to get you going? yes, application contexts come to mind - a fixed number of binds comes to mind. Am I going to work them out? No - it is the wrong way to approach a database application.

  • Calling plsql block in java

    Hi
    Needs some help, urgently.
    i have to call/execute a plsql block in java program.
    block is similar to this
    declare
    CURSOR l_csr IS
    select empname, empid, empdate from emp
    order by empid;
    l_empid NUMBER;
    l_empdate DATE;
    l_empname varchar2(30);
    o_dateProfileId NUMBER;
    o_dayofweekprofileid NUMBER;
    begin
    open l_csr;
    loop
    FETCH l_csr INTO l_empid , l_empname , l_empdate;
    EXIT WHEN l_csr%NOTFOUND;
    DETERMINEEMPPROFILE(l_empdate,o_dateProfileId,o_dayofweekprofileid,l_empid ,FALSE);
    IF(o_dateProfileId IS NOT NULL) THEN
    SELECT totaljobs INTO l_max1 FROM dateprofile WHERE dateprofileid = o_dateprofileid;               
    ELSE
    SELECT totaljobs INTO l_max1 FROM dayofweekprofile WHERE dayofweekprofileid = o_dayofweekprofileid;
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('SQLCODE = ' || SQLCODE);
    END;
    i need to call this in java program and take the results of l_max1.
    can someone provide an example of hot to do this or sample code
    appreciate any help

    I'm assuming this is for Oracle. Take a look at this article [url=http://www.enterprisedt.com/publications/oracle/result_set.html
    ]here for an example of how to use java to parse a result set from an Oracle procedure.

  • Why CBO don't use function-base index when I use like and bind variable

    Hello
    I have litle problem with function-base index and like with bind variable.
    When I use like with bind variable, the CBO don't use my function-base index.
    For example when I create table and index:
    ALTER SESSION SET NLS_SORT='BINARY_CI';
    ALTER SESSION SET NLS_COMP='LINGUISTIC';
    alter session set nls_language='ENGLISH';
    -- DROP TABLE TEST1;
    CREATE TABLE TEST1 (K1 VARCHAR2(32));
    create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI'));
    INSERT INTO TEST1
    SELECT OBJECT_NAME FROM ALL_OBJECTS;
    COMMIT;
    When I run:
    ALTER SESSION SET NLS_SORT='BINARY_CI';
    ALTER SESSION SET NLS_COMP='LINGUISTIC';
    SELECT * FROM TEST1 WHERE K1 = 'abcd';
    or
    SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%';
    CBO use index.
    PLAN_TABLE_OUTPUT
    SQL_ID 4vrmp7cshbvqy, child number 1
    SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%'
    Plan hash value: 1885706448
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    | 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 2 | 98 | 1 (0)| 00:00:01 |
    |* 2 | INDEX RANGE SCAN | TEST1_IDX | 2 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("TEST1"."SYS_NC00002$">=HEXTORAW('6162636400') AND
    "TEST1"."SYS_NC00002$"<HEXTORAW('6162636500') )
    but when I run
    SELECT * FROM TEST1 WHERE K1 LIKE :1;
    CBO don't use index
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 0
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 4122059633
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 89 (100)| |
    |* 1 | TABLE ACCESS FULL| TEST1 | 2 | 48 | 89 (3)| 00:00:02 |
    Predicate Information (identified by operation id):
    1 - filter("K1" LIKE :1)
    What should I change to force CBO to use index.
    I don't wont use index hint in query.
    My oracle version:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    OK. But why if I create normal index (create index test1_idx on test1(K1)) and return to default nls settings this same query use index.
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 0
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 598212486
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    |* 1 | INDEX RANGE SCAN| TEST1_IDX | 1 | 18 | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - access("K1" LIKE :1)
    filter("K1" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)
    when index is function-base (create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI')))
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 1
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 4122059633
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 89 (100)| |
    |* 1 | TABLE ACCESS FULL| TEST1 | 3 | 54 | 89 (3)| 00:00:02 |
    Predicate Information (identified by operation id):
    1 - filter("K1" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)
    when I create index with upper function "index test1_idx on test1(upper(K1))" the query use index
    SELECT * FROM TEST1 WHERE upper(K1) LIKE :1
    Plan hash value: 1885706448
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    | 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 4481 | 157K| 1 (0)| 00:00:01 |
    |* 2 | INDEX RANGE SCAN | TEST1_IDX | 806 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("TEST1"."SYS_NC00002$" LIKE :1)
    filter("TEST1"."SYS_NC00002$" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)

  • Am facing this error sqlcode :-6502 while running sql code in plsql block

    Am facing this error sqlcode :-6502 while running sql code in plsql block.
    am using query :
    SELECT SUBSTR('123456DE789KL|987654321|B',1,INSTR('123456DE789KL|987654321|B','|')-1) FROM DUAL;
    CAN any body tell me why.

    BD_Fayez wrote:
    I've tried the following, but don't get any error.As I mentioned, most likely variable is too short:
    SQL> declare
      2  strSub varchar2(2);
      3  begin
      4  SELECT SUBSTR('123456DE789KL|987654321|B',1,INSTR('123456DE789KL|987654321|B','|')-1) into strSub FROM DUAL;
      5  dbms_output.put_line(strSub);
      6  end;
      7  /
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 4
    SQL> SY.

  • Unknow number of binding variables in Dynamic SQL

    I have to use a dynamic sql and binding variables. The problem is the number of binding variable varies due to the form input.
    EX.
    if ( something is not null ) then
    query := query || ' and column = :column';
    end if;
    if ( something_else is not null ) then
    query := query || ' and another_column = :another_column';
    end if;
    When I use in my USING clause, I don't know which of the four combinations of column/another_column I could be
    open query;
    open query using A,B;
    open query using A;
    open query using B;
    How can I solve this problem?
    Thanks a lot!

    Always with NVL:
    query := query || ' AND column = NVL(:column,column ) AND another_column = NVL(:another_column,another_column)';Invoke:
    DECLARE
      a_null CHAR(1); -- set to NULL automatically at run time
    BEGIN
      --open query
      open query using (a_null,a_null)
      --open query using A,B
      open query using A,B;
      --open query using A
      open query using A,a_null;
      --open query using B
      open query using a_null ,B;
    END;
    /Edited by: jortri on 04-dic-2008 18:34

  • Unable to insert row in object table from plsql block

    I have table called test based on an object type. When I issue an insert statement from sqlplus, the row is inserted. The exact same sql statement in a plsql block gives the error below. Any ideas? (it is not a constraint problem).
    SQL> insert into test values( 3,2,1,1,'asp',1,'mach' );
    1 row created.
    SQL> begin
    2 insert into test values( 3,2,1,1,'asp',1,'mach' );
    3 end;
    4 /
    insert into test values( 3,2,1,1,'asp',1,'mach' );
    ERROR at line 2:
    ORA-06550: line 2, column 16:
    PL/SQL: ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-302: component 'DOCUMENT' must be declared
    ORA-06550: line 2, column 4:
    PL/SQL: SQL Statement ignored
    (ddl)
    CREATE OR REPLACE type document as object
    DOC_ID NUMBER (38),
    BATCH_ID NUMBER (38),
    STATE NUMBER (2),
    TRANSIENT NUMBER (2),
    ASP VARCHAR2 (20),
    USER_ID NUMBER (6),
    MACHINE VARCHAR2 (30),
    MEMBER PROCEDURE setState,
    MEMBER function getState RETURN NUMBER
    ) not final;
    create table test of document;

    Hi Adam
    You need to instantiate your object type in your insert statement(while doing through PL/SQL block), so try like this
    Insert into test values(document(1,2,'CO',55,'xyz','kkk','PENTIUM'));
    The reason you were successful through SQLPLUS was that, SQLPLUS automatically instantiate the values into object type.
    Qurashi

  • Using SOAP-JMS binding for business process

    Hi all,
    We are currently designing one business process which consume MQ messages. The MQ message body is SOAP XML. SOAP Headers carry business specific important data section, so we don't want to loose these headers at any cost. The message consumer is the Websphere process choreographer business process, reading message as a JMS message. When we develop the business process, we are planning to use SOAP-JMS binding. But problem with SOAP-JMS binding is: when the MDB reads the message off the message queue, it strips off all the SOAP headers and delivers only the SOAP body. Is there a way to make this behaviour change to keep the SOAP headers? You may suggest to use JMS bindings, but JMS binding will send the message body as WSIF message (as a serialized java object). I'm not sure of how easy it is to marshalling/unmarshalling of this serialised object. My main concern is around, how to identify the "type" of the message while marshalling. Would writing our own MDB solve the problem? Again MDB's sends messages as WSIF messages to the business process EJB's, which I guess I get stumble across the same marshal/unmarshall problem. Hope I made myself clear of what i'm going trying to do. Any advice is highly appreciated.
    Regards,
    Prasad

    Hello Markus,
    I just paste my answer form the other forum entry Re: Business process management strategy in SAP?
    in a nutshell BPM Netweaver is focussing on so called edge-processes (usually
    SOA-based and often workflow related). These edge-processes a thought to enhance exisitng core business processes and should provide the fast competitive edge versus competitors. Examples would be also xApps. For this Netweaver provides process modelling tools, where you can get exectuable code through the integration between CE and PI. The monitoring part for these processes is mainly targeting business end-users and business manager.
    Business Process Monitoring with Solution Manager focusses on core business processes which are realized with the "conventional", "old" SAP Architecture, e.g. Order-to-Cash or Procure-to-Pay. You get a combination of technical monitors (average response times of transactions, background job runtimes, monitors for IDOC or qRFC processing) and application related monitors (you get more than 200 pre-configured application monitors out-of-the-box like number of overdue customer orders or outbound deliveries or number of deliveries with goods issue posted but no invoice). The target group here is the support organization of the customer, from Basis-Support over application support on IT side to process owner on business department side.
    Overview presentations can be found under
    https://service.sap.com/bpm --> Media Library --> Customer Information -->
    "Business Process Monitoring - Part 1 & 2".
    Or look under https://www.sdn.sap.com/irj/sdn/nw-processmonitoring
    In the end BPM Netweaver and BPMon SolMan are complementary for different purposes and different target groups.
    Best Regards
    Volker

Maybe you are looking for

  • [SOLVED]ZSH and regular expressions

    Hi I am getting into regular expressions and i have noticed that with my .zshrc file i have some problem. In bash this expression works: \^\[^#] but not also in zsh. I have also noted that regular expression works fine with other zshrc configurations

  • How to remove obsolete parameters in oracle

    hi, can anyone tell me how to delete a obsolete parameter in oracle,wat are the steps to follow or is there any command Thanks renjy

  • Help/Query Optimization

    The below query runs in a second where the po_requisition_header _d in line 42 (5063 value) is hard coded. However, when it is joined to the outer query it takes minutes. I have tried using hints. maybe I'm not using the right hint? Could does someon

  • DTW de balances

    Hola!!! montando la nueva sociedad en 8.8 al subir por DTW me esta generando el siguiente error que no entiendo y me tiene barada porque no he podido continuar http://www.sendspace.com/file/nuj6yd, espero sus ayudas gracias!!!!

  • ICloud bookmarks don't sync on iPad mini

    I have an iPad mini 1st gen and have had it for over a year. Recently, I've noticed that my Safari bookmarks that I have updated on either my MBP mid-2010 Mavericks or my iPhone 5 are not being synced to my iPad. I am running the latest operating sys