Using dynamic value in procedure on column

I want a PL/sql procedure to select the data from the column dynamically into a variable .
My friend suggested its not possible in PL/sql ,its only possible in sql .
What i want is when i execute the PL/sql procedure the a_1 must get the value of the data in the table,i do not want to use execute immediate in pl/sql.
I create a table A
create table A (a1 number,a2 number,a3 number);
insert into a values (1,2,3);
then i create a procedure
create or replace
procedure test_a (var IN number)
as
a_1 number;
i number;
z varchar2(5);
begin
if var=1
then
i:=1;
elsif var = 2
then
i:=2;
z:='A2';
end if;
SELECT 'a'||i into a_1 from a;
end;
Edited by: user536416 on May 13, 2010 4:03 AM

I prefer reference cursors over execute immediate if I must do dynamic SQL (and have learned not to do it unless necessary - among other things dynamic SQL is hard to debug and maintain).
The advantages to ref cursors are
* execute immedate will only retrieve one row, ref cursors as many as you want
* easier for me to build the query first, then execute it (though you can do this with execute immediate too) for debugging
You can buiid the query dynamcially but have to be careful to make sure the select list matches the INTO clause on the fetch statements. Although the queries in the example below are hard coded I could have done something like
  v_command_c := 'select '||var1||', '||var2||' from '''||table_name||'''';
  open refcur for v_command_c;To randomize your column selection use something like the above with IF logic and a randomizer, possibly the DBMS_RANDOM package or a time extraction.
Something like
SET SCAN OFF
SET SERVEROUTPUT ON
DECLARE
  --define composite data types
  --reference cursor type - structure
  TYPE RefCursorType   IS REF CURSOR;
  --collection (index-by table) type - structure
  TYPE TablesTableType IS TABLE OF user_tables.table_name%TYPE
    INDEX BY BINARY_INTEGER;
  --define ref cursors to be used in BEGIN section
  UserTablesCursor RefCursorType;
  UserViewCursor   RefCursorType;
  --define actual index-by tables to be used in BEGIN section
  NamesTable TablesTableType;
  ViewsTable TablesTableType;
  --define internal procedures to be used in this script
  PROCEDURE ListItems(RefCursor IN RefCursorType,
    DataTable IN OUT TablesTableType
    ) IS
    Counter   INTEGER := 1;
    TableName user_tables.table_name%TYPE;
  BEGIN
    FETCH RefCursor INTO DataTable(Counter);
    Counter := Counter + 1;
    WHILE RefCursor%FOUND LOOP
      FETCH RefCursor INTO DataTable(Counter);
      Counter := Counter + 1;
    END LOOP;
  END; --ListItems;
  PROCEDURE WriteItems(DataTable IN TablesTableType) IS
  BEGIN
    FOR i IN 1..DataTable.count LOOP
      dbms_output.put_line(DataTable(i));
    END LOOP;
  END; --WriteItems;
BEGIN
  OPEN UserTablesCursor FOR
    SELECT table_name
      FROM user_tables;
  ListItems(UserTablesCursor,NamesTable);
  CLOSE UserTablesCursor;
  dbms_output.put_line('user_tables');
  dbms_output.put_line('--------------');
  WriteItems(NamesTable);
  --second defintion & set of calls
  dbms_output.put_Line(CHR(13));
  OPEN UserTablesCursor FOR
    SELECT view_name
      FROM user_views;
  ListItems(UserTablesCursor,ViewsTable);
  CLOSE UserTablesCursor;
  dbms_output.put_line('user_views');
  dbms_output.put_line('--------------');
  WriteItems(ViewsTable);
END;
/Edited by: riedelme on May 13, 2010 5:44 AM

Similar Messages

  • Using dynamic values in the IN clause

    hey guys ,
    is it possible to use dynamic values for comparing in the IN clause while writting query in views, in adf bc .

    Thanks to Jobinesh http://jobinesh.blogspot.com/2010/12/using-oraclejbodomainarray-with.html
    Timo

  • Unable to use Dynamic Calc members on webform Column.

    Hi All,
    I am getting an error 'invalid webform' if i keep a dynamic calc member in webform column. For example if i keep scenario "Variance", a dynamic calc member with a formula "Actual -Budget" on webform column, the form is giving me the error.
    What could be the issue. I am using 11.1.2.1. It is working fine in our old version 9.3.1.
    Many Thanks

    Have you checked the essbase application log as it may be generating an error, could need the cache increasing.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Another question - using dynamic value body tag????

    Can this be done?
    I need to send an ASP dynamic value to my 'open browser
    window' pop up.
    Something like:
    <body
    onload="MM_openBrWindow('subscribe_pop.asp?email="&<%(Recordset1.Fields.Item("emailaddres s").Value)%>','','location=yes,width=400,height=200')">
    Any ideas?
    Thanks
    Andy

    Change what you have to this -
    <body onload="@@(onload)@@">
    The downside to this method is that your popup link WILL NOT
    BE MANAGED. If
    you change the name of the page or the location of the page,
    you will have
    to change the value of this Template parameter, and then save
    it to
    propagate through the site. Then, of course, you will have to
    upload your
    local files again.
    You do know that this popup will be blocked by modern
    browsers, right?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Andy" <[email protected]> wrote in message
    news:[email protected]...
    > Morning Dooza - Sorry it's me again ;-)
    >
    > Well i've part way through this but seem to have created
    another problem.
    > When i used the 'make attribute editable' the code
    generated on the page
    > that launches the pop up was:
    > -----------
    > <!-- InstanceEndEditable --><!--
    InstanceBeginEditable name="head" -->
    > <!-- InstanceEndEditable --><!-- InstanceParam
    name="onload" type="text"
    >
    value="P7_initPM(0,0,1,-20,10);MM_openBrWindow('subscribe_pop.asp?custemail=<%=(Customers RS.Fields.Item("CustomerEmail").Value)%>','','location=yes,width=400,height=200')"
    > -->
    > </head>
    >
    > <body onload="P7_initPM(0,0,1,-20,10)">
    > --------
    >
    > It didn't put the 'MM_openBrWindow' code in the Body
    Tag, only in the
    > 'InstanceParam name'
    > I opened the page up in note pad and added it manually
    and all the code
    > worked as it should.
    >
    > The problem now is that when i change the template, my
    page isn't updated
    > at all.
    >
    > Before i used 'make attribute editable' my Body Tag
    contained just the
    > <body onload="P7_initPM(0,0,1,-20,10)">
    >
    > Any ideas??
    >
    > Thanks
    > Andy
    >
    >
    >
    >
    > "Dooza" <[email protected]> wrote in message
    > news:[email protected]...
    >> Andy wrote:
    >>> Hi Dooza
    >>>
    >>> I'm still not getting the value passed to the
    pop up :-(
    >>>
    >>> I followed the steps below and the page passing
    the email address is
    >>> producing the correct email.
    >>> The subscriber page is still giving the Either
    BOF or EOF is True error.
    >>>
    >>> I tried the subscriber page (local url) using
    subscribe_pop.asp?ID=516
    >>>
    >>> 516 is my email address. The recordset on the
    subscribe_pop.asp page
    >>> pulls the email address based on the ID.
    >>>
    >>> For some reason this code just isn't sending the
    value.
    >>>
    >>>
    >>>
    "P7_initPM(0,0,1,-20,10);MM_openBrWindow('subscribe_pop.asp?ID=<%=(CustomersRS.Fields.Ite m("CustomerEmail").Value)%>','','location=yes,width=400,height=200')"
    >>>
    >>> Really scratching my head now
    >>
    >> When you view the page in your browser that launches
    the pop up, what
    >> does the source look like for the body tag?
    >>
    >> Hang on, your passing the email address as the ID?
    Are you sure you want
    >> to do that? Don't you want to pass the ID? Maybe
    thats where you are
    >> going wrong?
    >>
    >> Dooza
    >> --
    >> Posting Guidelines
    >>
    http://www.adobe.com/support/forums/guidelines.html
    >> How To Ask Smart Questions
    >>
    http://www.catb.org/esr/faqs/smart-questions.html
    >
    >

  • Can I use dynamic alias to name a column?

    I guys. I just want to know if it is possible to assign dynamic names to a column. for instance:
    SQL> select sysdate+1 from dual;
    SYSDATE+1
    09-JUL-08the column name is SYSDATE+1. can I do something like:
    SQL> select 1 as (select sysdate from dual) from dual;(this throws error)
    The reason for this requirement is that I need to assign a column name according to a value that comes from a parameter. So, instead of returning something like:
    SQL> select sysdate, sysdate+1 from dual;
    SYSDATE   SYSDATE+1
    08-JUL-08 09-JUL-08I need to find a way to return something like:
    SQL> select sysdate as <<dynamic column name based on parameter that has been passed in>>, sysdate+1 AS <<dynamic column name based on parameter that has been passed in>> from dual;Obviously I can use something like:
    select sysdate as "08-JUL-08", sysdate+1 AS "09-JUL-08" from dual;But in this case I'm hard coding it. I need this alias to be dynamic.
    Any way to do it?

    Why? Column names are a "programming thing" - not a "display thing".
    When you render the columns, you can decide what and how to display them. It does not make any sense to attempt to do this dynamically.
    Why not?
    Sharable SQL.
    Everytime you create a SQL and dynamically change the column aliases, you create a brand new unique SQL - even if the rest of the SELECT is exactly the same. This means you are stuffing the shared pool full of non-sharable SQL.
    This is bad for performance (lots of hard parsing). It is bad for the shared pool (memory fragmentation).

  • How to use dynamic values for service-ref

    service-ref element allows for static configuration for endpoint reference as follows:
    <copy>
    <from>
    <literal>
    <sref:service-ref xmlns:sref="http://docs.oasis-open.org/wsbpel/2.0/serviceref">
    <EndpointReference xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
    <Address>http://localhost:8080/mockservice</Address>
    </EndpointReference>
    </sref:service-ref>
    </literal>
    </from>
    <to>$serviceref</to>
    </copy>
    I want to change the address value dynamically in service-ref element. How can I achieve it ?

    Hi,
    Why don't you try:
    1. Bpel references
    You can select a BPEL reference property in your composite.xml and use it within your bpel process. This is explained here:
    http://orasoa.blogspot.co.uk/2009/08/soa-11g-preferences.html
    Then you can create a deployment configuration plan. Right-click on the composite file and generate a deployment configuration plan for your composite. This should create a search/replace construction for your preference.
    2. DVM (Data Value Maps)
    You can populate the address by using dvm lookup function. Create a DVM file with two columns, one to specify the Address/URL and populate the other column with the actual value. Use the address as your unique lookup criteria to retrieve the value. This value can be configured per environment.
    Hope this helps.
    Thanks
    Sander

  • RENAME/COPY/DELETE a file using FTP Adapter in 11g using dynamic values

    Hi All
    We have a requirement to do the above for a client. I was able to find a post\blog that tells you to add the below properties in FTP adapter JCA file and it works but,
    <interaction-spec className="oracle.tip.adapter.ftp.outbound.FTPIoInteractionSpec">
    <property name="SourcePhysicalDirectory" value="foo1"/>
    <property name="SourceFileName" value="bar1"/>
    <property name="TargetIsRemote" value="false"/>
    <property name="TargetPhysicalDirectory" value="foo2"/>
    <property name="TargetFileName" value="bar2"/>
    <property name="Type" value="COPY"/>
    </interaction-spec>
    The problem is that how to assign these values dynamically (from xpath or bpel variables etc). Can somebody provide me with some pointers? Its very urgent!

    Use the below approach to set the directory and file names dynamically.
    In BPEL source mode, specify the bpelx:inputProperty. Set the values for these variables in bpel. These can also be accessed as bpel preference values.
    <invoke>
    <bpelx:inputProperty name="jca.ftp.SourceFileName" variable="SourceFileNameVar"/>
    <bpelx:inputProperty name="jca.ftp.TargetFileName" variable="TargetFileNameVar"/>
    </invoke>

  • Assigning a password to PDF, using dynamic value from query

    I have a report that bursts through bi publisher, and i would like to dynamically protect each pdf that is generated by using something that is unique to the report, like an office id from the query. I know how to set a static password from the template properties, and i understand how to use the api if i wanted to write my own routine to run the report, i just dont want to do that. i just want to dynamically set the password, while the job runs inside the bipublisher environment as a scheduled job. can this be done? are there ways to embed java api calls/code in the report and have it run inside bipublisher, instead of having to call a webservice?

    You have to do the same way you do for static password,
    instead of typing the password, you refer an element from xml or concat some elements and form a password.
    {/fromROOT/password}

  • Insufficient privilege while using dynamic sql in procedure

    Hi,
    I am using following script on oracle 10g. and getting unsufficient privs error. please advice.
    SQL> show user
    User is "GRSADM"
    SQL> create or replace procedure grsadm.test_proc as
    a varchar2(2000);
    begin
    a:='CREATE OR REPLACE VIEW
    test_view
    AS SELECT
    ''sadf'' a
    FROM dual';
    execute immediate a;
    end;
    Procedure created.
    SQL> begin
    grsadm.test_proc;
    end;
    begin
    grsadm.test_proc;
    end;
    Error at line 16
    ORA-01031: insufficient privileges
    ORA-06512: at "GRSADM.TEST_PROC", line 9
    ORA-06512: at line 2
    SQL> select * from session_privs
    where privilege like '%VIEW%'
    PRIVILEGE
    CREATE ANY VIEW
    DROP ANY VIEW
    CREATE ANY MATERIALIZED VIEW
    ALTER ANY MATERIALIZED VIEW
    DROP ANY MATERIALIZED VIEW
    5 rows selected.
    Edited by: Ratnesh Sharma on Nov 24, 2011 12:00 PM

    yes it has EXECUTE ANY PROCEDURE priv.
    Following is the list of all the priv this user has.
    PRIVILEGE
    CREATE ANY SQL PROFILE
    DROP ANY SQL PROFILE
    GRANT ANY OBJECT PRIVILEGE
    DEBUG CONNECT SESSION
    RESUMABLE
    ADMINISTER DATABASE TRIGGER
    ADMINISTER RESOURCE MANAGER
    DROP ANY OUTLINE
    DROP ANY CONTEXT
    CREATE ANY CONTEXT
    MANAGE ANY QUEUE
    DROP ANY DIMENSION
    CREATE ANY DIMENSION
    GLOBAL QUERY REWRITE
    DROP ANY INDEXTYPE
    CREATE ANY INDEXTYPE
    DROP ANY OPERATOR
    CREATE ANY OPERATOR
    DROP ANY LIBRARY
    CREATE ANY LIBRARY
    EXECUTE ANY TYPE
    DROP ANY TYPE
    ALTER ANY TYPE
    CREATE ANY TYPE
    DROP ANY DIRECTORY
    CREATE ANY DIRECTORY
    DROP ANY MATERIALIZED VIEW
    ALTER ANY MATERIALIZED VIEW
    CREATE ANY MATERIALIZED VIEW
    ANALYZE ANY
    DROP PROFILE
    CREATE PROFILE
    DROP ANY TRIGGER
    ALTER ANY TRIGGER
    CREATE ANY TRIGGER
    EXECUTE ANY PROCEDURE
    DROP ANY PROCEDURE
    ALTER ANY PROCEDURE
    CREATE ANY PROCEDURE
    CREATE PROCEDURE
    AUDIT ANY
    DROP ANY ROLE
    CREATE ROLE
    DROP PUBLIC DATABASE LINK
    CREATE PUBLIC DATABASE LINK
    CREATE DATABASE LINK
    DROP ANY SEQUENCE
    CREATE ANY SEQUENCE
    DROP ANY VIEW
    CREATE ANY VIEW
    DROP PUBLIC SYNONYM
    CREATE PUBLIC SYNONYM
    DROP ANY SYNONYM
    CREATE ANY SYNONYM
    DROP ANY INDEX
    ALTER ANY INDEX
    CREATE ANY INDEX
    DROP ANY CLUSTER
    CREATE ANY CLUSTER
    DELETE ANY TABLE
    UPDATE ANY TABLE
    INSERT ANY TABLE
    SELECT ANY TABLE
    COMMENT ANY TABLE
    DROP ANY TABLE
    ALTER ANY TABLE
    CREATE ANY TABLE
    DROP ROLLBACK SEGMENT
    CREATE ROLLBACK SEGMENT
    DROP USER
    BECOME USER
    CREATE USER
    UNLIMITED TABLESPACE
    DROP TABLESPACE
    ALTER TABLESPACE
    CREATE TABLESPACE
    CREATE SESSION
    ALTER SYSTEM

  • List of values failure error when trying to use dynamic data values

    Hi there,
    I have a user who is experiencing problems when trying to use dynamic values in a report.  Whenever he tries to insert dynamic parameters he gets the following error message:
    Prompting failed with the following message: 'List of Values failure: Failed to get values.  [Cause of error: Access is denied.]  Error Source: prompt.dll  Error Code: 0x8004380D
    He even opened the sample report - prompting.rpt - that is included with CR and gets the same error.
    We are using Crystal Reports XI Release 2 ver. 11.5.11.1470.
    Any help would be appreciated.

    Please excuse my ignorance of the product.  I've had this problem dropped in my lap and I know practically nothing about Crystal Reports.  In doing some digging it appears to me as if the BusinessObjects Enterprise software may not be installed properly, if at all.  In the programs menu under the BusinessObjects XI Release 2 folder I see a BusinessObjects Enterprise folder, but the only icon listed in that folder is Software Inventory Tool.
    Is the BusinessObjects Enterprise software a separate install from Crystal Reports or is it bundled together?  I talked with the tech that did the install and he said that all he had was the Crystal Reports install media.

  • How to configure dynamic values in survey

    Did anybody use dynamic values in survey? How do we configure dynamic list box with single/multiple selection in survey?
    -hari

    dynamic selections in dropdown listboxes is always coded in the same way :
    - you use method GET_V_xxxx in order to build the value list
    - you use method GET_P_yyyy in order to raise an event when the value is selected (this is useful to refresh values of other lists)

  • How to use dynamically column_name and column_name value in plsql procedure

    hi,
    how to use dynamically column_name and column_name value in plsql procedure.
    for example, i have one table with column col1.i want write plsql code with dynamically execute the insert one schema to another schema.
    by
    siva

    DECLARE
    CURSOR C
    IS
    SELECT cc_cd
    FROM TEMP1 WHERE s_flg ='A' AND b_num IN('826114');--,'709537','715484');
    CURSOR D
    IS
    SELECT * FROM cONSTRAINTS_test ORDER BY SRL_NUM;
    STMT VARCHAR2(4000);
    p_target_schema VARCHAR2(30):='schema1';
    p_source_schema VARCHAR2(30):='schema2';
    BEGIN
    FOR REC IN C
    LOOP
    FOR REC1 IN D
    LOOP
    STMT := 'INSERT INTO '||p_target_schema||''||'.'||''||REC1.CHILD_TABLE||' SELECT * FROM '||p_source_schema||''||'.'||''||REC1.CHILD_TABLE||' where '||REC1.COLUMN_NAME||'='||REC.cntrct_cd||'';
    Dbms_Output.Put_Line('THE VALUE STMT:'||STMT);
    END LOOP;
    END LOOP;
    END;
    cc_cd='434se22442ss3433';
    cc_t_ms is parent table-----------------------pk_cc_cd is primary key
    cc_cd is column name
    CONSTRAINTS_test table
    CHILD_TABLE NOT NULL VARCHAR2(30)
    CONSTRAINT_NAME NOT NULL VARCHAR2(30)
    COLUMN_NAME NOT NULL VARCHAR2(400)
    R_CONSTRAINT_NAME VARCHAR2(30)
    CONSTRAINT_TYPE VARCHAR2(1)
    PARENT_TABLE NOT NULL VARCHAR2(30)
    SRL_NUM NUMBER(4)
    CHILD_TABLE     CONSTRAINT_NAME     COLUMN_NAME     R_CONSTRAINT_NAME     CONSTRAINT_TYPE     PARENT_TABLE     SRL_NUM
    a aaa cc_CD     pk_cc_CD     R     cc_t_MS     1
    bb     bbb      Cc_CD     PK_CC_CD     R     cc_t_MS     2
    bb_v     bb_vsr     S_NUM     PK_S_NUM      R     bb_v      3
    cC_HS_MS     cc_hs_CD     cc_CD     PK_CC_CD     R     cc_t_MS     4
    cC_HS_LNK cc_HIS_LNK_CD     H_CD     PK_HS_HCD     R     cC_hs_ms 5
    cC_D_EMP     cc_d_EMP     Cc_CD     PK_CC_CD      R     cc_t_MS     6
    i want insert schema1 to schema2 with run time of column_name and column value.the column_name and values should dynamically generated
    with refential integrity.is it possible?
    can any please quick solution.its urgent
    by
    siva

  • Get OLD&NEW value of an UPDATED column selected dynamically in a Trigger

    Hi All,
    I am writting a trigger which take column name dynamically. And on the basis of that column it should give me old value as well as updated value of a column corresponding to a modified row.
    OOO_SCHEDULE is my table name;
    Note: This is only for test so I am writting only for update not for insert and delete.
    create or replace trigger "OOO_SCHEDULE_AUDIT"
    BEFORE
    insert or update or delete on "OOO_SCHEDULE"
    for each row
    begin
    DECLARE
    v_username varchar2(30);
    AUDIT_EMP_ID varchar2(30);
    AUDIT_EMP_ID_NEW varchar2(30);
    v_Column_name VARCHAR(30);
    v_stmt1 VARCHAR(40);
    v_stmt2 VARCHAR(40);
    CURSOR C1 is
    select COLUMN_NAME from user_tab_columns where table_name='OOO_SCHEDULE';
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 into v_Column_name;
    EXIT WHEN c1%NOTFOUND;
    v_stmt1:=('OLD.'||v_Column_name);
    v_stmt2:=('NEW.'||v_Column_name);
    AUDIT_EMP_ID:=v_stmt1;
    AUDIT_EMP_ID_NEW:=v_stmt2;
    INSERT INTO TEMPTEST VALUES(v_stmt1);
    INSERT INTO TEMPTEST VALUES(AUDIT_EMP_ID);
    END LOOP;
    CLOSE c1;
    END;
    end;
    Suppose OOO_EMP_NAME is the column name where user made the change.
    If i do like this..
    AUDIT_EMP_ID:=OLD.OOO_EMP_NAME;
    AUDIT_EMP_ID_NEW:=NEW.OOO_EMP_NAME;
    Then it is working fine because I have given column name statically. But I want the column name to be selected dynamically and I am able to do it through cursor. Also I am able to fetch all column names in v_Column_name variable one by one dyanamically for the cursor.
    But by executing these statements
    AUDIT_EMP_ID:=v_stmt1;
    AUDIT_EMP_ID_NEW:=v_stmt2;
    I am getting OLD.OOO_EMP_NAME and NEW.OOO_EMP_NAME rather then old and new values of the updated column.
    Please help me identifying the problem, where I am doing the mistake? What is the correct way to execute these statements? So that I can get old and new values of the column (updated column).
    I have tried it by passing in a procedure also but don't know how to execute this dynamic statement to get the old and new values.
    Thanks,
    Ishrat.

    In the given link, column name has been selected statically. But i want that column name should be selected daynamically throgh loop and then check the
    condition for any update corresponding to that column value. I don't want to write as many if condition as the no. of column name. I just want one if condition for all column namesDon't be lazy. Write all column names into your trigger. Or use a way to create the trigger "dynamically".
    What is the problem that you have with static column names? "I don't want to write many..." is not a problem, but an opinion.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • About creating an AJAX page with DML procedures  using dynamic actions

    About creating an AJAX page with DML procedures in APEX using dynamic actions. Help with limitations.
    I want to share my experience, creating AJAX procedures in APEX 4.0.
    LIMITATIONS
    •     How Can I Hide UPDATE button while I press NEW button. ??
    •     How Can I Hide CREATE button while I’m UPDATING A RECORD. ??
    •     How can I avoid multiple Inserts or Updates. ??
    Here are the steps to create an AJAX Updatable Form using the sample table DEPTS. You can see the demo here: [http://apex.oracle.com/pls/apex/f?p=15488:1]
    1)     Create a blank page
    2)     Add a Report Region for departments (It shows the columns deptno, dname and loc).
    3)     Add an HTML Region and create the elements to edit a Department.
    a.     P1_DEPTNO (Hidden to store PK)
    b.     P1_DNAME (Text Field)
    c.     P1_LOC (Text Field)
    4)     You also have to create a hidden element called P1_ACTION. This will help to trigger dynamic actions to perform DMLs.
    5)     Open Page Attributes and in the HTML Header Section include the following code.
    <script>
         function doSelect(pId){
              $x_Value(‘P1_DEPTNO’,pId);
              $x_Value(‘P1_ACTION’,’SELECT’);
    </script>
    6)     Modify the column DEPTNO in the report, to add column link. In the link text you can use #DEPTNO# , in target you must select ‘URL ‘ and in the URL field write javascript:doSelect(#DEPTNO#);
    7)     Create the following Buttons in the Form Region.
    CANCEL     Redirects to URL: javascript:$x_Value(‘P150_ACTION’,’CANCEL’);
    NEW          Redirects to URL: javascript:$x_Value(‘P150_ACTION’,’NEW’);
    SAVE          Redirects to URL: javascript:$x_Value(‘P150_ACTION’,’UPDATE’);
    CREATE          Redirects to URL: javascript:$x_Value(‘P150_ACTION’,’CREATE’);
    8)     Create the following Dynamic Action to Select a Department
    Name:     Select Dept
    Event:     Change
    Selection Type:     Item(s)
    Item(s):     P1_ACTION
    Condition:     equal to
    Value:     SELECT
    Action:     Execute PL/SQL Code
    PL/SQL Code:     
    SELECT dname, loc
    INTO :P1_DNAME, :P1_LOC
    FROM dept
    WHERE deptno = :P1_DEPTNO;
    Page Items to Submit:     P1_DEPTNO, P1_DNAME, P1_LOC     
    Don’t include any false action and create the Dynamic Action.
    The first limitation, the value of page elements don’t do refresh so I added the following true actions to the dynamic action AFTER Execute PL/SQL Code.
    Action:     Set Value
    Unmark *‘Fire on page load’* and *‘Stop execution on error’*
    Set Type:     PL/SQL Expression
    PL/SQL Expression:     :P1_DNAME
    Page Items to submit:     (none) (leave it blank)
    Affected Elements: Item P1_DNAME
    Action:     Set Value
    Unmark *‘Fire on page load’* and *‘Stop execution on error’*
    Set Type:     PL/SQL Expression
    PL/SQL Expression:     :P1_LOC
    Page Items to submit:     (none) (leave it blank)
    Affected Elements: Item P1_LOC
    These actions allow refresh the items display value.
    9)     Create the following Dynamic Action to Update a Department
    Name:     Update Dept
    Event:     Change
    Selection Type:     Item(s)
    Item(s):     P1_ACTION
    Condition:     equal to
    Value:     CREATE
    Action:     Execute PL/SQL Code
    PL/SQL Code:     
    UPDATE dept SET
    dname = :P1_DNAME,
    loc = :P1_LOC
    WHERE deptno = :P1_DEPTNO;
    Page Items to Submit:     P1_DEPTNO, P1_DNAME, P1_LOC     
    Don’t include any false action and create the Dynamic Action.
    Include the following True Actions BEFORE the Execute PL/SQL Code true Action.
    Action:     Set Value
    Unmark ‘Fire on page load’ and ‘Stop execution on error’
    Set Type:     PL/SQL Expression
    PL/SQL Expression:     :P1_DNAME
    Page Items to submit:     P1_DNAME
    Affected Elements: Item P1_DNAME
    Action:     Set Value
    Unmark *‘Fire on page load’* and *‘Stop execution on error’*
    Set Type:     PL/SQL Expression
    PL/SQL Expression:     :P1_LOC
    Page Items to submit:     P1_LOC
    Affected Elements: Item P1_LOC
    These actions allow refresh the items display value.
    Finally to refresh the Departments report, add the following true action at the end
    Action:     Refresh
    Affected Elements: Region Departments
    10)     Create the following Dynamic Action to Create a Department
    Name:     Create Dept
    Event:     Change
    Selection Type:     Item(s)
    Item(s):     P1_ACTION
    Condition:     equal to
    Value:     CREATE
    Action:     Execute PL/SQL Code
    PL/SQL Code:     
    INSERT INTO dept(deptno,dname,loc)
    VALUES (:P1_DEPTNO,:P1_DNAME,:P1_LOC);
    Page Items to Submit:     P1_DEPTNO, P1_DNAME, P1_LOC     
    Don’t include any false action and create the Dynamic Action.
    Include the following True Actions BEFORE the Execute PL/SQL Code true Action.
    Action:     Set Value
    Unmark *‘Fire on page load’* and *‘Stop execution on error’*
    Set Type:     PL/SQL Function Body
    PL/SQL Function Body:     
    DECLARE
    v_pk NUMBER;
    BEGIN
    SELECT DEPT_SEQ.nextval INTO v_pk FROM DUAL;; -- or any other existing sequence
    RETURN v_pk;
    END;
    Page Items to submit:     P1_DEPTNO
    Affected Elements: Item P1_DEPTNO
    Action:     Set Value
    Unmark *‘Fire on page load’* and *‘Stop execution on error’*
    Set Type:     PL/SQL Expression
    PL/SQL Expression:     :P1_DNAME
    Page Items to submit:     P1_DNAME
    Affected Elements: Item P1_DNAME
    Action:     Set Value
    Unmark ‘Fire on page load’ and ‘Stop execution on error’
    Set Type:     PL/SQL Expression
    PL/SQL Expression:     :P1_LOC
    Page Items to submit:     P1_LOC
    Affected Elements: Item P1_LOC
    These actions allow refresh the items display value.
    Finally to refresh the Departments report, add the following true action at the end
    Action:     Refresh
    Affected Elements: Region Departments
    11)     Create the following Dynamic Action to delete a department
    Name:     Delete Dept
    Event:     Change
    Selection Type:     Item(s)
    Item(s):     P1_ACTION
    Condition:     equal to
    Value:     DELETE
    Action:     Execute PL/SQL Code
    PL/SQL Code:     
    DELETE dept
    WHERE deptno = :P1_DEPTNO;
    Page Items to Submit:     P1_DEPTNO
    Don’t include any false action and create the Dynamic Action.
    Include the following True Actions AFTER the Execute PL/SQL Code true Action.
    Action:     Refresh
    Affected Elements: Region Departments
    Action:     Clear
    Unmark ‘Fire on page load’
    Affected Elements: Items P1_DEPTNO, P1_DNAME, P1_LOC
    12)     Finally Create the following Dynamic Action for the NEW event
    Name:     New Dept
    Event:     Change
    Selection Type:     Item(s)
    Item(s):     P1_ACTION
    Condition:     equal to
    Value:     NEW
    Action:     Clear
    Unmark *‘Fire on page load’*
    Affected Elements: Items P1_DEPTNO, P1_DNAME, P1_LOC

    I need some help to solve this issues
    •     How Can I Hide UPDATE button while I press NEW button. ??
    •     How Can I Hide CREATE button while I’m UPDATING A RECORD. ??
    •     How can I avoid multiple Inserts or Updates. ??

Maybe you are looking for

  • I purchase ringtones on iphone, but they don't show up as purchased in itunes and i can't transfer from iphone to itunes.

    I have an iphone 3 on which i downloaded ringtones, two of which are not showing in itunes.  I now just purchased the iphone 4s.  When I synced the ringtones, those two were of course missing.  How do I get itunes to recognize that I purchased those

  • Error Message when Updating PS6 ?

    When trying to install the recent update for CS6 through the Application Manager (or Creative Cloud) this ends always with the error message U44M1P7. This the 1st time that aPS6 update does not work on my PC. I have Winows 7. Would like to know what

  • Refactoring Behavior Problem?

    I have created 2 applications which are deployed as ADF Jar Libraries. Inside these apps are fragment taskflows which I am using in a master application. When I run the master app, ADF complains that there are 2 references to "view/DataBindings.cpx"

  • Burning a slideshow onto a CD??

    I have created a slideshow on iPhoto complete with music and the Ken Burns effect I like. I would like to burn that very slideshow onto a CD. Should I burn it onto a DVD?? I would actually like to take several separate slideshows (each with their own

  • Unable to use PIC01 transaction for Supersession chain creation

    Dear All, I am trying to create a supersession chain using PIC01 transaction. While entering the transaction, i am getting error as "Transaction Code PIC01 cannot be executed. You are trying to execute the transaction code &1, but it is in a deactiva