Passing value as a parameter in select statement

Hi,
Very simple query, how do I pass the values that i get in the cursor to a select statement. If table1 values are 1,2,3,4 etc , each time the cursor goes through , I will get one value in the variable - Offer
So I want to pass that value to the select statement.. how do i do it?
the one below does not work.
drop table L1;
create table L1
(col1 varchar(300) null) ;
insert into L1 (col1)
select filter_name from table1 ;
SET SERVEROUTPUT ON;
DECLARE
offer table1.col1%TYPE;
factor INTEGER := 0;
CURSOR c1 IS
SELECT col1 FROM table1;
BEGIN
OPEN c1; -- PL/SQL evaluates factor
LOOP
FETCH c1 INTO offer;
EXIT WHEN c1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(offer);
select * from table1 f where f.filter_name =:offer ;
factor := factor + 1;
DBMS_OUTPUT.PUT_LINE(factor);
END LOOP;
CLOSE c1;
END;

Hi Greg,
Thanks for the response, No there is no ODB.net involved here.
If I remove the : from :offer. I get this error now.
Changed SQL is:
select * from table1 f where f.filter_name =offer ;
Error report:
ORA-06550: line 16, column 23:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 16, column 9:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Pass table name as parameter in prepared Statement

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

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

  • Lexical parameter in select statement showing null or column name in xml tag instead of value

    Hi,
    i am using lexical parameter in report select statement as
    Select &order value from oe_order_headers_all a where order_number ='7889'
    and setting  : order:='a.order_number';  in after parameter form trigger.
    lexical parameter intial value set to null
    when i run this report , its not showing order number in output ,its showing null or a.order_number as text.
    Please help.

    try this
    Select &order data_show
    from oe_order_headers_all
    where order_number ='7889'
    and setting  :order:='order_number';  in after parameter form trigger.
    Hope this helps
    Hamid

  • Passing parameter into select statement by using function in discoverer

    I have created two functions in database named Period_in and Period_out and a global variable  g_period_name
    I have called Period_out function in VIEW(Select statement where condition).
    I have registered Period_in function in discoverer admin then created calculation (called Period_in(:input parameter))in discoverer plus.
    My expectation is user will enter period name and that will hit Period_in function and returns 1 and stores entered period name in g_period_name at runtime. then VIEW will executed and fetches data.
    But i am getting no data found.
    Problem is 2 functions running at the same time in select statement. Please help me to overcome this. Thanks in advance
    FUNCTION period_in (p_period VARCHAR2)
          RETURN NUMBER
       AS
       BEGIN
          g_period_name := p_period;
          RETURN 1;
       END period_in;
       FUNCTION period_out
          RETURN VARCHAR2
       AS
       BEGIN
          RETURN g_period_name;
       END period_out;

    You can use this code: 
    WITH cte
    AS ( SELECT EmpID ,
    EmpName ,
    [dbo].[udf_testFunction](EmpID) AS testfunctionvalue
    FROM #Temp
    SELECT EmpID ,
    EmpName ,
    testfunctionvalue ,
    testfunctionvalue * EmpID ,
    testfunctionvalue + 2
    FROM cte
    But using scalar functions in select clause can hurt the performance. Please see this link: 
    SQL Server Scalar User Defined Function Performance
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

  • Dynamic Parameter LOV Select Statement

    I have a parameter form with a value for the fiscal year and equipment ID. I want to populate the equipment ID list of values based on the fiscal year that is selected.
    My query for the equipment ID list of values would be SELECT EQPID,NAME FROM EQPLIST WHERE FY = :FY.
    When I tried to add this query to the list of values of the equipment ID parameter I get REP-0781: Bind variables are not allowed in the Select statement.
    Is there a way to dynamically generate the list of values select statement in a reports trigger?

    Hi,
    What version of Oracle Reports are you using?
    Unfortunately, it is a limitation of Oracle Reports to not restrict values based on other parameters - for sure until Reports 6i and I believe until the recent new versions.
    The other way to do what you want to do is to do it outside of Reports, if you have an Oracle Forms application. For example, you can create a simple Oracle Form that captures the Report parameters and then submits the report from the Forms. In Forms, you can implement the solution you are looking for - restricting values based on values of other parameters. In reports, you can't do that.
    If you have a few other reports that have similar requirements, then you can create a form to launch reports and submit all your reports from there after capturing all your parameters there.
    Venkat

  • How to get all values from an interval using select statement

    Hi,
    Is it possible to write a select statement that returns all values from an interval? Interval boundaries are variable.
    something like this:
    select (for x in 1,1024 loop x end loop) from dual
    (this, of course, doesn't work)
    The result in this example should be 1024 rows of numbers from 1 to 1024. These numbers are parameters, so it is not possible to create a table with predefined values.
    Thanks in advance for your help,
    Mia.

    For your simple case, with a lower boundary of 1, you can use:
    SELECT rownum
    FROM all_objects
    WHERE rownum <= 1024For a set of number between say 50 - 100, you can use something like:
    SELECT rownum + (50 - 1)
    FROM all_objects
    WHERE rownum <= (100 - 50 + 1)Note, that all_objects was used only because it generally has a lot of rows. Any table with at least the number of rows in your range will work.
    TTFN
    John

  • Retrieving multiple values from one column in SELECT statement

    Hi,
    I have a slight dilemma in that I'm trying to pull down all the values from a column from a select statement that includes some JOINS in it.
    If I run the query at the SQL Plus prompt, it pulls back all the values/rows.
    When I run the select (and prepared ) statement in my JSP, it only pulls back one of the 4 values I'm trying to retrieve.
    e.g.
    at the DB level :
    SELECT role_name, CC_ID FROM votetbl a
    INNER JOIN APPROVERS b ON
    a.BUSVP = b.BUSVP AND
    a.BRANCH = b.BRANCH
    WHERE CC_ID = 1688this will return:
    ROLE_NAME CC_ID
    ops 1688
    ops 1688
    comply 1688
    legal 1688
    comply 1688
    When run in my JSP, like so:
    String primID3a = request.getParameter("primID");
    Statement stmtovoter = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    String prepvotSQL = "SELECT role_name, CC_ID FROM votetbl a INNER JOIN APPROVERS b ON a.BUSVP = b.BUSVP AND " +
                         "a.BRANCH = b.BRANCH WHERE CC_ID = ?";
    PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
    prepvotstmt.setString(1, primID3a);
    ResultSet rest3 = prepvotstmt.executeQuery();
    rest3.next();
    String votecat = rest3.getString(1);
    out.println("Vote category: "+votecat);I only get ops returned.
    Do I need to run an enumerator? Or reqest.getParameterValues or use a while statement around the results set?
    Any feedback and direction here is welcomed!
    Thanks!

    Actually, I tried looping and still only get 1, but returned several times.
    i.e.
    PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
    prepvotstmt.setString(1, primID3a);
    ResultSet rest3 = prepvotstmt.executeQuery();
    rest3.next();
    String votecat = rest3.getString(1);
    while (rest3.next()) {
    out.print("category roles "+votecat);
    }then I get returned the following:
    admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admin
    like so.
    Where as at the DB level I get
    ROLE_NAME CC_ID
    admin 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    risk 1688
    comply 1688
    legal 1688
    legal 1688
    ops 1688
    comply 1688
    Maybe the while should go around the getString(1) designation? But I was thinking I'd tried that and gotten invalid cursor error
    Something is definitely amiss, between the prepared statement in the servlet and the SELECT statement at the DB level.
    I can totally hardcode the statement in the servlet or JSP and it will return one value potentially several times, but only one.
    Other times, it will not return a value at all, even though one resides in the db.
    Yet go to the DB/SQL Plus prompt and it returns perfectly. I can simply copy and paste the SELECT statement from the out.print line I made and it works like a champ in SQL Plus. Any ideas why the same exact thing cannot return the proper values within the servlet/JSP?
    Yeeeeeeesh!!! : (
    Message was edited by:
    bpropes20

  • How to use bind variable value for table name in select statement.

    Hi everyone,
    I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
    :p37_table_name or v('p37_table_name) but none worked.
    Following is the sql for interactive report:
    select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
    to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
    I am setting value of p37_table_name in previous page which is atm_state_day_insp.
    Following is error msg:
    "Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
    Any help would be higly appreciated.
    Raj

    Interestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)

  • Use lexical parameter in select statement

    Hi,
    I have a report like below:
    select d.dname, &par1 mgrSal, &par2 empSal from emp e, dept d where d.deptno=e.deptno
    and d.deptno = :dno;
    Here the &par1 and &par2 are calling a function like:
    :par1 := ' f(:dno, :job)';
    in the after parameter form. the function returns a number ( something like count(*) or max(sal) ).
    Now the reports server (6i) generats error message:
    inlalid column or miss expression.
    What is the right way for this kind of report? Please help me.
    Any help is greatly appreciated.

    Hi,
    I have a report like below:
    select d.dname, &par1 mgrSal, &par2 empSal from emp e, dept d where d.deptno=e.deptno
    and d.deptno = :dno;
    Here the &par1 and &par2 are calling a function like:
    :par1 := ' f(:dno, :job)';
    in the after parameter form. the function returns a number ( something like count(*) or max(sal) ).
    Now the reports server (6i) generats error message:
    inlalid column or miss expression.
    What is the right way for this kind of report? Please help me.
    Any help is greatly appreciated.
    Try debugging it in the same good old way.
    What you have stated seems to have no problem
    but you never know. So In the after param form see whether it is actually setting a value to your parameter.
    If that is Ok I dont think you should have problems.
    But there are two things which look odd here. since the Parameter value is not changing after the after param form why do you need it in the query?
    Second If you are trying to display the departments thier emp count and max salary I think You can use straight selects than anyhting else.
    Try doing it
    vij

  • Passing value to internal parameter of subreport

    I have a report which contains a subreport. That subreport has 2 regular parameters and 1 internal parameter (which has default value).
    From what I've read ( http://msdn.microsoft.com/en-us/library/aa337490(v=sql.90).aspx ) I understand that there's no need to pass a value from the parent report to the subreport
    for internal parameters.
    All runs fine in VS (2005) and also fine after deploying to SSRS 2005. But when I deploy to SSRS 2008R2, I get "error subreport could not be shown" for that subreport.
    If I do pass that internal report (it DOES show in the chooslist from the parent report) then I get error "error subreport could not be shown" both in VS and in the reporting site. So I can't find any way to display it in SSRS 2008.
    Your advice appreciated.
    Namnami

    The report doesn't know whether it is a report or subreport. In either case, it takes the input and generates an output using the same settings and formulae. If you get a different output when it is run as a subreport, it is because the input is different.
    So I suggest that you display each parameter value of your subreport (or at least those that are passed in by your main report) in a set of text boxes added to the top of the report. Run the report by itself in SSRS 2008 and record the values
    that the report is consuming. Now in the main report, do the same. Display the value of each parameter that you are passing to the subreport in a text box. Look for differences. Remember to display multivalue parameter values in a text box, you will need
    to convert them to a string using Join: =Join(Parameters!Multi.Value,",").

  • Output of value returned from function in SELECT statement ??

    Hi
    I have created the below function
    create or replace
    FUNCTION jc_test
    RETURN VARCHAR2
    IS myrec VARCHAR2(270);
    BEGIN
    SELECT RPAD('*',270,'*')
    INTO myrec
    FROM DUAL ;
    RETURN myrec;
    END ;
    and I executed the SELECT statement in Oracle SQL developer as a script
    select
    LENGTH(jc_test()) len
    *,jc_test() rec*
    from dual ;
    I get exact output as below
    LEN REC
    270 ******************************************************************************************************************************************************************************************************************************************************************************
    So here LEN is correctly shown as 270 characters but when I see the astrisk's (also appended with spaces ) its total length is 4000 characters
    Can anyone give their thoughts on this.
    Its fine if I run as normal, i mean not as a script.
    Regards
    jc
    Edited by: JC on Jun 16, 2011 11:25 AM

    Hi,
    So here LEN is correctly shown as 270 charactersYes, correct
    but when I see the astrisk's (also appended with spaces ) its total length is 4000 charactersNo buts. It is not padded. That is just how it is displayed by your tool. In SQL*Plus this is controlled by LINESIZE and COLUMN
    SQL> create or replace function dummy return varchar2 as begin return null; end;
      2  /
    Function created.
    SQL> select dummy from dual;
    D
    X
    SQL> select dummy() from dual;
    DUMMY()
    SQL> col "dummy()" for a10
    SQL> select dummy() from dual;
    DUMMY()
    SQL>P.S: It is a really bad idea to create your own wrapper functions, built-in functions. Hopefully you are not really doing that?
    Regards
    Peter

  • Get values in 1 parameter by selecting values from 2 param at selection scr

    Hi all
    Please help me out in getting values at selection screen .
    as, i am using a search help in one parameter field of selection screen and by selecting one value from their i want that corresponding values should come in the second parameter .
    specificaly I have a parameter field (PERNR) , i attached one search help with this field through match code statement using table (pa0001) .
    i have one more parameter field at selection screen - Designation , which is of type PSTXT of text table T528T with respect to PLANS for particular employee .
    i want that when i select particular pernr using search help , their corresponding designation will display on the selection screen .
    Please guide me how to solve it .
    Thanks & Regards

    Hi,
    There are two options.
    Create your own search help with these TWO as EXPORT paramters and then
    create a strucutre with these two fields or select one which is already there and then make Search help assignment at the strucutre level and then map the EXPORT paramters of search help to Strucutre fields, then if you select PERNR you will automatically get the Designation.
    Else what you can do is
    Create AT SELECTION-SCREEN ON VALUE-REQUEST FOR pernr.
    In this event code in such a way that once you select your pernr using this you make a query to get the Designation and then assign the value to the Designation field.
    Regards,
    Sesh

  • How to catch BCD_OVERFLOW error when passing value to formal parameter?

    Hi,
    catching runtime error BCD_OVERFLOW exception is simple. However, it's not possible to catch this error directly, if it results from assigning too big value to the formal parameter.
    Let's assume simple code with local class lcl_calculator implementing functional method add with two input parameters i_op1 and i_op2 both of type i and result value r_result of type i as well.
    The following code dumps, without the exception being caught:
    DATA:
       lo_calculator TYPE REF TO lcl_calculator,
       l_result TYPE i.
    START-OF-SELECTION.
       TRY.
           CREATE OBJECT lo_calculator.
           l_result = lo_calculator->add(
             i_op1 = 10000000000
             i_op2 = 1 ).
           WRITE:/ l_result.
         CATCH cx_sy_conversion_overflow.
           WRITE:/ 'Error'.
       ENDTRY.
    To solve this, the workaround has to be implemented with checking the values being passed to the method before the actual call is made:
    DATA:
       lo_calculator TYPE REF TO lcl_calculator,
       l_result TYPE i,
       l_op1 TYPE i,
       l_op2 TYPE i.
    START-OF-SELECTION.
       TRY.
           l_op1 = 10000000000.
           l_op2 = 1.      
           CREATE OBJECT lo_calculator.
           l_result = lo_calculator->add(
             i_op1 = l_op1
             i_op2 = l_op2 ).
           WRITE:/ l_result.
         CATCH cx_sy_conversion_overflow.
           WRITE:/ 'Error'.
       ENDTRY.
    It's the same with the function module call, so it's general unit interface issue. Also, using the exception handling related to the CALL METHOD command does not help here as it's not wrong parameter TYPING which causes the error. It's the VALUE of correctly typed parameter that causes the error.
    The CATCH apparently reacts different ways when the assignment is made to the variable and to the formal parameter of the unit. Any idea how to solve the above without using that workaround?
    Thank you
    Michal

    What about using numeric?
    CLASS lcl_calculator DEFINITION.
       PUBLIC SECTION.
         METHODS add IMPORTING i_op1 TYPE numeric i_op2 TYPE numeric RETURNING value(r_sum) TYPE i
                      RAISING cx_sy_conversion_overflow.
    ENDCLASS.                    "lcl_calculator DEFINITION
    CLASS lcl_calculator IMPLEMENTATION.
       METHOD add.
         TRY.
             r_sum = i_op1 + i_op2.
           CATCH cx_sy_arithmetic_overflow.
             RAISE EXCEPTION TYPE cx_sy_conversion_overflow.
         ENDTRY.
       ENDMETHOD.                    "add
    ENDCLASS.                    "lcl_calculator IMPLEMENTATION
    DATA:
        lo_calculator TYPE REF TO lcl_calculator,
        l_result TYPE i.
    START-OF-SELECTION.
       TRY.
           CREATE OBJECT lo_calculator.
           l_result = lo_calculator->add(
             i_op1 = 10000000000
             i_op2 = 1 ).
           WRITE:/ l_result.
         CATCH cx_sy_conversion_overflow.
           WRITE:/ 'Error'.
       ENDTRY.

  • Sending Package as Parameter into SELECT Statement

    Hi,
    Im Facing a very typical Problem
    I have a table with 5 columns...
    Select EMPNO,ENAME,SAL,JOB,DEPTNO from emp;
    Now my package actually returns 30 records
    select * from TABLE(PKG_SEARCH.DOC_PROPERTY(29)
    which actually returns 7 columns with 30 records...
    My requirement is -
    i want the package to be sent as column to the Select EMPNO,ENAME,SAL,JOB,DEPTNO from emp;
    Is there any way that we can create bind variables for this scenario?
    Plz Help
    Regards,
    ~ Sri

    i want the package to be sent as column to the Select EMPNO,ENAME,SAL,JOB,DEPTNO from emp;Why not
    Select EMPNO,ENAME,SAL,JOB,DEPTNO, PKG_SEARCH.DOC_PROPERTY(29) doc_property from emp;?

  • How to pass value to select-option parameter using SET PARAMETER Command

    Hi,
        Am passing values to selection-screen fields in report RV13A004 ( used in VK11, VK12 and VK13). using below statement but material number is select-option in this report. am able to pass  MATERIAL FROM using SET PARAMETER ID, can i know how to pass values MATERIAL TO range in select-options fields using SET PARAMETER Command ??
    Passing values to parameter id
    set parameter id 'VKS' field kschl.
    set parameter id 'VKO' field vkorg.
    set parameter id 'VTW' field vtweg.
    set parameter id 'KDA' field erdat.
    set parameter id 'MAT' field matnr_from.
    Change condition price.
    call transaction 'VK12' and skip first screen.
    Thanks in advance.
    Regards,
    Balamurugan.

    Hi,
    instead of using set parameters and dden call transaction use this..........
    submit RV13A004  WITH SELECTION-TABLE rspar
    Effect
    If you specify this addition, parameters and selection criteria on the selection screen are supplied from an internal table rspar. You must specify an internal table with the row type RSPARAMS for rspar. The structured data type RSPARAMS is defined in the ABAP Dictionary and has the following components, all of which are data type CHAR:
    SELNAME (length 8),
    KIND (length 1),
    SIGN (length 1),
    OPTION (length 2),
    LOW (length 45),
    HIGH (length 45).
    To supply parameters and selection criteria for the selection screen with specific values, the lines in the internal table rspar must contain the following values:
    SELNAME must contain the name of a parameter or selection criterion for the selection screen in block capitals
    KIND must contain the type of selection screen component (P for parameters, S for selection criteria)
    SIGN, OPTION, LOW, and HIGH must contain the values specified for the selection table columns that have the same names as the selection criteria; in the case of parameters, the value must be specified in LOW and all other components are ignored.
    If the name of a selection criterion is repeated in rspar, this defines a selection table containing several lines and passes it on to the selection criterion. If parameter names occur several times, the last value is passed on to the parameter.
    The contents of the parameters or selection tables for the current program can be entered in the table by the function module RS_REFRESH_FROM_SELECTOPTIONS.
    Notes
    In contrast to selection tables, the data types of the components LOW and HIGH in table rspar are always of type CHAR and are converted to the type of the parameter or selection criterion during transfer, if necessary.
    When entering values, you must ensure that these are entered in the internal format of the ABAP values, and not in the output format of the screen display.
    Cheers
    Will.

Maybe you are looking for