Passing table as (IN) parameter of an Oracle StoredProcedure

Hello,
I want to call an oracle 8.1.7 stored procedure define as:
CREATE TYPE Commande as object(Name varchar2(64), Type varchar2(2))
CREATE TYPE CommandeList as table of CommandeRapport
PROCEDURE Enregistrer (pListe IN CommandeList)
I can't use oracle.jdbc.driver.OracleCallableStatement
because I'm using the JDBC pooling of Weblogic (JDBC dataSource that gives me an java.sql.CallableStatement)
CallableStatement cs =
connection.prepareCall("{call Enregistrer(?)}");
what type of cs.set????(1, ????) do I have to use, while I cannot instanciate an "java.qsl.Array" object ?

I'm not using Weblogic JDBC driver but the Oracle thin driver for 8.1.7.
I want to use Weblogic JDBC pooling mecanism that gives me "weblogic.jdbc20.rmi.SerialConnection" (not OracleConnection)
My question is not about driver but "how to pass java array as a SQL ARRAY parameter to a Callable/PreparedStatement, using JDBC 2.0 standard API ?". Oracle specialized JDBC classes allow me to create "oracle.jdbc.ARRAY" objects. I used it for a test and it works fine, but I need JDBC pooling ...
Please help ... My boss is getting nervous !

