SQL ARRAY IN 'WHERE IN'

Dear All
How could I declare a variable and then used in WHERE IN clause?
I would like to do something like
SELECT * FROM rooms WHERE number IN ('1001','1012','1015')
but with the room number array declared as variable so I could reuse it
I tried the following which is not working
DECLARE @RoomNumbers VARCHAR(MAX) = '1001,1012,1015';SELECT * FROM rooms WHERE number IN (@RoomNumbers)
If not using EXEC, is it possible to do it?  Thanks.

You can do it by creating a split function.  The are many examples of split functions, but one possibility is
CREATE FUNCTION dbo.Split (@DelimitedString nvarchar(max), @Delimiter nvarchar(max))
RETURNS table
AS
RETURN (
WITH Pieces (ID, start, stop) AS (
SELECT CAST(1 AS bigint), CAST(1 AS bigint), CAST(CHARINDEX(@Delimiter, @DelimitedString) AS bigint)
UNION ALL
SELECT ID + 1, CAST(stop + DATALENGTH(@Delimiter)/2 As bigint), CAST(CHARINDEX(@Delimiter, @DelimitedString, stop + DATALENGTH(@Delimiter)/2) AS bigint)
FROM Pieces
WHERE stop > 0
SELECT ID,
SUBSTRING(@DelimitedString, start, CASE WHEN stop > 0 THEN stop-start ELSE LEN(@DelimitedString) END) AS Element
FROM Pieces
GO
Then you can use that split function, for example
DECLARE @RoomNumbers VARCHAR(MAX) = '1001,1012,1015';
SELECT * FROM rooms WHERE number IN (Select Element From dbo.Split(@RoomNumbers, ','))
Tom
Very good, Thanks

Similar Messages

  • The ABAP/4 Open SQL array insert results in duplicate database records

    Hi,
    Iam getting following error :
    The ABAP/4 Open SQL array insert results in duplicate database records.
    Error in ABAP application program.
    The current ABAP program "SAPLV60U" had to be terminated because one of the
    statements could not be executed.
    This is probably due to an error in the ABAP program.
    " Information on where terminated
    The termination occurred in the ABAP program "SAPLV60U" in "VBUK_BEARBEITEN".
    The main program was "SAPMSSY4 ".
    The termination occurred in line 503 of the source code of the (Include)
    program "LV60UF0V"
    of the source code of program "LV60UF0V" (when calling the editor 5030).
    Processing was terminated because the exception "CX_SY_OPEN_SQL_DB" occurred in
    the
    procedure "VBUK_BEARBEITEN" "(FORM)" but was not handled locally, not declared
    in the
    RAISING clause of the procedure.
    The procedure is in the program "SAPLV60U ". Its source code starts in line 469
    of the (Include) program "LV60UF0V "."
    Please assist how to proceed further ..
    Many thanks
    Mujeeb.

    Sorry, THe correct note is 402221.
    Description from the note
    << Please do not post SAP notes - they are copyrighed material >>
    Edited by: Rob Burbank on Feb 22, 2009 3:46 PM

  • ABAP/4 Open SQL array insert results in duplicate databaserecordsfor pk13

    Hi Experts, when I am working with pk13n tranaction iam getting an error message stating that update was terminated by user. when i am checking with st22 it gives the following message. please give the solution , iam sending the code as well.
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught
    in
    procedure "SAVE_DATA" "(FORM)", nor was it propagated by a RAISING clause.
    Since the caller of the procedure could not have anticipated that the
    exception would occur, the current program is terminated.
    The reason for the exception is:
    If you use an ABAP/4 Open SQL array insert to insert a record in
    the database and that record already exists with the same key,
    this results in a termination.
    (With an ABAP/4 Open SQL single record insert in the same error
    situation, processing does not terminate, but SY-SUBRC is set to 4.) please find the below code please give the solution for this error message.
    1 *eject
    2 *----
    3 *   Verbuchen der Daten                                           *
    4 *----
    5 FORM SAVE_DATA.
    6
    7   DATA: lf_menge LIKE ekpo-menge VALUE 0,                   "717464
    8         lf_netwr LIKE ekpo-netwr VALUE 0.
    9
    10 * Einteilungen löschen --> Array Delete aus Tabelle DEKET
    11   DESCRIBE TABLE DEKET LINES SY-TFILL.
    12   IF SY-TFILL GT 0.
    13     DELETE EKET FROM TABLE DEKET.
    14     IF SY-SUBRC NE 0.
    15       MESSAGE A865.
    16     ENDIF.
    17     EKET_DELETE = EKET_DELETE + SY-DBCNT.
    18     REFRESH: DEKET.
    19     CLEAR  : DEKET.
    20   ENDIF.
    21
    22 * Einteilungen hinzufügen --> Array Insert aus Tabelle IEKET
    23   DESCRIBE TABLE IEKET LINES SY-TFILL.
    24   IF SY-TFILL GT 0.
    >>     INSERT EKET FROM TABLE IEKET.
    26     IF SY-SUBRC NE 0.
    27       MESSAGE A864.
    28     ENDIF.
    29     EKET_INSERT = EKET_INSERT + SY-DBCNT.
    30     REFRESH: IEKET.
    31     CLEAR  : IEKET.
    32   ENDIF.
    33
    34 * Check whether the qty in EKPO-MENGE is correct: note 717464
    35   SELECT SUM( menge ) FROM eket INTO lf_menge
    36                       WHERE ebeln = ekpo-ebeln
    37                       AND   ebelp = ekpo-ebelp.
    38   IF sy-subrc = 0 AND ekpo-menge <> lf_menge.
    39     IF ekpo-ktmng <> 0.
    40       refe1 = ekpo-zwert * lf_menge / ekpo-ktmng.
    41     ELSE.
    42       refe1 = ekpo-zwert * lf_menge / 1000.
    43     ENDIF.
    44     IF refe1 > maxwert.

    Hi,
    Well I don't know why you have duplicates, this is a functionnal issue. But you get the dump due the the message number 864 that triggers the abend... Changing the message type to 'E', 'S' or 'I' will prevent the dump but I guess this message has a good reason to be
    Kr,
    Manu.

  • Deadlock in Oracle.sql.ARRAY type

    Hi,
    We've come across the deadlock situation below when running multiple J2EE MDB instances that are trying to write to the DB:
    [deadlocked thread] [ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)':
    Thread '[ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)'' is waiting to acquire lock 'oracle.jdbc.driver.T4CConnection@90106ee' that is held by thread '[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)''
    Stack trace:
    oracle.sql.ARRAY.toBytes(ARRAY.java:673)
    oracle.jdbc.driver.OraclePreparedStatement.setArrayCritical(OraclePreparedStatement.java:5985)
    oracle.jdbc.driver.OraclePreparedStatement.setARRAYInternal(OraclePreparedStatement.java:5944)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8782)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8278)
    oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8868)
    oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:240)
    weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:287)
    org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:356)
    org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:216)
    org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:127)
    org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:298)
    org.springframework.jdbc.object.BatchSqlUpdate$1.setValues(BatchSqlUpdate.java:192)
    org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:892)
    org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1)
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614)
    org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:883)
    org.springframework.jdbc.object.BatchSqlUpdate.flush(BatchSqlUpdate.java:184)
    com.csfb.fao.rds.rfi.common.dao.storedprocs.SaveEarlyExceptionBatchStoredProc.execute(SaveEarlyExceptionBatchStoredProc.java:93)
    com.csfb.fao.rds.rfi.common.dao.EarlyExceptionDAOImpl.saveEarlyExceptionBatch(EarlyExceptionDAOImpl.java:34)
    com.csfb.fao.rds.rfi.application.rulesengine.RulesEngine.saveEarlyExceptions(RulesEngine.java:302)
    com.csfb.fao.rds.rfi.application.rulesengine.RulesEngine.executeRules(RulesEngine.java:209)
    com.csfb.fao.rds.rfi.application.rulesengine.RulesEngine.onMessage(RulesEngine.java:97)
    com.csfb.fao.rds.feeds.process.BaseWorkerMDB.onMessage(BaseWorkerMDB.java:518)
    weblogic.ejb.container.internal.MDListener.execute(MDListener.java:466)
    weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:371)
    weblogic.ejb.container.internal.MDListener.onMessage(MDListener.java:327)
    weblogic.jms.client.JMSSession.onMessage(JMSSession.java:4547)
    weblogic.jms.client.JMSSession.execute(JMSSession.java:4233)
    weblogic.jms.client.JMSSession.executeMessage(JMSSession.java:3709)
    weblogic.jms.client.JMSSession.access$000(JMSSession.java:114)
    weblogic.jms.client.JMSSession$UseForRunnable.run(JMSSession.java:5058)
    weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
    weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    [deadlocked thread] [ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)':
    Thread '[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'' is waiting to acquire lock 'oracle.jdbc.driver.T4CConnection@b48b568' that is held by thread '[ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)''
    Stack trace:
    oracle.sql.ARRAY.toBytes(ARRAY.java:673)
    oracle.jdbc.driver.OraclePreparedStatement.setArrayCritical(OraclePreparedStatement.java:5985)
    oracle.jdbc.driver.OraclePreparedStatement.setARRAYInternal(OraclePreparedStatement.java:5944)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8782)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8278)
    oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8868)
    oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:240)
    weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:287)
    org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:356)
    org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:216)
    org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:127)
    org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:298)
    org.springframework.jdbc.object.BatchSqlUpdate$1.setValues(BatchSqlUpdate.java:192)
    org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:892)
    org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1)
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614)
    org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:883)
    org.springframework.jdbc.object.BatchSqlUpdate.flush(BatchSqlUpdate.java:184)
    com.csfb.fao.rds.rfi.common.dao.storedprocs.SaveEarlyExceptionBatchStoredProc.execute(SaveEarlyExceptionBatchStoredProc.java:93)
    com.csfb.fao.rds.rfi.common.dao.EarlyExceptionDAOImpl.saveEarlyExceptionBatch(EarlyExceptionDAOImpl.java:34)
    com.csfb.fao.rds.rfi.application.rulesengine.RulesEngine.saveEarlyExceptions(RulesEngine.java:302)
    com.csfb.fao.rds.rfi.application.rulesengine.RulesEngine.executeRules(RulesEngine.java:209)
    com.csfb.fao.rds.rfi.application.rulesengine.RulesEngine.onMessage(RulesEngine.java:97)
    com.csfb.fao.rds.feeds.process.BaseWorkerMDB.onMessage(BaseWorkerMDB.java:518)
    weblogic.ejb.container.internal.MDListener.execute(MDListener.java:466)
    weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:371)
    weblogic.ejb.container.internal.MDListener.onMessage(MDListener.java:327)
    weblogic.jms.client.JMSSession.onMessage(JMSSession.java:4547)
    weblogic.jms.client.JMSSession.execute(JMSSession.java:4233)
    weblogic.jms.client.JMSSession.executeMessage(JMSSession.java:3709)
    weblogic.jms.client.JMSSession.access$000(JMSSession.java:114)
    weblogic.jms.client.JMSSession$UseForRunnable.run(JMSSession.java:5058)
    weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
    weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Looking at the ARRAY.toBytes() method:
    public byte[] toBytes()
    throws SQLException
    synchronized (getInternalConnection())
    return this.descriptor.toBytes(this, this.enableBuffering);
    ..., it synchronizes on the following method (getInternalConnection() -> getPhysicalConnection()):
    oracle.jdbc.internal.OracleConnection getPhysicalConnection()
    if (this.physicalConnection == null)
    try
    this.physicalConnection = ((oracle.jdbc.internal.OracleConnection)new OracleDriver().defaultConnection());
    catch (SQLException localSQLException)
    return this.physicalConnection;
    defaultConnection() does the following:
    public Connection defaultConnection()
    throws SQLException
    if ((defaultConn == null) || (defaultConn.isClosed()))
    synchronized (OracleDriver.class)
    if ((defaultConn == null) || (defaultConn.isClosed()))
    defaultConn = connect("jdbc:oracle:kprb:", new Properties());
    return defaultConn;
    So there's synchronizations on the connection instance and OracleDriver.class object... I can't see how this can deadlock. To get to the point of needing the lock on OracleDriver.class, the thread would already have the lock on the connection instance.... clearly I'm missing something.
    Thanks
    Edited by: 928154 on 17-Apr-2012 03:42

    Welcome to the forum. If you want help, at least try to think where to post a question and look for a forum that matches the topic. Lets examine what you have:
    - its Weblogic, so if you would ask a non-programming related question anywhere it would be in the Weblogic forum
    - HOWEVER, if you check the top of the stacktrace, you'll see that the problem stems from the JDBC driver, so a JDBC related forum would be a closer match
    For future reference, Weblogic specific questions should go here: https://forums.oracle.com/forums/category.jspa?categoryID=193
    and JDBC/OJDBC driver related questions should go here: Java Database Connectivity (JDBC)
    Final tip: use \ tags to post code so it is readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • PL/SQL array passed to SQL IN

    Hi,
    I have a PL/SQL array which type is defined like this:
    create or replace type type_id_array as table of number(6, 3);
    then i create a variable and initilaize:
    var_1 type_id_array;
    var_1 := .....
    then i have a select statement.
    select * from table t where t.id in(var_1)
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?
    Thanks

    user610868 wrote:
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?SQL supports set commands specifically for arrays (in addition to the using the TABLE() method mentioned). For example:
    SQL> create or replace type TNumbers is table of number;
      2  /
    Type created.
    SQL>
    SQL> declare
      2          numList TNumbers;
      3          cnt     integer;
      4  begin
      5          numList := new TNumbers(1,2,3,4,5,6,7);
      6          select
      7                  count(*) into cnt
      8          from    user_objects
      9          where   TNumbers(object_id) member of numList;
    10          DBMS_OUTPUT.put_line( 'cnt='||cnt );
    11  end;
    12  /
    cnt=0
    PL/SQL procedure successfully completed.Obviously there are performance considerations when using arrays/collections in SQL. So before choosing a method, evaluate the performance.

  • RE: (forte-users) SQL Array Insert

    Unfortunately that carries a tremendous overhead. Each request is a seperate
    message and forte generates alot of behind the scenes prepares for the sql.
    ---------------------- Forwarded by Amos G. Radford on 10/27/2000 02:34 PM
    "Amin, Kamran" <kamran.aminlendware.com> on 10/27/2000 02:33:07 PM
    To: Amos G. RadfordBankofAmerica
    cc:
    Class: Internal Use Only
    Subject: RE: (forte-users) SQL Array Insert
    User a for loop and call update for each row in the array.
    For Loop
    Update
    set
    1=test[1]
    end for
    ka
    -----Original Message-----
    From: Amos.G.Radfordbankofamerica.com
    [mailto:Amos.G.Radfordbankofamerica.com]
    Sent: Friday, October 27, 2000 12:07 PM
    To: forte-userslists.xpedior.com
    Subject: (forte-users) SQL Array Insert
    I have run into a strange problem that I never really run into
    before. If I want to save an array of items into a table in TOOL
    SQL, how can I do it if the column names in the table are different
    than the column names in the class. In the past we always had
    the luxury of the column names being the same.
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com

    Madhu,
    Do the following:
    1. create prepare statement
    e.g
    stmHnd : DBStatementHandle;
    inputData : DBDataset = new;
    stmType : integer;
    stmHnd = DBSesObj.prepare('insert into
    table_name myCOl1, myCol2, myCol3
    values(:myCol1Value, :myCol2Value, :myCol3Value)',
    inputData,stmType);
    2. Populate the input DBDataset.
    e.g
    // assign the maximum value
    inputData = myArrObj.items;
    // assign the values
    for i in 1 to myArrObj.items do
    inputdata.currentRow = i;
    inputdata.setvalue(':myCol1Value',
    myArrObj.attr1);
    inputdata.setvalue(':myCol2Value',
    myArrObj[i].attr2);
    inputdata.setvalue(':myCol3Value',
    myArrObj[i].attr3);
    end for;
    3. execute the statement:
    e.g .
    DBSesObj.execute(stmHnd, inputData);
    4. release the handle
    DBSesObj.RemoveStatement(stmHnd);
    Hope this helps,
    Babu
    --- "Epari, Madhusudhan" <meparioxhp.com> wrote:
    Babu,
    I'm not clear on how dynamic sql statement would
    access the database only
    one time for inserting an array of records in to the
    table. Could you tell
    how's it done?
    thanks in advance,
    Madhu
    -----Original Message-----
    From: Babu Raj [mailto:ibcsmartboyyahoo.com]
    Sent: Friday, October 27, 2000 8:02 PM
    To: Amos.G.Radfordbankofamerica.com;
    forte-userslists.xpedior.com
    Subject: RE: (forte-users) SQL Array Insert
    Amos,
    Why don't you use, Dyanmic SQL statement,
    where
    you need to prepare only one SQL Statement, and
    populate input place holder, which is much simpler
    and
    you need to access the database only one time(which
    is
    efficient operation). This is useful, especially,
    when
    you want to update. But for your inforamtion, Forte
    internally inserts, one by one row, even if u call
    Static SQl statement, with array of record. Os its
    advisable to use Dyanmic SQL statement.
    Hope this helps,
    Babu
    --- Amos.G.Radfordbankofamerica.com wrote:
    Unfortunately that carries a tremendous overhead.
    Each request is a seperate
    message and forte generates alot of behind the
    scenes prepares for the sql.
    ---------------------- Forwarded by Amos G.Radford
    on 10/27/2000 02:34 PM
    "Amin, Kamran" <kamran.aminlendware.com> on
    10/27/2000 02:33:07 PM
    To: Amos G. RadfordBankofAmerica
    cc:
    Class: Internal Use Only
    Subject: RE: (forte-users) SQL Array Insert
    User a for loop and call update for each row inthe
    array.
    For Loop
    Update
    set
    1=test[1]
    end for
    ka
    -----Original Message-----
    From: Amos.G.Radfordbankofamerica.com
    [mailto:Amos.G.Radfordbankofamerica.com]
    Sent: Friday, October 27, 2000 12:07 PM
    To: forte-userslists.xpedior.com
    Subject: (forte-users) SQL Array Insert
    I have run into a strange problem that I never
    really run into
    before. If I want to save an array of items intoa
    table in TOOL
    SQL, how can I do it if the column names in the
    table are different
    than the column names in the class. In the pastwe
    always had
    the luxury of the column names being the same.
    For the archives, go to:
    http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To
    unsubscribe, send in a new
    email the word: 'Unsubscribe' to:
    forte-users-requestlists.xpedior.com
    For the archives, go to:
    http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To
    unsubscribe, send in a new
    email the word: 'Unsubscribe' to:
    forte-users-requestlists.xpedior.com
    For the archives, go to:
    http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To
    unsubscribe, send in a new
    email the word: 'Unsubscribe' to:forte-users-requestlists.xpedior.com

  • How do I Pass a parameter to a SQL Component Task where the source SQL statement is also a variable

    Hi,
    I have been tasked with making a complex package more generic.
    To achieve this I need to pass a parameter to a SQL Component Task where the source SQL statement is also a variable.
    So to help articulate my question further I have create a package and database as follows; -
    USE [KWPlay]
    GO
    /****** Object: Table [dbo].[tblTest] Script Date: 05/14/2014 17:08:02 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[tblTest](
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [Description] [nvarchar](50) NULL,
    CONSTRAINT [PK_tblTest] PRIMARY KEY CLUSTERED
    [ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    I populated this table with a single record.
    I unit tested the SQL within SSMS as follows;
    SELECT * FROM dbo.tblTest
    Result; -
    ID           
    Description
    1             
    Happy
    DECLARE @myParam NVARCHAR(100)
    SET @myParam = 'Sad'
    UPDATE dbo.tblTest SET [Description] = @myParam FROM dbo.tblTest WHERE ID = 1
    SELECT * FROM dbo.tblTest
    Result; -
    ID   
    Description
    1    
    Sad
    Within the package I created two variables as follows; -
    Name: strSQL
    Scope: Package
    Data Type: String
    Value: UPDATE dbo.tblTest SET [Description] = @myParam FROM dbo.tblTest WHERE ID = 1
    Name: strStatus
    Scope: Package
    Data Type: String
    Value: Happy
    I then created a single ‘Execute SQL Task’ component within the control flow as follows; -
    However when I run the above package I get the following error; -
    SSIS package "Package.dtsx" starting.
    Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "UPDATE dbo.tblTest SET [Description] = @myParam FR..." failed with the following error:
    "Parameter name is unrecognized.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Task failed: Execute SQL Task
    Warning: 0x80019002 at Package: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. 
    The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the
    errors.
    SSIS package "Package.dtsx" finished: Failure.
    I also tried; - 
    Name: strSQL
    Scope: Package
    Data Type: String
    Value: UPDATE dbo.tblTest SET [Description] = ? FROM dbo.tblTest WHERE ID = 1
    However I received the error; - 
    SSIS package "Package.dtsx" starting.
    Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "UPDATE dbo.tblTest SET [Description] = ? FROM dbo...." failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with
    the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Task failed: Execute SQL Task
    Warning: 0x80019002 at Package: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches
    the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
    SSIS package "Package.dtsx" finished: Failure.
    Kind Regards,
    Kieran.
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Tried; - 
    Name: strSQL
    Scope: Package
    Data Type: String
    Value: UPDATE dbo.tblTest SET [Description] = ? FROM dbo.tblTest WHERE ID = 1
    and; - 
    Result; - 
    SSIS package "Package.dtsx" starting.
    SSIS package "Package.dtsx" finished: Success.
    Therefore the answer was to put the parameter number rather than the parameter name under the parameter mapping tab-> parameter name column. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

  • Problem Encountering in oracle.sql.ARRAY type

    Hi,
    i am using one stored procedure to get a set of records.
    i am getting it by mapping those things with java.sql.Array. And after that i am getting the values as ResultSet from that Array. The same thing is working fine in Windows platform. If i posted those thing into Unix - AIX, i am facing an ArrayIndexOutofBoundsException while getting ResultSet from oracle.sql.ARRAY class. I checked out ARRAY instance.it is not null. Both Application and Database are same except O.S.
    Can Anybody help me. I need it imm.
    Thanks in Advance
    Regards
    Eswaramoorthy.G

    Hi
    Did you ever figure out what the problem was with this? We have a client that is experiencing the same problem on AIX but we cannot reproduce using their database running under NT nor Sun. Any information would be appreciated. You can respond directly to [email protected]
    Thanks in adavance
    Rick DeMilia
    Sungard DataSystems

  • Can a recursive sql have a where clause

    can the following sql have a where clause and I dont want to hard code the id is is that possible...
    select DISPLAY_NAME, ID, PARENT_ID, display_in_parent_folder, sub_folder_sequence
    from wwsbr_all_folders start with id = 8888
    connect by prior id= parent_

    actually g is another alias I created sorry I missed it... if I do this as a regular sub query I get three records but when I implement it as a recursive query it does not retutn any thing. Below is my regular query followed by the recursive query which I am using to organize the result but get no results:
    REGULAR Query that retrieves records with parent_id = from the list of parent ids
    select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
    from WWSBR_ALL_FOLDERS f, WWSBR_ALL_FOLDERS g
         where g.parent_id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
    where
         e.caid = 103 AND
    e.parent_id <> 0 AND
    e.type_id = 1 AND
    e.display_in_parent_folder <> 0 AND
         e.id = f.parent_id)
    order by f.id, f.sub_folder_sequence;
    Recursive query that results nothing:
    select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
    from WWSBR_ALL_FOLDERS g, WWSBR_ALL_FOLDERS f start with f.id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
    where
         e.caid = 103 AND
    e.parent_id <> 0 AND
    e.type_id = 1 AND
    e.display_in_parent_folder <> 0 AND
         e.id = f.parent_id)
         connect by prior f.id= g.parent_id
    order by f.id, f.sub_folder_sequence;

  • The ABAP/4 Open SQL array insert results in duplicate Record in database

    Hi All,
    I am trying to transfer 4 plants from R/3 to APO. The IM contains only these 4 plants. However a queue gets generated in APO saying 'The ABAP/4 Open SQL array insert results in duplicate record in database'. I checked for table /SAPAPO/LOC, /SAPAPO/LOCMAP & /SAPAPO/LOCT for duplicate entry but the entry is not found.
    Can anybody guide me how to resolve this issue?
    Thanks in advance
    Sandeep Patil

    Hi Sandeep,
              Now try to delete ur location before activating the IM again.
    Use the program /SAPAPO/DELETE_LOCATIONS to delete locations.
    Note :
    1. Set the deletion flag (in /SAPAPO/LOC : Location -> Deletion Flag)
    2. Remove all the dependencies (like transportation lane, Model ........ )
    Check now and let me know.
    Regards,
    Siva.
    null

  • Conversion of java Array to oracle SQL Array while calling Stored Procedure

    How java Array can be converted to oracle SQL array while calling Stored procedure with callable statement.
    i.e java Array ---> Sql Array in Oracle while setting the datatypes to callable statement arguments.

    Look at:
    http://forum.java.sun.com/thread.jsp?forum=48&thread=376735&tstart=0&trange=15
    Paul

  • How to create oracle.sql.array

    I need to create an oracle.sql.array to pass in my custom objects array to the database. I know you can create it using the ArrayDescriptor class but the problem with that is the connection object is need.
    I am using the writeSql() method of the SQLData interface. I therefore dont have the connection object. Any ideas?

    haha
    you misunderstand. i have in my code:
    <code>
         // update the organisation
         public boolean setOrganisation(Organisation pOrg) {
              Organisation org = pOrg;
              OracleCallableStatement callStat = null;
              Connection conn = null;
              boolean OK = false;
              try {
                   conn = getConnection(getUserName());
                   pOrg.setConnection(conn);
                   callStat = (OracleCallableStatement) conn.prepareCall("{call p_cmt.update_organisation(?)}");
                   callStat.setObject(1, org);
                   callStat.execute();
                   OK = true;
              } catch (Exception e) {
                   logger.severe("error writing organisation with id " + org.getId() + ". " + e);
              } finally {
                   cleanUpConnections(conn, callStat);
              return OK;
    </code>
    This writes the object organisation to the database. Now in the class organisation i have the following method which is called automatically when writing the organisation object to the database:
    <code>
         public void writeSQL(SQLOutput p_stream) throws SQLException {
              p_stream.writeInt(id);
              p_stream.writeObject(country);
         if (finIndexArr == null)
              finIndexArr = new ListElement[0];
         ArrayDescriptor af = ArrayDescriptor.createDescriptor(
         ObjectMapper.elementList, conn);
         ARRAY arr = new ARRAY(af, conn, finIndexArr);          
              p_stream.writeArray(arr);
    </code>
    The problem is the last bit. To put the finIndexArr into an array i need the connection object. So i have to pass into the organisation object the connection object which seems unneccessary and pointless to me. I was just looking at an alternative way of creating the array without the need of the connection object. Since the setOrganisation() above has the connection to the database i dont see why i need to specify it in the array as well

  • Problem passing oracle.sql.ARRAY to Oracle

    I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
    Here is my code:
    PreparedStatement stmt = null;
    String strArray[] = { "1,2,3,4,5" };
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    //encounter Exception on the line below.
    ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
    String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
    stmt = dbConnection.prepareStatement(queryStr);
    stmt.setArray( 1, array_to_pass );
    stmt.execute();
    I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
    MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
    Really frustrated searching through the forums for the whole day,
    Thanks,

    Try this if you are at weblogic 8.1:
    Connection con = getConnectionFromDataSource();
    Connection vendorConnection = ((WLConnection)con).getVendorConnection();
    // use direct oracle connection.
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    vendorConnection.close();
    Beware that you should be very careful as you are going to use a direct vendor
    connection.
    The better aproach is to pass the string array as a delimited string to your storad
    procedure and parse it in the SP - then you don't have to mess up with vendor-specific
    handling.
    Hope this helps.
    Regards,
    Slava Imeshev
    "Daddy Daddy" <[email protected]> wrote in message news:24349835.1097143668312.JavaMail.root@jserv5...
    I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
    Here is my code:
    PreparedStatement stmt = null;
    String strArray[] = { "1,2,3,4,5" };
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    //encounter Exception on the line below.
    ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
    String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
    stmt = dbConnection.prepareStatement(queryStr);
    stmt.setArray( 1, array_to_pass );
    stmt.execute();
    I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
    MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
    Really frustrated searching through the forums for the whole day,
    Thanks,

  • Bind PL/SQL array to PHP array

    Hi all!
    I try to bind a PL/SQL array (nested tables, index by integer) returned by a PL/SQL-function to an PHP array.
    Here is the code:
    create or replace package MyPackage as
    TYPE my_type IS TABLE OF VARCHAR2(1024);
    FUNCTION MyFunction RETURN my_type;
    end MyPackage;
    create or replace PACKAGE BODY MyPackage is
    FUNCTION MyFunction RETURN my_type IS
    t_docs my_type;
    begin
    t_docs := my_type('val0','val1','val2');
    return t_docs;
    end MyFunction;
    end MyPackage;
    In the PHP-code ist looks like this
    $query = "begin :vals := MyPackage.MyFunction; end;";
    $stmt = oci_parse ($conn, $query);
    oci_bind_array_by_name($stmt, ":vals", $vals_array, 5, 512, SQLT_CHR);
    oci_execute ($stmt);
    Output:
    PLS-00382: expression is of wrong type. Error in Line....
    This error point to
    begin :vals := MyPackage.MyFunction; end;
    ^^^
    Questions:
    Is it generally possible to bind a pl/sql array to a php array? Or only the other was around?
    Could you please post a snipet of code how to do it the right way :-)
    Thanks a lot for your help! Christian

    As you noted, you can't return a PL/SQL array and map it to a PHP array when it is a record type. Likewise, you can't map an object type to a PHP array. You can return a reference cursor through PL/SQL, and then fetch the function result with oci_fetch_assoc($rc).
    Alternatively, you can return an object type collection or a pipelined table function result into PHP. It's a bit long but you'll find examples on my blog. Start here, and there's a link to a full discussion of pipelined table functions:
    http://blog.mclaughlinsoftware.com/2009/03/19/beats-a-reference-cursor/
    This is an object table example, which you may prefer over pipelined table functions:
    http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/
    Hope this helps.

  • Java.sql.SQLException: Internal Error while using oracle.sql.ARRAY.getArray

    Hello All,
    Here is the issue description. Our application uses Oracle Object Types and LIST. We deployed our application on QA environment which has Oracle 10g. Application runs fine...no issues. Now we moved to UAT. UAT environment is same as QA environment and DBA have created replica of QA database.
    Now WAR file which works fine with QA database , somehow doesnt work with UAT database. Application throws following exception when code tries to call getArray() on java.sql.Array.
    We tried to point UAT weblogic to QA database and it worked fine.....but when we point UAT weblogic to UAT database , we get following exception. So we know that this is a database issue.
    DBA claims that QA env database and UAT env database are same.
    Can anybody please tell me what wrong here? What setting is not done on UAT database which is done on QA?
    java.sql.SQLException: Internal Error at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227) at oracle.jdbc.oracore.OracleTypeCOLLECTION.initCollElemTypeName(OracleTypeCOLLECTION.java:975) at oracle.jdbc.oracore.OracleTypeCOLLECTION.getAttributeType(OracleTypeCOLLECTION.java:1005) at oracle.jdbc.oracore.OracleNamedType.getFullName(OracleNamedType.java:96) at oracle.jdbc.oracore.OracleTypeADT.createStructDescriptor(OracleTypeADT.java:1958) at oracle.jdbc.oracore.OracleTypeADT.unpickle81(OracleTypeADT.java:1432) at oracle.jdbc.oracore.OracleTypeUPT.unpickle81UPT(OracleTypeUPT.java:426) at oracle.jdbc.oracore.OracleTypeUPT.unpickle81rec(OracleTypeUPT.java:383) at oracle.jdbc.oracore.OracleTypeCOLLECTION.unpickle81_imgBody_elems(OracleTypeCOLLECTION.java:928) at oracle.jdbc.oracore.OracleTypeCOLLECTION.unpickle81_imgBody(OracleTypeCOLLECTION.java:872) at oracle.jdbc.oracore.OracleTypeCOLLECTION.unpickle81(OracleTypeCOLLECTION.java:692) at oracle.jdbc.oracore.OracleTypeCOLLECTION._unlinearize(OracleTypeCOLLECTION.java:217) at oracle.jdbc.oracore.OracleTypeCOLLECTION.unlinearize(OracleTypeCOLLECTION.java:189) at oracle.sql.ArrayDescriptor.toJavaArray(ArrayDescriptor.java:663) at oracle.sql.ARRAY.getArray(ARRAY.java:282) at weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY.getArray(Unknown Source)
    Please help.

    425260 wrote:
    This can happen if you use the oracle.sql.ARRAY class with WebLogic.
    WebLogic wraps oracle.sql.ARRAY with its own class (i.e. weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY). The easiest solution is to replace oracle.sql.ARRAY with the JDBC standard java.sql.Array.
    <PRE class=jive-pre><CODE class="jive-code jive-java">Object[] items = (Object[])array.getArray();
    <FONT color=navy><B>if</B></FONT> (items.length &gt; 0) <FONT color=navy>{</FONT>
    <FONT color=navy><B>for</B></FONT> (<FONT color=navy><B>int</B></FONT> i = 0; i &lt; items.length; i++) <FONT color=navy>{</FONT>
    Object arrayItem = items;
    <FONT color=navy>}</FONT>
    <FONT color=navy>}</FONT>
    </CODE></PRE>
    The <B>array</B> object is a java.sql.Array. Here no unwrapping of the WebLogic wrapper is needed.
    If you absolutely need the oracle.sql.ARRAY class than you must use an <B>unwrap</B> API on the WebLogic wrapper class.
    <PRE class=jive-pre><CODE class="jive-code jive-java"><FONT color=navy><B>if</B></FONT> (object <FONT color=navy><B>instanceof</B></FONT> weblogic.jdbc.wrapper.Array)
    array = (ARRAY) ( ((weblogic.jdbc.wrapper.Array)object).unwrap(Class.forName(<FONT color=red>"oracle.sql.ARRAY"</FONT>)) );
    <FONT color=navy><B>else</B></FONT>
    array = (ARRAY) object;
    </CODE></PRE>
    Here, <B>array</B> is an oracle.sql.ARRAY. Try to see if this <A class=bodylinkwhite href="http://www.software-to-convert.com/3gp-conversion-software/3gp-to-myspace-video-software.html"><FONT face=tahoma,verdana,sans-serif color=#000 size=1>helps</FONT></A>. Good luck.
    Thanks for your explanation! It's very valuable, It is exactly what I need, I understand this part.

Maybe you are looking for