Running SQL stored within a varchar2 for an update statement

I have a table that stores option settings for different programs that run in our system. It just has an id (number), name (varchar2(4000)) and value (varchar2(4000)). I will have one record (id=1) that stores sql code to generate a date that is converted into a character format, something like "to_char(sysdate-60,'YYYY-MM-DD HH24:MI:SS')", and I have two records that store dates (id=2 and 3) as text.
I want to run something like "update options set value=(select value from options where id=1) where id=2;", but I know that will store my sql code ('to_char(sysdate-60,''YYYY-MM-DD HH24:MI:SS'')'), and not a text-formatted date ('2009-04-16 13:04:05'). Is there any way within sql that I can use an update statement to store the results of value and not value itself? I generally use C++, so if I had to write a function to accomplish this, I would probably place it in the C++ program instead of a pl/sql function.

"triggers...<shivers>
Are you allowed to change database-side functionality?"
For the most part, yes. We're a small group, and I still do most of the DBA work, despite being a C++ developer and having a part-time DBA. The few triggers we have created are for record id numbers on data that a customer will input through APEX, and I will have to keep those. They're only on inserts, do nothing if the id is populated, and don't exist on this table. The trigger here seems to be something deep within oracle that I cannot change.
CREATE DATABASE LINK LOOPBACK USING '(description=(address=(protocol=beq)(program=/your/path/to/bin/oracle)))';
UPDATE options SET VALUE = dbms_xmlgen.getxmltype('SELECT VALUE FROM options@loopback WHERE id = 1').EXTRACT('//text()').getstringval () WHERE id = 2;
ERROR at line 1:
ORA-12899: value too large for column "TEST"."OPTIONS"."VALUE" (actual: 65, maximum: 55)The "VALUE" column is a varchar(4000). I'm guessing something is too large for one of the oracle functions or there is a problem with a datatype, but I haven't found any answers. Will using extract affect my data in any way, say if my formula has a less than character for some strange reason? I happened to see a comparison between extract().getstringval() and extractval() at [http://pbarut.blogspot.com/2007/01/oracle-xmltype-exctractvalue-vs-extract.html], which makes it look like EXTRACT('//text()').getstringval () will change the less than to '&lt'. I can run tests to check once I get this working, but I'm not sure I can switch the procedure to extractval().
Edited by: jbo5112 on Jun 15, 2009 5:25 PM -- The forum mangled my response when I actually typed the less than character

Similar Messages

  • I'm running Lion on a Late 2008 MacBook Air.  With no other applications running, I can no longer Check for Software Updates.  It gets abut half way through the checking process and then freezes.  The MBA passes Disk Utility. Thoughts?

    I'm running Lion on a Late 2008 MacBook Air. 
    With no other applications running, I can no longer Check for Software Updates.  It gets about half way through the checking process and then freezes. 
    The MBA passes Disk Utility. Thoughts?
    Thanks
    Jim Taylor

    How long do you leave it?
    Mine can sometimes sit for quite a while (maybe 10 minutes??) before it finally finishes.
    You could look at the relevant logs via Console (Utilities folder) to see if Software Update is complaining about anything.
    charlie

  • Help with doing SELECT sub query within the SET of an UPDATE statement

    After doing some research, it appears as if it's possible to use a SELECT subquery in the SET of an UPDATE statement.  i did find some examples and here is my code, however when I click the "check" button it's saying the field (my entire select subquery) is unknown and neither in one of the specified tables or defined by a "DATA".  Do I have a syntax issue or is there another reason why it's not taking this as a valid statement?  Thanks for the help!
    LOOP AT IT_DATA
    UPDATE /BIC/AZDP_O0140
       SET /BIC/ZCOUNTER = (SELECT COUNT( DISTINCT MATERIAL )
                            FROM /BIC/AZDP_O0140
                            WHERE MATERIAL EQ IT_DATA-MATERIAL
                            GROUP BY MATERIAL).
    ENDLOOP.

    my Update does indeed have a WHERE clause but because of the issue i'm having, all my criteria in my WHERE is black text in the ABAP editor.  The editor doesn't even recognize the keywords "WHERE" or "EQ".  Below is my entire statement which contains all WHERE criteria in both the Update and the Subquery, i've just removed it for testing to help simplify the query and eliminate as many other factors as posisble that may be causing problems:
    LOOP AT IT_DATA.
       UPDATE /BIC/AZDP_O0140
       SET /BIC/ZCOUNTER = (SELECT COUNT( DISTINCT MATERIAL ) FROM /BIC/AZDP_O0140
       WHERE WHSE_NUM EQ IT_DATA-WAREHOUSE
        AND  PLANT EQ IT_DATA-PLANT
        AND  /BIC/ZTRAN_NO EQ IT_DATA-TRANS_NUM
        AND  DELIV_NUMB EQ IT_DATA-DELIVERY
        AND  MATERIAL EQ IT_DATA-MATERIAL
        GROUP BY MATERIAL)
       WHERE WHSE_NUM EQ IT_DATA-WAREHOUSE
        AND  PLANT EQ IT_DATA-PLANT
        AND  /BIC/ZTRAN_NO EQ IT_DATA-TRANS_NUM
        AND  DELIV_NUMB EQ IT_DATA-DELIVERY
        AND  MATERIAL EQ IT_DATA-MATERIAL.
    ENDLOOP.
    i should also mention the sources i found were not within the SAP Library but instead on other third-party ABAP websites.  so because i was having issues i wanted to post here to see if anyone else has come up with a working solution.  but if this cannot be done i can likely come up with a solution for my needs using multiple internal tables, this would just have been much easier since i can get a query like this to do what i want in SQL Server.  Thought i could utilize this in ABAP as well.

  • How to run sql scripts using batch file for a web dynpro data dictionary

    Hi,
    I want to develop a sql script to be executed on the server alongwith the installation of a product to pre-populate web dynpro data dictionary tables required for the application.
    I further require to make the scripts independent of the database name,so that it can be run at any client environment.
    Your help will be appreciated and rewarded.

    See shoblock's answer
    call sql script from unix
    masterfile.sql:
    @file1 &1
    @file2 &2
    @file3 &3
    @file4 &4
    then just call the master script:
    sqlplus userid/password @masterfile <p1> <p2> <p3> <p4>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • When I click on a Firefox update My Mac Mini Os 10.4 just keeps running how long should I wait for this update to complete.

    The update just keeps running it seems that it will never complete the update like it is stuck in one place with out progress.
    I have the indicator on my screen going but no advancement.

    Firefox 4 requires at least OS X 10.5 and an Intel Mac.
    * http://www.mozilla.com/firefox/4.0/system-requirements/
    For Mac OS X 10.4.11 or Mac OS X 10.5.8 you can look at:
    * http://www.floodgap.com/software/tenfourfox/
    * Download a new copy of the Firefox program
    * Firefox 3.6: http://www.mozilla.com/en-US/firefox/all-older.html
    * Trash the current Firefox application to do a clean (re-)install
    * Install the new version that you have downloaded
    Your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.

  • All sql is working fine except for the COUNT statement ... ?

    This piece of code using taglib
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    <sql:query var="aantalantw" scope="session">
              SELECT COUNT(*) FROM antwoorden
    </sql:query>
    <c:out value="${aantalantw}"/>
    This result should be something like 12 or some other number of course
    but i seem to get this :
    org.apache.taglibs.standard.tag.common.sql.ResultImpl@fbcb70
    Ideas ?

    Sorry, I made a mistake. The right code is:
    <sql:query var="aantalantw" scope="session">
    SELECT COUNT(*) AS count FROM antwoorden
    </sql:query>
    <c:forEach var="aantalantw_row" items="aantalantw.rows">
    <c:out value="${aantalantw_row.count}"/>
    </c:forEach>

  • Where clause with substr for a update statement

    Dear Reader,
    Currently I am working on a package that will update a value in a column, this column always has a default value of 9999 and is named STATUS_FLAGS
    In my package I need to update this column's value for instance into 9919. Where 1 represents a specific extraction run and 9 represents non-ran records.
    Currently I have the following code (which does not work):
    IF run = 'somevalue' THEN
    -- The flag string: 9999 where 9 = xx, 9 = xxx, 9 = xxxx, 9 = etc
    UPDATE TABLE.STATUS_FLAGS
    SET TABLE.STATUS_FLAGS = 1 || substr(TABLE.STATUS_FLAGS,1,4)
    WHERE SUBSTR(TABLE.STATUS_FLAGS,2,3) <> '1';
    END IF;
    Could you please help me to tell me what I am doing wrong and how I should do it?
    Thanks a lot.
    Edited by: user3542281 on Jan 6, 2009 5:31 AM

    I'm really not sure what you're after - you're saying that my method works correctly and that yours doesn't. So, why aren't you using my method?
    Perhaps you should give us more information about your situation, such as your starting set of data and the updates you'll be doing.
    Or perhaps you want a more generalised version, such as:
    update table t
    set t.status_flags = substr(t.status_flags, 1, p_position_to_update-1)||'1'||substr(t.status_flags, p_position_to_update+1);where p_position_to_update is a parameter that's passed in (or a variable set in the procedure)

  • How to dynamically change the table name for a update statement

    Hi All,
    I need to update a coulumn xyz in either of tables abc and efg based on some condition.
    I wrote a cursor which has union of two queries(one querying abc and other efg)
    Now based on some inparameter only one will be executed at a time.
    And based on some condition a coulumn xyz needs to be updated which is in either of the table.
    As the update condition is same
    Update abc/efg set xyz=data where condition
    I am looking to initialize a variable like v_tname based on some condition and update like
    update v_tname .........
    (Exactly that may not be like so, But looking a technique like this)
    Please help

    If there is only two tables you'll need to update then you are better off using static SQL and implementing something like this instead:
    DECLARE
            update_condition        BOOLEAN;
    BEGIN
            -- initialize update_condition
            update_condition := <some_boolean_check>;
            IF update_condition
            THEN
                    UPDATE abc
                    SET    xyz = some_val
                    WHERE  some_col = some_other_val;
            ELSE
                    UPDATE fgh
                    SET    xyz = some_val
                    WHERE  some_col = some_other_val;   
            END IF;
    END;
    /Hope this helps!

  • Writing a BULK Update for a Update statement

    I want write(convert) this Query in PL/sql code using Bulk Collect and Update since this query is taking more time to execute. How I can achive this ?
    Please Help me.
    UPDATE my_master aa
    SET (pay_date, last_mod_by, last_mod_date, verified_status) =
    (SELECT TO_DATE ('03/09/2007', 'dd/mm/yyyy'), 'S1',
    TO_DATE ('22/02/2008', 'dd/mm/yyyy'), 'Y'
    FROM dtl_1 a, dtl_2 b
    WHERE a.br_id = b.nr_id
    AND aa.acct_num = a.acct_num
    AND TO_DATE (TO_CHAR (aa.dat1, 'mm/yyyy'),
    'mm/yyyy'
    ) <
    TO_DATE (TO_CHAR (a.dat1, 'mm/yyyy'),
    'mm/yyyy'
    WHERE (acct_num) =
    (SELECT a.acct_num
              FROM dtl_1 a, dtl_2 b
    WHERE a.br_id = b.nr_id
    aa.acct_num = a.acct_num
    AND TO_DATE (TO_CHAR (aa.dat1, 'mm/yyyy'),
    'mm/yyyy'
    ) <
    TO_DATE (TO_CHAR (a.dat1, 'mm/yyyy'),
    'mm/yyyy'
    AND dat1 <
    (SELECT a.dat1
    FROM dtl_1 a, dtl_2 b
    WHERE a.br_id = b.nr_id
    aa.acct_num = a.acct_num
    AND TO_DATE (TO_CHAR (aa.dat1, 'mm/yyyy'),
    'mm/yyyy'
    ) <
    TO_DATE (TO_CHAR (a.dat1, 'mm/yyyy'),
    'mm/yyyy'
    ))

    "More" is a relative term. More than what? Perhaps you just mean it is taking a long time and you think it should be possible to make it faster.
    First, if I tidy up the query and simplify the date expressions so it's easier to read, I get this, which should give the same results (but not be any faster):
    UPDATE my_master aa
    SET    ( pay_date, last_mod_by, last_mod_date, verified_status ) =
           ( SELECT DATE '2007-09-03', 'S1', DATE '2008-02-22', 'Y'
             FROM   dtl_1 a
                  , dtl_2 b
             WHERE  a.acct_num = aa.acct_num
             AND    TRUNC(aa.dat1,'mm') < TRUNC(a.dat1,'mm')
             AND    b.nr_id = a.br_id )
    WHERE  acct_num =
           ( SELECT a.acct_num
             FROM   dtl_1 a
                  , dtl_2 b
             WHERE  a.acct_num = aa.acct_num
             AND    TRUNC(a.dat1,'mm') > TRUNC(aa.dat1,'mm')
             AND    b.nr_id = a.br_id )
    AND    dat1 <
           ( SELECT a.dat1
             FROM   dtl_1 a
                  , dtl_2 b
             WHERE  a.acct_num = aa.acct_num
             AND    TRUNC(a.dat1,'mm') > TRUNC(aa.dat1,'mm')
             AND    b.nr_id = a.br_id );If so, I'm a bit confused by the second subquery. Don't you already compare dat1 in the first subquery? I can't test this but isn't it the same as:
    UPDATE my_master aa
    SET    ( pay_date, last_mod_by, last_mod_date, verified_status ) =
           ( SELECT DATE '2007-09-03', 'S1', DATE '2008-02-22', 'Y'
             FROM   dtl_1 a
                  , dtl_2 b
             WHERE  a.acct_num = aa.acct_num
             AND    TRUNC(aa.dat1,'mm') < TRUNC(a.dat1,'mm')
             AND    b.nr_id = a.br_id )
    WHERE  EXISTS
           ( SELECT NULL
             FROM   dtl_1 a
                  , dtl_2 b
             WHERE  a.acct_num = aa.acct_num
             AND    TRUNC(a.dat1,'mm') > TRUNC(aa.dat1,'mm')
             AND a.dat1 > aa.dat1
             AND    b.nr_id = a.br_id );Although if a.dat1 is in a later month than aa.dat1 then the second check is redundant anyway.
    Message was edited by:
    William Robertson

  • Long running sql

    Hi All,
    I have a long running sql which I am tuning for oltp environment.
    Here is the sql
    explain plan for
    SELECT a.* ,rownum as rnm
    FROM ( SELECT /*+ FIRST_ROWS(100) STAR_TRANSFORMATION PARALLEL(PLS,2) */
    /* End of Hint in Query Builder */
    PLD.PRVDR_LCTN_IID AS "ProviderLocationIid", PLD.PRVDR_LCTN_DTL_SID AS "ProviderLocationDetailSid",
    PLD.ENRLMNT_TYPE_CID AS "EnrollMentTypeCid", PLD.PRVDR_TYPE_CODE AS "ProviderTypeCode",
    PLD.MAINECARE_ID AS "Provider Id", PLD.PRVDR_NAME AS "Provider Name",
    PLD.PRVDR_TYPE_CODE || '-' || PLD.PRVDR_TYPE_NAME AS "Provider Type",
    TO_CHAR(PLS.FROM_DATE,'MM/dd/yyyy') AS "Start Date",
    TO_CHAR(PLS.TO_DATE,'MM/dd/yyyy') AS "End Date", PLD.COUNTY_NAME AS "County",
    PLD.CITY_TOWN_NAME AS "Town", PLD.ENRLMNT_TYPE_NAME AS "Enrollment Type",
    PLS.STATUS_CID AS "StatusCid", STSBS.STATUS_NAME AS "Business Status",
    PLD.LCTN_PHONE_NMBR AS "Phone Number", PLD.PRVDR_TYPE_NAME AS "PrvdrTypeName",
    SP.SPCLTY_CODE||'-'||SP.SPCLTY_NAME ||'/'|| SP1.SPCLTY_CODE||'-'||
    SP1.SPCLTY_NAME AS "Specialty/Subspecialty",
    UPPER(SP1.SPCLTY_CODE) AS "SubSpclty", UPPER(SP.SPCLTY_CODE) AS "Spclty"
    FROM /*Query Builder Clause*/
    STATUS STS,
    STATUS STSBS,
    SPECIALTY_SUBSPECIALTY SSP,
    (SELECT PRVDR_LCTN_STATUS_SID, PRVDR_LCTN_IID, PRVDR_LCTN_DTL_SID, FROM_DATE, TO_DATE,
    STATUS_TYPE_CID, STATUS_CID, OPRTNL_FLAG,
    FN_GETANCHORDT(FROM_DATE,TO_DATE) AS ANCHOR_DATE
    FROM PRVDR_LCTN_STATUS
    WHERE STATUS_TYPE_CID = 1
    AND OPRTNL_FLAG = 'A'
    ) PLS,
    PRVDR_LCTN_X_SPCLTY_SUBSPCLTY PXSP,
    PRVDR_LCTN_STATUS PLSBS,
    PROVIDER_LOCATION_DETAIL PLD,
    SPECIALTY SP1,
    SPECIALTY SP
    WHERE
    STS.STATUS_TYPE_CID = 1
    AND STS.STATUS_CID = 2
    AND STSBS.STATUS_TYPE_CID = 15
    AND PLSBS.OPRTNL_FLAG = 'A'
    --          UPPER(UPPER(SP1.SPCLTY_CODE)) LIKE UPPER('1%')
              AND SP1.SPCLTY_CODE LIKE '1%'
    -- AND UPPER(UPPER(SP.SPCLTY_CODE)) LIKE UPPER('1%')
    AND SP.SPCLTY_CODE LIKE '1%'
    AND PLS.OPRTNL_FLAG = 'A'
    AND SP1.OPRTNL_FLAG = 'A'
    AND PXSP.OPRTNL_FLAG = 'A'
    AND PXSP.STATUS_CID = 2
    AND SSP.OPRTNL_FLAG = 'A'
    AND SP.OPRTNL_FLAG = 'A'
    AND PLS.ANCHOR_DATE >= PLSBS.FROM_DATE
    AND PLS.ANCHOR_DATE <= PLSBS.TO_DATE
    AND PLS.STATUS_TYPE_CID = STS.STATUS_TYPE_CID
    AND PLS.STATUS_CID = STS.STATUS_CID
    AND PLD.PRVDR_LCTN_DTL_SID = PLS.PRVDR_LCTN_DTL_SID
    AND PLSBS.PRVDR_LCTN_IID = PLS.PRVDR_LCTN_IID
    AND PLSBS.STATUS_TYPE_CID = STSBS.STATUS_TYPE_CID
    AND PLSBS.STATUS_CID = STSBS.STATUS_CID
    AND PLS.ANCHOR_DATE >= SP1.FROM_DATE
    AND PLS.ANCHOR_DATE <= SP1.TO_DATE
    AND PXSP.PRVDR_LCTN_IID = PLS.PRVDR_LCTN_IID
    AND PXSP.SPCLTY_SUBSPCLTY_SID = SSP.SPCLTY_SUBSPCLTY_SID
    AND PLS.ANCHOR_DATE >= PXSP.FROM_DATE
    AND PLS.ANCHOR_DATE <= PXSP.TO_DATE
    AND SSP.SPCLTY_CODE = SP.SPCLTY_CODE
    -- AND SSP.SUBSPCLTY_CODE = SP1.SPCLTY_CODE
    AND SSP.SUBSPCLTY_CODE = SP1.SPCLTY_CODE
    AND PLS.ANCHOR_DATE >= SSP.FROM_DATE
    AND PLS.ANCHOR_DATE <= SSP.TO_DATE
    AND PLS.ANCHOR_DATE >= SP.FROM_DATE
    AND PLS.ANCHOR_DATE <= SP.TO_DATE
    ORDER BY /*Query Builder Clause*/
    "Provider Id" DESC
    ) A
    WHERE rownum < 101
    Here is the Emplain plan
    SQL> @c:\mohammed\tune\UTLXPLS
    Plan Table
    | Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
    | SELECT STATEMENT | | | | | | |
    | COUNT STOPKEY | | | | | | |
    | VIEW | | | | | | |
    | SORT ORDER BY STOPKEY | | 1 | 358 | 120 | | |
    | SORT ORDER BY STOPKEY | | | | | | |
    | NESTED LOOPS | | 1 | 358 | 117 | | |
    | NESTED LOOPS | | 1 | 313 | 116 | | |
    | NESTED LOOPS | | 1 | 268 | 115 | | |
    | NESTED LOOPS | | 1 | 240 | 114 | | |
    Plan Table
    | NESTED LOOPS | | 1 | 209 | 112 | | |
    | NESTED LOOPS | | 1 | 95 | 111 | | |
    | NESTED LOOPS | | 1 | 74 | 110 | | |
    | NESTED LOOPS | | 7 | 294 | 103 | | |
    | INDEX UNIQUE SCAN |SYS_C00489936 | 1 | 7 | | | |
    | TABLE ACCESS FULL |PRVDR_LCTN_STATUS | 1K| 53K| 102 | | |
    | TABLE ACCESS BY INDEX ROWID |PRVDR_LCTN_STATUS | 57K| 1M| 2 | | |
    | INDEX RANGE SCAN |TUNE_PNBS2_1 | 57K| | 1 | | |
    | TABLE ACCESS BY INDEX ROWID |STATUS | 5 | 105 | 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489936 | 5 | | | | |
    | TABLE ACCESS BY INDEX ROWID |PROVIDER_LOCATION_D | 40K| 4M| 1 | | |
    Plan Table
    | INDEX UNIQUE SCAN |XPKPROVIDER_LOCATIO | 40K| | | | |
    | TABLE ACCESS BY INDEX ROWID |PRVDR_LCTN_X_SPCLTY | 1M| 39M| 3 | | |
    | INDEX RANGE SCAN |TUNE_SARWAR_0503200 | 1M| | 2 | | |
    | TABLE ACCESS BY INDEX ROWID |SPECIALTY_SUBSPECIA | 549 | 15K| 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489888 | 549 | | | | |
    | TABLE ACCESS BY INDEX ROWID |SPECIALTY | 11 | 495 | 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489875 | 11 | | | | |
    | TABLE ACCESS BY INDEX ROWID |SPECIALTY | 11 | 495 | 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489875 | 11 | | | | |
    32 rows selected.
    I have tried with several hints and several driving tables and tires. Any help in this regard will be highly appreciated.
    Thanks a lot,
    Mohammed Sarwar
    ocp dba
    Email: [email protected]
    [email protected]
    Phone : 301-944-2029 w
    913-484-9204 cell

    This should be better. Any help on tuning the above sql statement using the following explain plan will be highly appreciated.
    Plan Table
    | Operation ------------------| Name -------------| Rows | Bytes| Cost | Pstart| Pstop |
    | SELECT STATEMENT -----------| ------------------| -----| -------|------| | |
    | COUNT STOPKEY --------------|-------------------|------|--------|------| | |
    | VIEW -----------------------|-------------------|----- | -------| -----| | |
    | SORT ORDER BY STOPKEY ------|------------------ |--- 1 | ---358 | 120 -| | |
    | SORT ORDER BY STOPKEY ------| ------------------|----- |------- | -----| | |
    | NESTED LOOPS ---------------|-------------------|--- 1 |--358 -|- 117 | | |
    | NESTED LOOPS ---------------|----------------- -|--- 1 | -313 -| -116 | | |
    | NESTED LOOPS ---------------|----------------- -|--- 1 | 268-- | 115 -| | |
    | NESTED LOOPS--------------- |-------------------| --1- | -240 -| -114 | | |
    Plan Table
    | NESTED LOOPS--------------- |------------------ | ---1 |- 209 -|- 112 | | |
    | NESTED LOOPS--------------- | ------------------|--- 1 |-- 95- | -111 | | |
    | NESTED LOOPS ---------------|----- -------------|--- 1 |-- 74 -| -110 | | |
    | NESTED LOOPS ---------------|----------------- -|--- 7 | -294- |- 103| | |
    | INDEX UNIQUE SCAN ----------|SYS_C00489936------| ---1 |--- 7--|-----| | |
    | TABLE ACCESS FULL ----------|PRVDR_LCTN_STATUS -| --1K | 53K-- | 102 | | |
    | TABLE ACCESS BY INDEX ROWID |PRVDR_LCTN_STATUS- | 57K -|---- 1M|-- 2 | | |
    | INDEX RANGE SCAN -----------|TUNE_PNBS2_1 ------| 57K- |------ |-- 1 | | |
    | TABLE ACCESS BY INDEX ROWID |STATUS------------ | 5 |105----|-- 1 | | |
    | INDEX UNIQUE SCAN---------- |SYS_C00489936 -----| 5--- | ------|-----| | |
    | TABLE ACCESS BY INDEX ROWID-|PROVIDER_LOCATION_D| 40K | 4M----|-- 1 | | |
    Plan Table
    | INDEX UNIQUE SCAN ----------|XPKPROVIDER_LOCATIO| 40K |----- |----- | | |
    | TABLE ACCESS BY INDEX ROWID-|PRVDR_LCTN_X_SPCLTY| 1M -|---39M|--- 3 | | |
    | INDEX RANGE SCAN -----------|TUNE_SARWAR_0503200| 1M -| -----|--- 2 | | |
    |TABLE ACCESS BY INDEX ROWID- |SPECIALTY_SUBSPECIA| 549 |---15K| ---1 | | |
    | INDEX UNIQUE SCAN ----------|SYS_C00489888 -----| 549 |----- | -----| | |
    |TABLE ACCESS BY INDEX ROWID- |SPECIALTY ---------| 11- |---495|--- 1 | | |
    | INDEX UNIQUE SCAN ----------|SYS_C00489875----- | 11 -|----- |----- | | |
    |TABLE ACCESS BY INDEX ROWID -|SPECIALTY ---------| 11- |---495|----1 | | |
    | INDEX UNIQUE SCAN-----------|SYS_C00489875----- | 11 -|----- |----- | | |
    --------------------------------------------------------------------------------

  • Execute immediate of Anonymous pl/sql block stored in a VARCHAR2 DB Column

    Hi Guys,
    I really hope someone can help me with this.
    I have the following pl/sql anonymous block stored in a varchar2 database column.
    declare
        l_my_val varchar2(32767);
                cursor c_activity is
                SELECT
                      l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description,  '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
                FROM   ACTIVITY a
                      ,MOUNTAINEERING m
                      ,LOV l
                      ,LOV l2
                WHERE  a.JSATFA_ID = 82
                AND    a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
                AND    m.ACTIVITY_ID(+) = a.ACTIVITY_ID
                AND    m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
    begin
    for each_row in c_activity loop
      l_my_val := l_my_val ||  ', ' || each_row.value1;
    end loop;
    :l_value := ltrim (l_my_val, ', ');
    end;  The code is select out of the database and assigned to a local variable within my pl/sql package. The following code should demonstrate what I'm trying to achieve:
    declare
      l_sql varchar2(32767);
      l_value varchar2(32767);
    begin
      select query_sql into l_sql from lov where lov_id = 100;
      execute immediate l_sql using out :l_value;
      dbms_output.put_line(l_value);
    end;However Oracle (10.2.0.2) seems to be doing something funny with the single quotes. and gives the following error:
    ORA-06550: line 1, column 1:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare exit for function goto if loop mod null
       package pragma procedure raise return select separate type
       update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       form table call close current define delete fetch lock insert
       open rollback savepoint set sql execute commit forall merge
       library OPERATOR_ pipe
    errorIf I embed the code I'm trying to execute within the package i.e
    declare
      l_sql varchar2(32767);
      l_value varchar2(32767);
    begin
      l_sql := q'~declare
        l_my_val varchar2(32767);
                cursor c_activity is
                SELECT
                      l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description,  '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
                FROM   ACTIVITY a
                      ,MOUNTAINEERING m
                      ,LOV l
                      ,LOV l2
                WHERE  a.JSATFA_ID = 82
                AND    a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
                AND    m.ACTIVITY_ID(+) = a.ACTIVITY_ID
                AND    m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
    begin
    for each_row in c_activity loop
      l_my_val := l_my_val ||  ', ' || each_row.value1;
    end loop;
    :l_value := ltrim (l_my_val, ', ');
    end; 
      ~';
      execute immediate l_sql using out :l_value;
      dbms_output.put_line(l_value);
    end;It works perfectly. Notice I have used the q syntax when embedding the sql directly into the package.
    I have tried
    - appending the q syntax directly to query_sql stored in the database
    - escaping the quotes i.e. ' become ''
    Neither method seem to work. We are running 10.2.0.2 on Windows Server 2003. If anyone has any suggestions I would love to hear from you as this has me stumped.
    Regards
    Kris
    - http://kristianjones.blogspot.com

    If you do:
    declare
    l_sql varchar2(32767);
    l_value varchar2(32767);
    begin
    select query_sql into l_sql from lov where lov_id = 100;
    dbms_output.put_line(l_sql);
    end;
    You'll see something like that:
    SELECT
    l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description, '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
    FROM ACTIVITY a
    ,MOUNTAINEERING m
    ,LOV l
    ,LOV l2
    WHERE a.JSATFA_ID = 82
    AND a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
    AND m.ACTIVITY_ID(+) = a.ACTIVITY_ID
    AND m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
    you need to duplicate the '
    you can do many things like:
    CTH@> select * from sqls;
    C
    select first_name || ' ' || last_name as value1 from employees where rownum=1
    1 fila seleccionada.
    CTH@>
    CTH@> ;
    1 declare
    2 l_sql varchar2(32767);
    3 l_value varchar2(32767);
    4 type generic_cursor is ref cursor;
    5
    6 c generic_cursor;
    7
    8 begin
    9 select replace(c, ''', ''''') into l_sql from sqls;
    10
    11 execute immediate l_sql into l_value;
    12 dbms_output.put_line(l_value);
    13* end;
    CTH@> /
    Ellen Abel
    Procedimiento PL/SQL terminado correctamente.
    CTH@>

  • How do I return two values from a stored procedure into an "Execute SQL Task" within SQL Server 2008 R2

    Hi,
    How do I return two values from a
    stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
    Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
    Something like ?
    CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
    @intPeriod INT,
    @strPeriod_Length NVARCHAR(1),
    @dtStart NVARCHAR(8) OUTPUT,
    @dtEnd NVARCHAR(8) OUTPUT
    AS
    then within the SSIS component; -
    Kind Regards,
    Kieran. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
    Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
    Add a script task to check ssis variables values using,
    Msgbox(Dts.Variables("User::strExtractStartDate").Value)
    Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
    Regards, RSingh

  • How to run a pl/sql stored procedure as a concurrent program

    Hi All,
    I created a package PURGE_DEAL_REQUESTS. It contains a procedure QPR_DELETE_CANCELLED_REQUESTS. I want to run this stored procedure as concurrent program in ebs suite....
    Can anyone tell me how to run this procedure as a concurrent program(in ebs suite).....?
    Thanks
    Swathi.

    You need to add the concurrent program to the group of the responsibility that will run the report. For more details, please refer to:
    Note: 73492.1 - Creating a PL/SQL Concurrent Program in Oracle Applications
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=73492.1
    Note: 133991.1 - How to Register a Custom Report
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=133991.1

  • Plan Table for running SQL..

    Hi There,
    How can I go through the explain plan for a SQL query running by a particular user?
    For example:
    User A is running: select * from table x , table y where x.id = y.id;
    User B login and can do explain plan on the query running above to get the total cost..etc.
    Thanks

    user5545873 wrote:
    More specifically, I want to know how to connect the session id SID and the SQL_ID (we can get both from v$session_longops) with the v$sql_plan.. or plan_table.
    THanks
    Edited by: user5545873 on Oct 2, 2009 12:10 PMhoek's idea of using Oracle trace and tkprof generating execution plans should work.
    Aside from that, you might be able to trace through the V$ tables to get the info you are looking for. I personally find the V$ tables to be a bit erratic regarding what is there and what is not so you may or may not find everything you are looking for.
    Are you asking for join columns?
    Table                     Column          Datatype     Join Column
    v$session_longops     sql_id             varchar2(13)    v$sql.sql_id
                            sql_address     raw(8)             v$sql.address
                            sql_hash_value     number             v$sql.hash_value
    v$sql_plan             address             raw(8)          v$sql.address
                         child_address     raw(8)             v$sql.child_address
                         child_number     number             v$sql.child_number
                         hash_value     number             v$sql.hash_value

  • Winsock error when running SQL Server Stored Proc

    I have a SQL Server stored procedure that is trying to read emails from an IMAP server (I am using mail.dll from www.limilabs.com).
    The SP works fine on my local computer/db, and the code also runs fine when run from a console application on my remote server. When I try to run it from SQL Server however I get this error message:
    Msg 6522, Level 16, State 1, Procedure GetEmails, Line 0A .NET Framework error occurred during execution of user-defined routine or aggregate "GetEmails": Limilabs.Client.ServerException: The requested name is valid, but no data of the requested type was found ---> System.Net.Sockets.SocketException: The requested name is valid, but no data of the requested type was foundSystem.Net.Sockets.SocketException:    at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)   at System.Net.Sockets.Socket.Connect(String host, Int32 port)   at Limilabs.Client.ClientBase.Connect(String host, Int32 port, Boolean useSSL)Limilabs.Client.ServerException:    at Limilabs.Client.ClientBase.Connect(String host, Int32 port, Boolean useSSL)   at StoredProcedures.GetEmails()
    I suspect it is something to do with permissions (??) but it is beyond my knowledge of SQL Server. Anyone have some pointers? I am using the IP for the IMAP server, I have switched off the firewall.
    Thanks

    Reading emails in a stored procedure? Hm...
    Unless you are impersonating the actual user in your CLR procedure, the access will be under the service account for SQL Server. If this is Local Servic or similar and may not have the permission or configuration to access whatever System.Net.Dns.InternalGetHostByName
    is trying to access.
    Try running SQL Server under a domain account to see what happens.
    Erland Sommarskog, SQL Server MVP, [email protected]

Maybe you are looking for

  • Loop-aes/mount with gpg-agent

    Hey, this is not really an Arch related problem, but as this is the only forum I'm using, I'll try it here. The system I'm testing on is Debian etch. loop-aes and gpg-agent alone work fine, when I decrypt data with gpg, pinentry is called and gpg-age

  • Why can't I select "Extract Assets" in my PSD?

    Hello, For whatever reason, I cannot select "Extract Assets" in the right-click menu of layers. I've done this before several times with success, so I'm not sure what's going on here. I've rasterized the layer types & styles. The extract assets optio

  • Can i use this as icloud storage?

    I have my time capsule and I was told I can use as i cloud storage to store data anywhere I travel?

  • Lines when printing

    Help, when i print from my Officejet Pro L7680 All-in-one, lines go through my printed pages.  Why?  Do I have to change the printer heads or is it something more?

  • Total device has been out for 3 days now!

    Have been lied to about 6 different times that our service would be fixed!I've been a LOYAL Comcast customer for over 40 years! I needed my VERIZON phone to make all my calls on even get ahold of my 95 year old mother who lives alone to check on her