Similar Messages

  • Pass table name as parameter in prepared Statement

    Can I pass table name as parameter in prepared Statement
    for example
    select * from ? where name =?
    when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
    I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
    Thanks
    Haroon Idrees.

    haroonob wrote:
    I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
    Well, I would say (ugly as it is) String concatenation, or stored procedures.

  • Passing TABLE NAME as parameter is possible or not?

    I want develop a small/simple report like this
    TABLE NAME :
    WHERE :
    ORDER BY :
    QUERY ROWS
    In the above model i want to pass all the three (TABLE NAME,WHERE and ORDER BY) as a parameter.
    My doubt, is that possible to pass TABLE NAME as a parameter? If so!
    When i enter any TABLE NAME it has to fetch me out the records of that table (Based on WHERE condition and ORDER BY).
    Is that possible to do?
    Need some help!
    Edited by: Muthukumar Seshadri on Aug 10, 2012 6:19 PM

    Yes, it is possible with lexical parameters. Look in the help for examples:
    SELECT Clause
    SELECT &P_ENAME NAME, &P_EMPNO ENO, &P_JOB ROLE  FROM EMP
    P_ENAME, P_EMPNO, and P_JOB can be used to change the columns selected at runtime.  For example, you could enter DEPTNO as the value for P_EMPNO on the Runtime Parameter Form. 
    Note that in this case, you should use aliases for your columns.  Otherwise, if you change the columns selected at runtime, the column names in the SELECT list will not match the Report Builder columns and the report will not run.
    FROM Clause
    SELECT ORDID, TOTAL FROM &ATABLE
    ATABLE can be used to change the table from which columns are selected at runtime.  For example, you could enter ORD for ATABLE at runtime. 
    If you dynamically change the table name in this way, you may also want to use lexical references for the SELECT clause (look at the previous example) in case the column names differ between tables.
    WHERE Clause
    SELECT ORDID, TOTAL FROM ORD WHERE &CUST
    ORDER BY Clause
    SELECT ORDID, SHIPDATE, ORDERDATE, TOTAL  FROM ORD ORDER BY &SORT You have to be really careful with this approach. Dynamic SQL may cause serious performance problems.
    Edited by: InoL on Aug 10, 2012 10:06 AM

  • Dynamic SQL : passing table name as parameter

    Hi
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
    DECLARE lookupTableRow CURSOR FOR
      SELECT TableName FROM SYS_LookUpTable
      OPEN lookupTableRow
      FETCH NEXT FROM lookupTableRow INTO @tableName
      WHILE @@FETCH_STATUS=0
      BEGIN
      SET @sql='SELECT * FROM '+@tableName
    EXECUTE sp_executesql @sql
      IF @counter=0
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
      END
      ELSE
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
      END
      SET @counter=@counter+1
      FETCH NEXT FROM lookupTableRow INTO @tableName
      END
      CLOSE lookupTableRow
      DEALLOCATE lookupTableRow
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
    So i cant do this too with ORACLE dynamic sql .
    Please advice for any solution
    * how can i use dynamic sql with table name as parameter ?
    * how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
    Thanks for the advice

    Hi,
    b003cf5e-e55d-4ff1-bdd2-f088a662d9f7 wrote:
    Hi
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
    DECLARE lookupTableRow CURSOR FOR
      SELECT TableName FROM SYS_LookUpTable
      OPEN lookupTableRow
      FETCH NEXT FROM lookupTableRow INTO @tableName
      WHILE @@FETCH_STATUS=0
      BEGIN
      SET @sql='SELECT * FROM '+@tableName
    EXECUTE sp_executesql @sql
      IF @counter=0
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
      END
      ELSE
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
      END
      SET @counter=@counter+1
      FETCH NEXT FROM lookupTableRow INTO @tableName
      END
      CLOSE lookupTableRow
      DEALLOCATE lookupTableRow
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
    So i cant do this too with ORACLE dynamic sql .
    Please advice for any solution
    * how can i use dynamic sql with table name as parameter ?
    * how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
    Thanks for the advice
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    I doesn't help when you use one term to mean another thing.
    SQL is a language used in both Oracle and other products, such as Microsoft's SQL Server. I don't know much about SQL Server, but Oracle (at least) doesn't support stored procedures in SQL itself; they have to be coded in some other language, such as PL/SQL.  
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    If the table name is a parameter (or only known at run-time for any reason), that's exactly the kind of situation where you MUST use dynamic SQL.
    The number of columns that a query produces (and their datatypes) is fixed when you compile a query, whether that query is dynamic or not.  If you have multiple queries, that produce result sets with different numbers of columns, then you can't combine them into a single query.  The best you can do with one query is to add NULL columns to some of the queries so they all produce the same number of columns.
    If you're just displaying the results, there might not be any reason to combine separate result sets.  Just display one result set after another.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Help passing table name as parameter to a procedure

    Hello,
    i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
    CREATE OR REPLACE
    PROCEDURE excur(
        p_tbl user_tables.table_name%type )
    AS
      type rc is ref cursor;
      c rc;
      res BOOLEAN;
    BEGIN
      open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
      close c;
    END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.

    vishm8 wrote:
    Hello,
    i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
    CREATE OR REPLACE
    PROCEDURE excur(
    p_tbl user_tables.table_name%type )
    AS
    type rc is ref cursor;
    c rc;
    res BOOLEAN;
    BEGIN
    open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
    close c;
    END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.Generally speaking, Dynamic code is a bad idea for a staggering number of reasons.
    That aside, what do you want to return? You're selecting a column and applying an aggregate function (count) but you're not grouping, that doesn't usually work out too well.
    TUBBY_TUBBZ?select owner, count(*) from all_objects;
    select owner, count(*) from all_objects
    ERROR at line 1:
    ORA-00937: not a single-group group functionWhy do you perceive the need to be able to take in ANY table name, can't you design an application where table names are known at compile time and not run time?

  • Passing Table name as parameter to proc.

    Hi,
    I need to know how to pass a table name to a oracle procedure.
    In that procedure I will put that table name in a variable and then I will make operations on that table like DELETE, UPDATE and INSERT.
    Kinldy give me the solution for the above problem as soon as possible..
    Thanks & regards,
    Kiran

    You shouldn't do it, but if you do, you can use something like this:
    Anton
    create or replace type my_parm as object
      ( name varchar2(30)
      , val  anydata
    create or replace type my_parms as table of my_parm
    create table t1( c1 number, c2 varchar2(10), c3 date )
    create or replace procedure doital( p_action in varchar2, p_tab in varchar2, parms in my_parms )
    is
      p_stmt1 varchar2(32000);
      p_stmt2 varchar2(32000);
      ind pls_integer;
      curs integer;
      dummy integer;
      t_a anytype;
      t_v varchar2(32000);
      t_n number;
      t_d date;
    begin
      curs := dbms_sql.open_cursor;
      if upper( p_action ) = 'I'
      then
        ind := parms.first;
        loop
          exit when ind is null;
          p_stmt1 := p_stmt1 || ', ' || parms( ind ).name;
          p_stmt2 := p_stmt2 || ', :b' || to_char( ind );
          ind := parms.next( ind );
        end loop;
        p_stmt1 := 'insert into ' || p_tab || ' (' || substr( p_stmt1, 2 ) || ' ) values (' || substr( p_stmt2, 2 ) || ' )';
        dbms_sql.parse( curs, p_stmt1, dbms_sql.native );
        ind := parms.first;
        loop
          exit when ind is null;
          case parms( ind ).val.GetType( t_a )
            when dbms_types.typecode_varchar2
            then
              dummy := parms( ind ).val.GetVarchar2( t_v );
              dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_v );
            when dbms_types.typecode_number
            then
              dummy := parms( ind ).val.GetNumber( t_n );
              dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_n );
            when dbms_types.typecode_date
            then
              dummy := parms( ind ).val.GetDate( t_d );
              dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_d );
          end case;
          ind := parms.next( ind );
        end loop;
      end if;
      dummy := dbms_sql.execute( curs );
      dbms_sql.close_cursor( curs );
    end;
    begin
      doital( 'I', 't1', my_parms( my_parm( 'c2', anydata.ConvertVarchar2( 'testje' ) )
                                 , my_parm( 'c1', anydata.ConvertNumber( 3 ) )
                                 , my_parm( 'c3', anydata.ConvertDate( sysdate ) )
      doital( 'I', 't1', my_parms( my_parm( 'c1', anydata.ConvertNumber( 77 ) )
                                 , my_parm( 'c2', anydata.ConvertVarchar2( 'goedzo' ) )
                                 , my_parm( 'c3', anydata.ConvertDate( sysdate - 5 ) )
    end;
    /

  • How to pass Table name as parameter

    For example, you have several tables (TableA, TableB, TableC...TableN) that have the same structure.
    Ex.
    CREATE TABLE TableA(
    id VARCHAR(5),
    name VARCHAR(20)
    CREATE TABLE TableB(
    id VARCHAR(5),
    name VARCHAR(20)
    And you want to create a stored procedure in Oracle that can be used for all of the tables (TableA, TableB, ...)
    Ex. SELECT * FROM <tablename>
    WHERE ID > 1;
    How do you write the prepareCall and Callable Statement for that?
    Thanks in advance.

    You can't, not directly.
    You have two choices:
    -Write the SQL in java, then you can use string concatenation.
    -Use 'dynamic sql' in Oracle. There is a standard package that will take dynamic sql and run it.

  • Is it possible to pass table name as parameter to function calls?

    Let's say I would like to retrieve data from table BSAD, BSID, BSIS, BSAS with the exact same WHERE conditions.
    I.E.
          SELECT SINGLE * FROM bsis
               WHERE bukrs = zbukrs
                 AND belnr = zbelnr
                 AND gjahr = zgjahr
                 AND buzei = bseg-buzei.
          SELECT SINGLE * FROM bsas
               WHERE bukrs = zbukrs
                 AND belnr = zbelnr
                 AND gjahr = zgjahr
                 AND buzei = bseg-buzei.
    Is there a way that I could put them into a function and do something like?
    perform select_table_bsas using 'bsas'.
    perform select_table_bsis using 'bsis'.
    and I should get SELECT * FROM passed from the function calls.
    Thanks.

    Hello,
    You can try something like this
    DATA : LV_DBTAB1 LIKE DD02L-TABNAME.
    DATA : DREF TYPE REF TO DATA.
    FIELD-SYMBOLS: <ITAB> TYPE ANY TABLE. " used to store dynamic tables
    LV_DBTAB1 = 'MARA'. " in caps
      CREATE DATA DREF TYPE STANDARD TABLE OF (LV_DBTAB1)
                                WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN DREF->* TO <ITAB> .
    * chooses only english values
      SELECT * FROM (LV_DBTAB1) INTO TABLE <ITAB> WHERE SPRAS = 'E'.
    here, even the internal table is dynamic, but that can be static if you know the structure for sure

  • Pass table name as parameter PLS-00357

    create or replace
    PROCEDURE universal_p (
    tab IN VARCHAR2,
    col IN VARCHAR2,
    whr IN VARCHAR2 := NULL)
    IS
    TYPE cv_type IS REF CURSOR;
    cv cv_type;
    val VARCHAR2(32767);
    BEGIN
    OPEN cv FOR
    'SELECT ' || col ||
    ' FROM ' || tab ||
    ' WHERE ' || NVL (whr, '1 = 1');
    LOOP
    FETCH cv INTO val;
    EXIT WHEN cv%NOTFOUND;
    IF cv%ROWCOUNT = 1
    THEN
    DBMS_OUTPUT.PUT_LINE (RPAD ('-', 60, '-'));
    DBMS_OUTPUT.PUT_LINE (
    'Contents of ' ||
    UPPER (tab) || '.' || UPPER (col));
    DBMS_OUTPUT.PUT_LINE (RPAD ('-', 60, '-'));
    END IF;
    DBMS_OUTPUT.PUT_LINE (val);
    END LOOP;
    CLOSE cv;
    END;
    WHEN I CALL THIS PROCEDURE I got error messasge
    ORA-06550: Table,View Or Sequence reference not allowed in this context.
    PLS-00357:
    Can anyone can help me, please ?
    WHEN
    Edited by: user6446424 on 11.3.2010 13:59

    Works for me:
    SQL> create or replace
      2  PROCEDURE universal_p (
      3  tab IN VARCHAR2,
      4  col IN VARCHAR2,
      5  whr IN VARCHAR2 := NULL)
      6  IS
      7  TYPE cv_type IS REF CURSOR;
      8  cv cv_type;
      9  val VARCHAR2(32767);
    10  BEGIN
    11  OPEN cv FOR
    12  'SELECT ' || col ||
    13  ' FROM ' || tab ||
    14  ' WHERE ' || NVL (whr, '1 = 1');
    15
    16  LOOP
    17  FETCH cv INTO val;
    18  EXIT WHEN cv%NOTFOUND;
    19  IF cv%ROWCOUNT = 1
    20  THEN
    21  DBMS_OUTPUT.PUT_LINE (RPAD ('-', 60, '-'));
    22  DBMS_OUTPUT.PUT_LINE (
    23  'Contents of ' ||
    24  UPPER (tab) || '.' || UPPER (col));
    25  DBMS_OUTPUT.PUT_LINE (RPAD ('-', 60, '-'));
    26  END IF;
    27  DBMS_OUTPUT.PUT_LINE (val);
    28  END LOOP;
    29
    30
    31  CLOSE cv;
    32  END;
    33
    34  /
    Procedure created.
    SQL> exec universal_p('EMP','ENAME')
    Contents of EMP.ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    PL/SQL procedure successfully completed.
    SQL> select * from v$version
      2  ;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - ProductionMax
    http://oracleitalia.wordpress.com

  • Not able to pass table name as parameter in function

    Hi,
    i am not able to pass tablename as parameter. I am using below function.
    function count_test(tabname varchar2) return number is
    l_count number;
    begin
    select count(*) INTO l_count FROM tabname;
    RETURN l_count;
    END;

    You can't do it with static SQL.
    The only way is to do it with dynamic SQL:
    EXECUTE IMMEDIATE 'select count(*) FROM '|| tabname INTO l_count;
    Regards.
    Al
    Edited by: Alberto Faenza on May 10, 2012 1:44 AM
    Mispelling

  • Here's how to pass XML as a parameter to an Oracle stored proc

    This, or something like it, should be all over the web and I intend to do so.
    The first sample has exactly what you need in order to pass "XML" as a parm to a stored proc.
    http://www.oracle-base.com/forums/viewtopic.php?f=2&t=8468

    > Really, what is the difference between the 2?
    "What is a...?" questions are easily answered by Google. Generally speaking, however, "JavaScript" is Netscape's implementation of ECMAScript, a scripting language primarily for client-side development for a web browser. "Java" is an entire platform, but typically refers to an object-oriented programming language that is typically compiled to bytecode and run in a virtual machine.
    They're not the same thing at all.
    ~

  • PASSING TABLES AS PARAMETERS IN FOR ALL INSERT

    Hi All,
    I want to pass table as a parameter to perform update in dynamic sql....
    sample code:
    declare
    cur_tab1 is select * from tabl1;
    TYPE tables_bulk is TABLE OF table2.source_table%TYPE;
    v_tables_bulk tables_bulk;
    ls_exe varchar2(2000);
    begin
    for i in cur_tab1 loop
    select source_table bulk collect into v_tables_bulk from table2 where table_id =i.col1
    forall i in 1..v_tables_bulk.count
    ls_exe :='update '|| v_tables_bulk(i) || set bulk_col1|| =i.col2'
    end;
    code description :
    here source_table is a column in table 2..source table column contains many tables..I have to fecth that table and update it with conditions using cursor.Also for select condition , we will get more than one value (more tables)..so i used bulk collect instead of normal variable.......i get local collection error..please help me out..

    user2639048 wrote:
    I did that but still it showed invalid sql....What is version of your database ?
    Some syntax works on newer versions, and is disallowed on older.
    Here is an example that works on Oracle 11g2
    -- create base table
    CREATE TABLE TAB AS
    SELECT TAB_ID,
           EMP_ID,
           'NAME ' || TAB_ID NAME,
           ROUND( DBMS_RANDOM.VALUE( 1, 1000 ), 2 ) SALARY
    FROM (
      SELECT ROUND( DBMS_RANDOM.VALUE(1,20)) TAB_ID,
             LEVEL EMP_ID
      FROM DUAL
      CONNECT BY LEVEL <= 100
    -- create child tables
    DECLARE
      X PLS_INTEGER;
    BEGIN
      SELECT MAX( TAB_ID ) INTO X
      FROM TAB;
      FOR I IN 1 .. X LOOP
         EXECUTE IMMEDIATE
            'CREATE TABLE TAB' || I ||
           q'{ AS SELECT * FROM TAB
               WHERE 1 = 0 }';
      END LOOP;
    END;
    CREATE OR REPLACE
    PACKAGE UPDATE_TAB IS
       TYPE TAB_TAB_TYP IS TABLE OF TAB%ROWTYPE;
       PROCEDURE UPDATE_TAB( I_TAB IN TAB_TAB_TYP );
       PROCEDURE TEST_UPDATE_TAB;
    END UPDATE_TAB;
    CREATE OR REPLACE
    PACKAGE BODY UPDATE_TAB AS
      PROCEDURE UPDATE_TAB( I_TAB IN TAB_TAB_TYP ) AS
      BEGIN
        FOR I IN I_TAB.FIRST .. I_TAB.LAST
        LOOP
            EXECUTE IMMEDIATE
                ' UPDATE TAB' || I_TAB(I).TAB_ID ||
                Q'{ SET TAB_ID = :TABID, NAME = :NAM, SALARY = :SAL
                    WHERE EMP_ID = :EMPID }'
            USING I_TAB(I).TAB_ID, I_TAB(I).NAME,
                    I_TAB(I).SALARY, I_TAB(I).EMP_ID;
            IF SQL%ROWCOUNT <= 0 THEN
                EXECUTE IMMEDIATE
                  ' INSERT INTO TAB' || I_TAB(I).TAB_ID ||
                  ' ( TAB_ID, EMP_ID, NAME, SALARY ) ' ||
                  ' VALUES( :TABID,  :EMPID, :NAME , :SAL )'
                USING I_TAB(I).TAB_ID, I_TAB(I).EMP_ID,
                      I_TAB(I).NAME, I_TAB(I).SALARY;
            END IF;
        END LOOP;
      END UPDATE_TAB;
       PROCEDURE TEST_UPDATE_TAB IS
         L_TAB TAB_TAB_TYP;
       BEGIN
          SELECT * BULK COLLECT INTO L_TAB
          FROM TAB;
          UPDATE_TAB( L_TAB );
       END;
    END UPDATE_TAB;
    --- TEST
    BEGIN
      UPDATE_TAB.TEST_UPDATE_TAB;
    END;
    SELECT * FROM TAB16;
    TAB_ID                 EMP_ID                 NAME                                          SALARY                
    16                     2                      NAME 16                                       455.86                
    16                     6                      NAME 16                                       253.18                
    16                     14                     NAME 16                                       478.92                
    16                     32                     NAME 16                                       381.27                
    16                     56                     NAME 16                                       737.77                
    16                     58                     NAME 16                                       382.65                
    16                     70                     NAME 16                                       203.03                
    16                     100                    NAME 16                                       435.73                
    8 rows selected
    SELECT * FROM TAB2;
    TAB_ID                 EMP_ID                 NAME                                          SALARY                
    2                      1                      NAME 2                                        737.91                
    2                      18                     NAME 2                                        35.61                 
    2                      22                     NAME 2                                        57.76                 
    2                      33                     NAME 2                                        851.72                
    2                      73                     NAME 2                                        109.74
    5 rows selected
    UPDATE TAB SET SALARY = 100
    WHERE TAB_ID = 2;
    5 rows updated
    BEGIN
      UPDATE_TAB.TEST_UPDATE_TAB;
    END;
    SELECT * FROM TAB2;
    TAB_ID                 EMP_ID                 NAME                                          SALARY                
    2                      1                      NAME 2                                        100                   
    2                      18                     NAME 2                                        100                   
    2                      22                     NAME 2                                        100                   
    2                      33                     NAME 2                                        100                   
    2                      73                     NAME 2                                        100    
    5 rows selected 

  • Oracle 9i - passing a string as parameter when integer is required yet

    Dear all;
    I am trying to fix this problem with a limited amount effort and also prevent redesigning it as well. I know it is completely wrong but it was done by a past developer and I am just trying to make a simple twick to it. I will try to explain my current problem so please bear with me
    I have a table with a field called SN which is number type field, I have a select statement similar to this below
    select stype from tbl_one where sn = 1ok, the select statement works for numbers and numbers with dash(e.g 03-2). In the case of numbers with dash, it returns null which is okay now, I am having a bit of problems where sometimes the user entry is a an actual string like this (cat). Now the select statement isnt going to work for this case because I am going to get a Ora-00904 - invalid identifier error.
    The solution I had in mind is first use a regular expression to determine whether the parameter is a string or a numeric value and if it is a numer value pass it as a parameter to the select statment if not, then just return null in the select statement. However, since I am using oracle 9i I cant use regualr expression is there any suitable sql statment i can use in replacement of a regular expression or any other ideas.
    All help is appreciated. Thank you.

    Hi,
    user13328581 wrote:
    ... the select statement works for numbers and numbers with dash(e.g 03-2). That's actually not a number with a dash. That's a subtraction operation involving two numbers, 03 (which is the same as 3) and 2. 3 - 2 = 1, so it's the same as typing 1.
    The solution I had in mind is first use a regular expression to determine whether the parameter is a string or a numeric value and if it is a numer value pass it as a parameter to the select statment if not, then just return null in the select statement. However, since I am using oracle 9i I cant use regualr expression is there any suitable sql statment i can use in replacement of a regular expression or any other ideas.If you just want to see if the string s contains anything other than a digit, use
    LTRIM ( s
          , '0123456789'
          )  IS NOT NULLThe condition above will be TRUE when s contains anything other than a digit.
    If you want to check for signs, decimal points, and scientific notation, then see this thread:
    How to identify if a Varchar2 string has a-z characters?
    for a user-defined function.
    Edited by: Frank Kulash on Apr 21, 2011 11:28 AM

  • Pass table name as a parameter to function

    Is there a way to pass table name as a parameter to functions? Then update the table in the function.
    Thanks a lot.
    Jiaxin

    Hi, Harm,
    Thank you very much for your suggestion and example. But to get my program work, i need to realise code like follows:
    CREATE OR REPLACE FUNCTION delstu_func(stuno char) RETURN NUMBER AS
    BEGIN
    EXECUTE IMMEDIATE 'DELETE FROM student s' ||
    'WHERE' || 's.student_number' || '=' || stuno;
    LOOP
    DBMS_OUTPUT.PUT_LINE('record deleted');
    END LOOP;
    END;
    SELECT delstu_func('s11') FROM STUDENT;
    The intention is to check if such a function can perform operations such as update, delete and insert on occurence of certain values. When executing the above statement, the system returns an error message:
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    ORA-06512: at "SCMJD1.DELSTU_FUNC", line 3
    Could you tell me where is wrong?
    Jiaxin

  • Is it possible to pass TABLE as the output parameter in stored procedure

    Hey Experts,
      Is it possible to pass TABLE as the output parameter in stored procedure.
    eg
    create procedure spGetData
    @tableName as TABLE(intValue INT NOT NUL)
    as 

    You can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
    some limitations with these methods:
    http://technet.microsoft.com/en-us/library/ms188427.aspx
    In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
    exec sp_serveroption @server = 'PRODSVR\SQL2012'
    ,@optname = 'DATA ACCESS'
    ,@optvalue = 'TRUE'
    LINK: http://www.sqlusa.com/bestpractices/select-into/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Maybe you are looking for