Unique id in dynamic sql

hi all,
I am using oracle 10g version.
I have one table but i do not have any unique id to identify the row.
I want to have a unique id temporarily in my select statement (dynamic sql) in a stored procedure while fetching the results, so that i can return my results along with the unique id through the cursor.
Please help me...
Thanks in advance to all...

it depends if you have a more than one column that you can uniquely identify and put them together by concatenating you can have a unique id. or a rowid might help you to temporarily identify a row.
SQL> select e.* from employee e;
FNAME           MINIT LNAME           SSN       BDATE       ADDRESS                        SEX       SALARY SUPERSSN         DNO
John            B     Smith           123456789 09-Jan-1965 731 fONDREN, hOUSTON, TX       M       30000.00 333445555          5
Frankin         T     Wong            333445555 08-Dec-1955 683 Voss, Houston,Tx           M       40000.00 888665555          5
Alicia          J     Zelaya          999887777 19-Jul-1968 3321Castle, Spring, TX         F       25000.00 987654321          4
Jennifer        S     Wallace         987654321 20-Jun-2041 291 Berry, Bellaire, TX        F       43000.00 888665555          4
Ramesh          K     Narayan         666884444 15-Sep-1962 975 Fire Oak, Humble, TX       F       38000.00 333445555          5
Joyce           A     English         453453453 31-Jul-1972 5631 Rice,Houston,TX           F       25000.00 333445555          5
Ahmad           V     Jabbar          987987987 29-Mar-1969 980 Dallas,Houston, TX         M       25000.00 987654321          4
James           E     Borg            888665555 10-Nov-2037 450 Stone, Houston, TX         M       55000.00                    1
8 rows selected
SQL> select rowid, e.* from employee e;
ROWID              FNAME           MINIT LNAME           SSN       BDATE       ADDRESS                        SEX       SALARY SUPERSSN         DNO
AAD8pbAAJAAAJ4fAAA John            B     Smith           123456789 09-Jan-1965 731 fONDREN, hOUSTON, TX       M       30000.00 333445555          5
AAD8pbAAJAAAJ4fAAB Frankin         T     Wong            333445555 08-Dec-1955 683 Voss, Houston,Tx           M       40000.00 888665555          5
AAD8pbAAJAAAJ4fAAC Alicia          J     Zelaya          999887777 19-Jul-1968 3321Castle, Spring, TX         F       25000.00 987654321          4
AAD8pbAAJAAAJ4fAAD Jennifer        S     Wallace         987654321 20-Jun-2041 291 Berry, Bellaire, TX        F       43000.00 888665555          4
AAD8pbAAJAAAJ4fAAE Ramesh          K     Narayan         666884444 15-Sep-1962 975 Fire Oak, Humble, TX       F       38000.00 333445555          5
AAD8pbAAJAAAJ4fAAF Joyce           A     English         453453453 31-Jul-1972 5631 Rice,Houston,TX           F       25000.00 333445555          5
AAD8pbAAJAAAJ4fAAG Ahmad           V     Jabbar          987987987 29-Mar-1969 980 Dallas,Houston, TX         M       25000.00 987654321          4
AAD8pbAAJAAAJ4fAAH James           E     Borg            888665555 10-Nov-2037 450 Stone, Houston, TX         M       55000.00                    1
8 rows selected
SQL>

Similar Messages

  • Dynamic SQL within a SQL Query ?

    is there any possibility to do like this ?
    SELECT table_name, XXXXXXXX('SELECT Count(*) FROM '||table_name) tot_rows
      FROM dba_tables
    WHERE owner = 'SCOTT';or any other trick to run dynamic SQL within the SQL Query?
    Hoping....that it should be.
    Regards,
    Orapdev

    One small disadvantage: it is executing 202 SQL statements: 3 "user SQL statements" (the one above and the 2 "select count(*)..."), and 199 internal ones ...How did you get to those numbers?
    I just traced this statement and found completely different results:
    TKPROF: Release 10.2.0.3.0 - Production on Tue Jul 10 12:12:10 2007
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: diesl10r2_ora_5440.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    declare  cursor NlsParamsCursor is    SELECT * FROM
      nls_session_parameters;begin  SELECT Nvl(Lengthb(Chr(65536)),
      Nvl(Lengthb(Chr(256)), 1))    INTO :CharLength FROM dual;  for NlsRecord in
      NlsParamsCursor loop    if NlsRecord.parameter = 'NLS_DATE_LANGUAGE' then  
         :NlsDateLanguage := NlsRecord.value;    elsif NlsRecord.parameter =
      'NLS_DATE_FORMAT' then      :NlsDateFormat := NlsRecord.value;    elsif
      NlsRecord.parameter = 'NLS_NUMERIC_CHARACTERS' then     
      :NlsNumericCharacters := NlsRecord.value;    elsif NlsRecord.parameter =
      'NLS_TIMESTAMP_FORMAT' then      :NlsTimeStampFormat := NlsRecord.value;   
      elsif NlsRecord.parameter = 'NLS_TIMESTAMP_TZ_FORMAT' then     
      :NlsTimeStampTZFormat := NlsRecord.value;    end if;  end loop;end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    SELECT NVL(LENGTHB(CHR(65536)), NVL(LENGTHB(CHR(256)), 1))
    FROM
    DUAL
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.01       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
          1  FAST DUAL  (cr=0 pr=0 pw=0 time=7 us)
    SELECT *
    FROM
    NLS_SESSION_PARAMETERS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0          17
    total        3      0.00       0.00          0          0          0          17
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
         17  FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=124 us)
    select PARAMETER,VALUE
    from
    nls_session_parameters where PARAMETER in('NLS_NUMERIC_CHARACTERS',
      'NLS_DATE_FORMAT','NLS_CURRENCY')
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           3
    total        3      0.00       0.00          0          0          0           3
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          3  FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=57 us)
    select to_char(9,'9C')
    from
    dual
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          1  FAST DUAL  (cr=0 pr=0 pw=0 time=2 us)
    SELECT table_name,
           DBMS_XMLGEN.getxmltype ('select count(*) c from ' || table_name).EXTRACT
                                                                    ('//text').getstringval
                                                                          () tot
      FROM dba_tables
    WHERE table_name IN ('EMP', 'DEPT') AND owner = 'SCOTT'
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.01       0.02          0         48          0           2
    total        3      0.01       0.02          0         48          0           2
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          2  HASH JOIN  (cr=42 pr=0 pw=0 time=2952 us)
          2   MERGE JOIN CARTESIAN (cr=42 pr=0 pw=0 time=1206 us)
          2    NESTED LOOPS OUTER (cr=42 pr=0 pw=0 time=478 us)
          2     NESTED LOOPS OUTER (cr=36 pr=0 pw=0 time=421 us)
          2      NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=379 us)
          2       NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=365 us)
          2        NESTED LOOPS  (cr=22 pr=0 pw=0 time=312 us)
          2         NESTED LOOPS  (cr=16 pr=0 pw=0 time=272 us)
          2          NESTED LOOPS  (cr=8 pr=0 pw=0 time=172 us)
          1           TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=56 us)
          1            INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=30 us)(object id 44)
          2           INLIST ITERATOR  (cr=6 pr=0 pw=0 time=111 us)
          2            TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=87 us)
          2             INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=54 us)(object id 37)
          2          TABLE ACCESS CLUSTER TAB$ (cr=8 pr=0 pw=0 time=98 us)
          2           INDEX UNIQUE SCAN I_OBJ# (cr=4 pr=0 pw=0 time=26 us)(object id 3)
          2         TABLE ACCESS CLUSTER TS$ (cr=6 pr=0 pw=0 time=39 us)
          2          INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=13 us)(object id 7)
          2        TABLE ACCESS CLUSTER SEG$ (cr=8 pr=0 pw=0 time=37 us)
          2         INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=4 pr=0 pw=0 time=21 us)(object id 9)
          0       INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=4 us)(object id 36)
          2      TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=33 us)
          2       INDEX UNIQUE SCAN I_OBJ1 (cr=4 pr=0 pw=0 time=23 us)(object id 36)
          2     TABLE ACCESS CLUSTER USER$ (cr=6 pr=0 pw=0 time=28 us)
          2      INDEX UNIQUE SCAN I_USER# (cr=2 pr=0 pw=0 time=12 us)(object id 11)
          2    BUFFER SORT (cr=0 pr=0 pw=0 time=716 us)
          1     FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=661 us)
       1436   FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=1449 us)
    select count(*) c
    from
    EMP
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          1          0           1
    total        4      0.00       0.00          0          1          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT AGGREGATE (cr=1 pr=0 pw=0 time=96 us)
         14   INDEX FULL SCAN EMP_IDX (cr=1 pr=0 pw=0 time=46 us)(object id 61191)
    select metadata
    from
    kopm$  where name='DB_FDO'
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          2          0           1
    total        3      0.00       0.00          0          2          0           1
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS   (recursive depth: 1)
    Rows     Row Source Operation
          1  TABLE ACCESS BY INDEX ROWID KOPM$ (cr=2 pr=0 pw=0 time=42 us)
          1   INDEX UNIQUE SCAN I_KOPM1 (cr=1 pr=0 pw=0 time=22 us)(object id 365)
    select count(*) c
    from
    DEPT
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          1          0           1
    total        4      0.00       0.00          0          1          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    ALTER SESSION SET sql_trace=FALSE
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Parsing user id: 50 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        5      0.00       0.00          0          0          0           0
    Execute      5      0.00       0.00          0          0          0           1
    Fetch        3      0.01       0.02          0         48          0           6
    total       13      0.01       0.03          0         48          0           7
    Misses in library cache during parse: 0
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        5      0.00       0.00          0          0          0           0
    Execute      5      0.01       0.00          0          0          0           0
    Fetch        7      0.00       0.00          0          4          0          21
    total       17      0.01       0.00          0          4          0          21
    Misses in library cache during parse: 0
        9  user  SQL statements in session.
        1  internal SQL statements in session.
       10  SQL statements in session.
    Trace file: diesl10r2_ora_5440.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           1  session in tracefile.
           9  user  SQL statements in trace file.
           1  internal SQL statements in trace file.
          10  SQL statements in trace file.
          10  unique SQL statements in trace file.
         132  lines in trace file.
           0  elapsed seconds in trace file.I only see a ratio of 1:9 for user- to internal SQL statements?
    michaels>  select * from v$version
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production                         
    CORE     10.2.0.3.0     Production                                     
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production        
    NLSRTL Version 10.2.0.3.0 - Production  

  • Dynamic SQL generation

    Hi All,
    As part of the ODI Transforms, is it possible to create dynamic sqls at the run time, which could be dependent on the data coming inside, which in turn would be looking at some kind of mapping table and create the sql dynamically.
    Is this feature possible ODI?
    Thanks in advance for your input.

    Hi Cezar Santos,
    Thanks for the reply. The scenario is given below:
    Logic to dynamically map chartfield to segment.
    A user would have access to a GUI domain value map that would allow them to map BU/Chartfield to Ledger/Segment.
    Edge App 1 (PSFT)     AIA Common Key     Edge App 2 (Retail)
    Business Unit (from SETID)     Chartfield          Segment     Ledger
    US001     ACCOUNT     1     SEGMENT1     Ledger1
    US001     DEPARTMENT     2     SEGMENT2     Ledger1
    US001     PRODUCT     3     SEGMENT3     Ledger1
    US001     OPERATING_UNIT     4     SEGMENT4     Ledger1
    US002     OPERATING_UNIT     5     SEGMENT2     Ledger2
    US002     ACCOUNT     6     SEGMENT3     Ledger2
    US002     DEPARTMENT     7     SEGMENT4     Ledger2
    US003     OPERATING_UNIT     8     SEGMENT1     Ledger3
    The transformation happens inside the XFORM view by using an alias to select the columns from RETAIL_STG. Once the aliases are applied, the view can be mapped one to one with the PSFT_STG table.
    Use ODI to select unique Ledgers from RETAIL_STG.
    Execute transformation and transportation of data.
    Move to next Ledger and repeat.
    For US001/Ledger1
    SELECT LEDGER AS BUSINESS_UNIT, SEGMENT1 AS ACCOUNT, SEGMENT2 AS DEPARTMENT, SEGMENT3 AS PRODUCT, SEGMENT4 AS OPERATING UNIT FROM RETAIL_STG WHERE LEDGER = “Ledger1”
    For US002/Ledger2
    SELECT LEDGER AS BUSINESS_UNIT, SEGMENT3 AS ACCOUNT, SEGMENT4 AS DEPARTMENT, ‘ ‘, SEGMENT2 AS OPERATING UNIT FROM RETAIL_STG WHERE LEDGER = “Ledger2”
    For US003/Ledger3
    SELECT LEDGER AS BUSINESS_UNIT, ‘ ‘,’ ‘, ‘ ‘, SEGMENT1 AS OPERATING UNIT FROM RETAIL_STG WHERE LEDGER = “Ledger3”
    Kindly provide your thoughts. If you have questions, please let me know.
    Thanks.

  • Dynamic sql - built

    i have a table with say - rule_component
    which has two columns
    1.db_table
    2.from_clause
    The two columns contains tables for example
    db_table
    emp
    dept
    bonus
    emp
    def
    from_clause
    emp,dept,bonus,dept,emp,abc
    My requirement
    i want to find the duplicate tables in both the from_clause and db_table column
    and populate in my from clause which are unique to both the columns
    say example
    select ......
    from emp,dept,bonus,abc,def

    SQL> descr sswms_rule_components;
    Name Null? Type
    RULE_COMPONENT_ID NOT NULL NUMBER
    RULE_COMPONENT_CODE NOT NULL VARCHAR2(30)
    RULE_COMPONENT_NAME NOT NULL VARCHAR2(100)
    ENABLED_FLAG NOT NULL VARCHAR2(1)
    DB_TABLE VARCHAR2 (100)
    DB_COLUMN VARCHAR2 (100)
    DB_FUNCTION VARCHAR2(100)
    WHERE_CLAUSE VARCHAR2 (2000)
    FROM_CLAUSE VARCHAR2 (2000)
    The table contains the following data
    db_table
    sswms_shipment_lines
    wsh_carrier_ship_method --- the data inside the db_table column is a table
    db_column
    Ship to
    Carrier_id
    Where_clause
    Oe_order_headers_all.header_id = sswms_shipment_lines.order_header_id
    From_clause
    Oe_order_headers_all, sswms_shipment_lines -- the data inside the From_clause is a table
    Now my requirement is to build a dynamic sql in forms 6i.when I click the build sql it should update the sql
    So --- I have to write a procedure --
    Select db_table || . || db_column || ‘’ || group_key
    ---group_key is an alias
    From db_table, From_clause
    --- Here the logic should be
    1. I should remove the commas from the “FROM_CLAUSE” and check for duplicate values
    2. i should check for duplicate values for the “DB_TABLE “ column
    3. I should compare both the FROM_CLAUSE and DB_TABLE for DUPLICATE VALUES
    4. After doing this I should add the result to the “FROM” in the select statement
    where where_clause
    hope this is clear.
    regards
    sudharshan

  • NULL and dynamic SQL

    If table testrh2 has the following columns and data
    col1 --> NULL
    col2 --> 2
    and table testrh has the following columsn and data
    col1 --> NULL
    How could I write a dynamic SQL statement to join on the nulls? I've written the following block as a starting point.
    declare
    cursor c1 is select col1 from isis.testrh;
    lval varchar2(1000);
    lval2 varchar2(1000);
    begin
    for r1 in c1 loop
    lval := 'select col2 from isis.testrh2 where col1 = '||r1.col1;
    execute immediate lval into lval2;
    dbms_output.put_line(lval2);
    end loop;
    end;

    You can't compare null values with '=' in Oracle SQL.
    Null can only be compared with <column> is null .
    You can see it when you try these two queries:
    select * from dual where null is null;  -- you will see one row
    select * from dual where null=null;  -- you will see no rowsThat's why you have to write something like
    (<column1>=<column1>   or   (<column1> is null and <column2> is null))This should also work with null:
    decode(<column1>,<column2>,1,0)=1By the way, why do you use dynamic sql?
    lval := 'select col2 from isis.testrh2 where col1 = '||r1.col1;
    I think you could replace your two lines ( lval:= ... AND execute immediate) by this:
    begin
      select col2
      into lval
      from isis.testrh2
      where decode(col1,r1.col1,1,0)=1;
      dbms_output.put_line('lval='||lval);
    exception
    when no_data_found then
      dbms_output.put_line('no data found'); -- or whatever you want
    end;Edited by: hartmutm on 02.10.2010 23:54

  • How to rename C00n generic column names in a Dynamic SQL report

    I have a an interface whereby the user can select 1 to 60 (upper limit) columns out of 90 possible columns (using a shuttle) from one table before running a report.
    To construct the SQL that will eventually execute, I'm using a "PLSQL function body returning SQL query" with dynamic SQL. The only problem is that I have to use "Generic Column Names" option to be able to compile the code and end up with c001 to c060 as the column names.
    How can I use the names of the selected columns as the report headings rather than c001, C002... etc?
    I do not know beforehand which columns, or how many columns or the order of the selected columns.
    I know Denes K has a demo called Pick Columns but I can't access his code. I have a hunch though that he may be just using conditions to hide/show the apropriate columns.
    thanks in advance
    PaulP

    Hi Paul
    I would change the Heading Type in the Report Details screen to PLSQL and use the shuttle item to return the column values. e.g.
    RETURN :p1_shuttle;
    I'm assuming the shuttle already has a colon separated list of the column headings in the correct order?
    I hope that helps
    Shunt

  • Can we use Dynamic SQL in Oracle Reports ?

    Hi ,
    Can we use Dynamic SQL in Oracle Reports ?
    If yes please give some examples .
    Thanx
    srini

    I believe the built-in package SRW.Do_Sql is what you are looking for
    Example from the document:
    /* Suppose you want to create a "table of contents" by getting the
    ** first character of a columns value, and page number on which its
    ** field fires to print. Assume that you want to put the "table of
    contents"
    ** into a table named SHIP. You could write the following construct:
    DECLARE
    PAGE_NO NUMBER;
    PAGE_FOR INDEX NUMBER;
    SORT_CHAR CHAR(1);
    CMD_LINE CHAR(200);
    BEGIN
    SORT_CHAR := :SORT_NAME ;
    IF :CALLED = Y THEN
         SRW.GET_PAGE_NUM(PAGE_FOR_INDEX);
         SRW.USER_EXIT(RWECOP PAGE_FOR_INDEX
         P_START_PAGENO);
         SRW.MESSAGE(2,TO_CHAR(:P_START_PAGENO));
    END IF;
    SRW.GET_PAGE_NUM(PAGE_NO);
    CMD_LINE := INSERT INTO SHIP VALUES
                          (||SORT_CHAR||,||TO_CHAR(PAGE_NO)||);
    SRW.MESSAGE(2,CMD_LINE);
    SRW.DO_SQL(CMD_LINE);
    COMMIT;
    EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
            NULL;
      WHEN SRW.DO_SQL_FAILURE THEN
            SRW.MESSAGE(1,FAILED TO INSERT ROW INTO SHIP TABLE);
      WHEN OTHERS THEN
           COMMIT;
    END;

  • How to mention numbers in array while creating dynamic sql

    Hi,
    I am creating a dynamic sql and in that I am selecting some rows from the table and storing it into the array.
    I am firing this sql statement within trigger.
    But i got the error:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    I took the same sql statement (the one which was created dynamically) in the procedure and tried to run it but it gave me the same error.
    =========================================================
    Begin
    type NewValueArray is table of varchar2(4000);
    nVal_Array NewValueArray;
    Begin
    Select
    DISCOVERYHOSTNAME,
    DISCOVERYMACPRIMARYPHYSICAL,
    DISCOVERYSERIALNUMBER
    into
    nVal_Array(1),
    nVal_Array(2),
    nVal_Array(3)
    from ALT_42_Consolidated
    where rowid = 'AAEWNEABXAAAAkxAAA';
    EXCEPTION
    WHEN others THEN
    Raise;
    End;
    =========================================================
    I tried using to_number but still the same error.
    Can some body please inform me where I am goofing.
    Thanks!

    I got a different error, but you need to initialise your nval_array and make sure it can hold three values. The following should work:
    declare
      type NewValueArray is table of varchar2(4000);
      nVal_Array NewValueArray := NewValueArray();
    Begin
      nval_array.extend(3);
      Select col1, col2, col3
      into nVal_Array(1), nVal_Array(2), nVal_Array(3)
      from tab1
      where rowid = 'AAAGJZAAGAAAAAWAAV';
    EXCEPTION
      WHEN others THEN
        Raise;
    End;
    /

  • Dynamic SQL and MERGE

    Hi all,
    I'm under 10G r1
    I want to execute a dynamic SQL with merge in it
    when I try with insert ,update it works
    but I just want to use merge if possible
    this is the code
    CREATE OR REPLACE
    PROCEDURE I_COLUMN_CDS_FIXINGS
    v_ticker VARCHAR2,
    v_date DATE,
    v_tenor VARCHAR2,
    v_bid NUMBER,
    v_ask NUMBER)
    AS
    l_column VARCHAR2(80);
    v_column_bid VARCHAR2(80);
    v_column_ask VARCHAR2(80);
    v_source VARCHAR2(60) :='CMAN@BBG';
    v_gen_order pls_integer;
    BEGIN
    SELECT 'CDS_SPREAD_'
    ||v_TENOR
    ||'_BID'
    INTO v_column_bid
    FROM dual;
    SELECT 'CDS_SPREAD_'
    ||v_TENOR
    ||'_ASK'
    INTO v_column_ask
    FROM dual;
    dbms_output.put_line(v_ticker||' '||v_column_ask||' '||v_column_bid||' '||v_bid|| ' '||v_ask||' '||v_date);
    EXECUTE immediate 'MERGE into CDS_FIXINGS C
    using ( select v_ticker,'
    ||v_column_bid
    ||','
    ||v_column_ask
    ||',trunc(v_date) info_date ,v_bid,v_ask from dual ) B
    on (C.cds_ticker=b.v_ticker and c.info_date=b.info_date)
    WHEN MATCHED THEN
    update set '||v_column_bid||'=:1,'||v_column_ask||'=:2 using v_bid,v_ask
    WHEN NOT MATCHED THEN
    INSERT
    CDS_TICKER ,
    INFO_DATE ,
    '||v_column_bid||' ,
    '||v_column_ask||' ,
    SOURCE
    VALUES (:1, :2,:3,:4,:5) ' using v_ticker,
    v_date ,
    v_bid ,
    v_ask ,
    v_source
    ---EXCEPTION
    ---when others then raise;
    end;
    when I launch hte procedure
    exec i_column_cds_fixings('TEST',trunc(sysdate-1),'8Y',4232.01,4234.02);
    I get
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    ORA-06512: at "OWNER_HISTO.I_COLUMN_CDS_FIXINGS", line 26
    ORA-06512: at line 1
    How can I deal with this
    Thanks
    babata
    I get

    Sorry
    this is formatted one
    REATE OR REPLACE PROCEDURE i_Column_cds_FixIngs
    (v_Ticker VARCHAR2,
    v_Date DATE,
    v_Tenor VARCHAR2,
    v_Bid NUMBER,
    v_Ask NUMBER)
    AS
    l_Column VARCHAR2(80);
    v_Column_Bid VARCHAR2(80);
    v_Column_Ask VARCHAR2(80);
    v_Source VARCHAR2(60) := 'CMAN@BBG';
    v_gen_Order PLS_INTEGER;
    BEGIN
    SELECT 'CDS_SPREAD_'
    ||v_Tenor
    ||'_BID'
    INTO v_Column_Bid
    FROM Dual;
    SELECT 'CDS_SPREAD_'
    ||v_Tenor
    ||'_ASK'
    INTO v_Column_Ask
    FROM Dual;
    dbms_Output.Put_Line(v_Ticker
    ||' '
    ||v_Column_Ask
    ||' '
    ||v_Column_Bid
    ||' '
    ||v_Bid
    ||' '
    ||v_Ask
    ||' '
    ||v_Date);
    EXECUTE IMMEDIATE 'MERGE into CDS_FIXINGS C
    using ( select v_ticker,'
    ||v_Column_Bid
    ||','
    ||v_Column_Ask
    ||',trunc(v_date) info_date ,v_bid,v_ask from dual ) B
    on (C.cds_ticker=b.v_ticker and c.info_date=b.info_date)
    WHEN MATCHED THEN
    update set '
    ||v_Column_Bid
    ||'=:1,'
    ||v_Column_Ask
    ||'=:2 USING v_bid,v_ask
    WHEN NOT MATCHED THEN
    INSERT
    CDS_TICKER ,
    INFO_DATE ,
    ||v_Column_Bid
    ||' ,
    ||v_Column_Ask
    ||' ,
    SOURCE
    VALUES
    :1,
    :2,
    :3,
    :4,
    :5
    USING v_Ticker,v_Date,v_Bid,v_Ask,v_Source;
    ---EXCEPTION
    ---when others then raise;
    END;
    /

  • Dynamic sql and cursors

    We are running an oracle sql procedure that uses a LOT of dynamic sql. We are using a 3rd party package (SQR) as a sort of shell to run the sql procedure. The 3rd party package passes to us an oracle error. This error says, in effect, that there are no inactive database cursors available and that the sql program is too large to process. We conclude from this that we must increase one or more of the cursor parameters in init.ora (v$parameters). Is this the correct assumption? If not, does anyone know what we can do? We'd prefer not to break up the sql procedure into smaller pieces.

    increase the parameter for open cursors.
    check, wether all cursors in your programs are closed in time, or if you are using ref cursors from front-ends (e.g. Java JDBC) that this front-ends close these ref cursors , too.
    If you want to decrease the size of procedures get rid of comments, superfluos spaces, tabs, etc.
    keep a commented version outside vor documentation purposes.
    Hope thsi helps

  • Dynamic SQL and 255 bytes per line limit

    I would like to create a Dynamic SQL statement that is longer than 255 bytes. What do I need to do to embed a carriage return or something so that the resultant string is broken up into multiple lines?

    Please ignore. This was a stupid question!

  • Dynamic SQL and GRANT CREATE ANY TABLE

    hi gurus,
    i have a dynamic SQL in a procedure where a table will be created from an existing table without data.
    strSQL:='create table ' || strTemp || ' as select * from ' || strArc || ' where 1=2';
    execute immediate strSQL;
    without GRANT CREATE ANY TABLE for the user, *"ORA-01031: insufficient privileges"* error during execution.
    Is there a way to tackle this issue without providing GRANT CREATE ANY TABLE privilige?
    many thanks,
    Charles

    ravikumar.sv wrote:
    The problem is not because of dynamic sql...It probably has something to do with dynamic SQL or, more accurately, dynamic SQL within a stored procedure.
    From a SQL*Plus command prompt, you can create a table if your account has the CREATE TABLE privilege either granted directly to it or granted to a role that has been granted to your account. Most people probably have the CREATE TABLE privilege through a role (hopefully a custom "developer role" that has whatever privileges you grant to users that will own objects but potentially through the default RESOURCE role). That is not sufficient to create tables dynamically via a definer's rights stored procedure. Only privileges that are granted directly to the user, not those granted via a role, are visible in that case.
    I expect that the DBAs are granting the CREATE ANY TABLE privilege directly to the account in question rather than through whatever role(s) are being used which is why that appears to solve the problem.
    Justin

  • Dynamic SQL and IN CLAUSE from Pro C code

    Hi Guys,
    Tyring to embed sql in Pro C. Here I don't know in hand how many items will be there in the IN Clause of my dynamic sql. Tried this with a loop and then adding actual values to the stement and then executing it. This worked but as this hard coding makes it literal sql and hence hampers performance. Can any one help me with how to put bind variables where we don't know how many of them will be there in a dynamic sql.
    Thanks,

    Dynamic SQL supports user defined types, try passing a collection and using TABLE(CAST(collection)) in the SQL statement.
    In the current approach (creating IN clause at runtime) keep in mind that in a IN clause you can put a maximum of 255 elements...
    Max

  • Dynamic SQL and use of aggregate functions

    Hello Forum members,
    I'm trying to create dynamic SQL in a function module and return the MAX value of a field. 
    I am passing in a parameter called CREATE_FIELD_NAME, and my SQL is
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    I also tried:
    SELECT MAX((CREATE_FIELD_NAME)) INTO (CREATE_DATE) FROM (TABLE_NAME).
    But abap is not recognizing my variable as a variable in either case, but rather, as a field name.
    Anyone know a way around this?
    Thanks in advance,
    Jeff
    Here is my program:
    FUNCTION ZJLSTEST4.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(TABLE_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(CREATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(UPDATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"  EXPORTING
    *"     VALUE(MAX_DATE) LIKE  SY-DATUM
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
          UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    ENDSELECT.
    *SELECT MAX((UPDATE_FIELD_NAME)) INTO (UPDATE_DATE) FROM (TABLE_NAME).
    *ENDSELECT.
    IF CREATE_DATE > UPDATE_DATE.
       MAX_DATE = CREATE_DATE.
    ELSE.
       MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    ENDFUNCTION.

    Max is right, you need the spaces, as in my example.
    You might like to try this:
    data: l_CREATE_FIELD_NAME) LIKE MAKT-MAKTX,
          l_UPDATE_FIELD_NAME) LIKE MAKT-MAKTX.
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
    UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    concatenate 'MAX(' create_name ')' into l_create_name separated by space.
    concatenate 'MAX(' update_name ')' into l_update_name separated by space.
    SELECT SINGLE (l_CREATE_FIELD_NAME)
    INTO CREATE_DATE FROM (table_name).
    SELECT SINGLE (l_updATE_FIELD_NAME)
    INTO updATE_DATE FROM (table_name).
    IF CREATE_DATE > UPDATE_DATE.
    MAX_DATE = CREATE_DATE.
    ELSE.
    MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    If it still fails please post the latest abap code for us to check.

  • Dynamic SQL and PL/SQL Gateway

    This question is kind of out of curiosity...I had created a procedure that used some dynamic sql (execute immediate), and was trying to use it on pl/sql gateway. I kept getting page not found errors until I removed the execute immediate statement, and reverted to using static sql statements.
    I am just curious, is dynamic sql not supported at all with pl/sql gateway?
    Thanks
    Kevin

    > Relax damorgan, no need to be condescending. Of course I read the docs ..
    Well, you're one of the few that actually read the docs.. And one of many that lacked to state any real technical details for forum members to understand the actual problem, the actual error, and what the environment is that this is happening in.
    Remember that you came to this forum for forum members to help you. In order for us to do that, you need to help us understand
    - your problem
    - your environment
    - what you have tried
    What PL/SQL Gateway do you refer to? Thus is an old term for an old product - today in Oracle there are two "gateways" into the PL/SQL engine via HTTP. Via Apache/mod_plsql and via the internal Java servlet web engine called EPG inside Oracle.
    As for what the "Gateway" access to the PL/SQL engine via HTTP.. whether it supports EXECUTE IMMEDIATE or not is like asking if a car "supports" soft drinks or not (just because a human that may consume soft drinks acts as the driver of the car). Not sensible or relevant at all.
    mod_plsql creates an Oracle session to the database instance, and executes a PL/SQL procedure in the database. This is no different from any other client connection to Oracle. Oracle has no clue that the client is mod_plsql and not TOAD or Java or VB or PHP or Perl or whatever else.
    So how can this support or not support the EXECUTE IMMEDIATE command? Does PL/SQL support EXECUTE IMMEDIATE? Well duh...
    Why do you get a generic 404? Because the PL/SQL call made by mod_plsql failed with an unhandled exception. mod_plsql gets that exception and now what? Was a valid HTP buffer created for it to stream to the web browser? If the buffer perhaps partially completed? All that mod_plsql knows is that it asked for a HTP buffer via that PL/SQL call and it got an exception in return.
    A 404 HTTP error is the only reasonable and logical response for it to pass to the web browser in this case.
    PS. to see why mod_plsql fail, refer to the access_log and error_log of that Apache httpd server

Maybe you are looking for

  • I am looking for an app to reduce a photo size to fit into a picture pendant

    i am looking for an app to to shrink photos to print so i can put into a small picture pendant.

  • Laserjet M1522nf driver for Windows 7 64-bit operating system

    My operating system recognizes the printer on the network for printing, but not for scanning or faxing.  I would like to install the correct driver, but there are five (5) different drivers listed without any explanation of the difference between the

  • Archiving the file in to Multiple Directories

    Hi,    I have a scenario which takes the file from the source system and uses proxy to post the data in to ECC.When it picks the file it has to pick from multiple directories.This i can achieve by using advanced selection for source files and also i

  • Adobe Livecycle: Save as Filename from Form Field Assistance

    I have Livecycle E2 and Adobe 9.0.  I am trying to have a pdf save in a desired location with a filename that originates from a field form.  So far, I have created a folder level script under C/programfiles/adobe/acrobat 9.0/acrobat/javascript/xxxxxx

  • ITunes 7 and USB Harddrive issue

    Everytime I install the new version of iTunes, it drops my USB Harddrive from the computer. The system thinks the drive is empty, yet all my folders are there, just no files. I do a system restore and no iTunes, but I can then see everything on the h