Can you pass SQL to a function?

I have the following function:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2) IS
  v_v_val     VARCHAR2(4000);
  v_n_val     NUMBER;
  v_d_val     DATE;
  v_ret       NUMBER;
  c           NUMBER;
  d           NUMBER;
  col_cnt     INTEGER;
  f           BOOLEAN;
  rec_tab     DBMS_SQL.DESC_TAB;
  col_num     NUMBER;
  v_rowcount  NUMBER := 0;
  v_csv          VARCHAR2(32000);
BEGIN
  -- create a cursor
  c := DBMS_SQL.OPEN_CURSOR;
  -- parse the SQL statement into the cursor
  DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
  -- execute the cursor
  d := DBMS_SQL.EXECUTE(c);
  -- Describe the columns returned by the SQL statement
  DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
  -- Bind local return variables to the various columns based on their types
  FOR j in 1..col_cnt
  LOOP
    CASE rec_tab(j).col_type
      WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
      WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);      -- Number
      WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);     -- Date
    ELSE
      DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);  -- Any other type return as varchar2
    END CASE;
  END LOOP;
  -- This part outputs the DATA
  LOOP
    -- Fetch a row of data through the cursor
    v_ret := DBMS_SQL.FETCH_ROWS(c);
    -- Exit when no more rows
    EXIT WHEN v_ret = 0;
    v_rowcount := v_rowcount + 1;
    -- Fetch the value of each column from the row
    FOR j in 1..col_cnt  
    LOOP
      -- Fetch each column into the correct data type based on the description of the column
      CASE rec_tab(j).col_type
        WHEN 1  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                     v_csv:= v_csv||','||v_v_val;
        WHEN 2  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                     v_csv:= v_csv||','||v_n_val;
        WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                     v_csv:= v_csv||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS');
      ELSE
        DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
        DBMS_OUTPUT.PUT_LINE(v_v_val);
      END CASE;     
    END LOOP;
    dbms_output.put_line(substr(v_csv,2));
    v_csv:='';
  END LOOP;
  DBMS_SQL.CLOSE_CURSOR(c);
END;
It allows you to feed in an arbitrary query and have returned a comma-separated set of data. For example:
SQL> exec run_query('select * from scott.emp where deptno = 10');
7782,CLARK,MANAGER,7839,09/06/1981 00:00:00,2450,,10
7839,KING,PRESIDENT,,17/11/1981 00:00:00,5000,,10
7934,MILLER,CLERK,7782,23/01/1982 00:00:00,1300,,10
PL/SQL procedure successfully completed.
SQL> exec run_query('select * from (select * from scott.emp where deptno = 10 order by sal desc) where rownum < 5');
7839,KING,PRESIDENT,,17/11/1981 00:00:00,5000,,10
7782,CLARK,MANAGER,7839,09/06/1981 00:00:00,2450,,10
7934,MILLER,CLERK,7782,23/01/1982 00:00:00,1300,,10
(I'm not saying this is good practice: quite the opposite. But it's a requirement that's been set and I need to know how to meet it, not argue with it).
My question is: the code works when the query submitted to it doesn't include single quotes. As soon as it does, it dies:
SQL> exec run_query('select 'Example', sal from scott.emp where deptno = 10');
BEGIN run_query('select 'Example', sal from scott.emp where deptno = 10'); END;
ERROR at line 1:
ORA-06550: line 1, column 26:
PLS-00103: Encountered the symbol "EXAMPLE" when expecting one of the
following:
) , * & = - + < / > at in is mod remainder not rem =>
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec as between from using || multiset member
submultiset
The symbol ", was inserted before "EXAMPLE" to continue.
I could obviously escape the 'internal' single quotes, but the aim is for end-users to feed in their queries, not have to re-write them with tricky escape sequences!
So the question is: is there a way I can let users feed their SQL into the procedure without having to worry about single quotes that might be in the middle of it?
Again, I realise the risk of SQL injection... but I'd like assistance on the practicalities of quotation characters, not the management of a risk which I'm well aware of (and dealing with outside the procedural code I've shown here).
In other words, even if you think this is the worst idea in the world, I'd still like to know how I could feed 'select 'Example', sal from scott.emp where deptno = 10'to the procedure and have it run correctly.

Well, I'm going to say it's completely the wrong tool for the job simply because I don't know how to write it! Saying 'do it in Java' is like telling a Windows sysadmin 'do it in emacs'... might well be the right, most powerful, comprehensive and safest way of doing something, but if the skillset is foreign, it doesn't get you far!
Well I can understand why that might be your initial reaction.
But the fact is that ALL of your comments apply even more to use of the DBMS_SQL package. That package is not well known by most developers, is not used by most developers and, when it is used, is often misused.
Even if you want to pursue other options why don't you at least take a look at the two concepts involved in a Java Stored Procedure solution.
Here is a simple example from The Java Tutorials that shows how easy it is to execute a query that is contained in a string and iterate the result set.
http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html
Retrieving and Modifying Values from Result Sets
The following method, CoffeesTable.viewTable outputs the contents of the COFFEES tables, and demonstrates the use of ResultSet objects and cursors:
And here is an equally simple example from the Oracle Java Developer's Guide that shows how to write and execute a simple Java Stored Function.
http://docs.oracle.com/cd/B28359_01/java.111/b31225/chfive.htm
Java Stored Procedures Steps
You can run Java stored procedures in the same way as PL/SQL stored procedures. Normally, a call to a Java stored procedure is a result of database manipulation, because it is usually the result of a trigger or SQL DML call. To call a Java stored procedure, you must publish it through a call specification.
Before you can call Java stored procedures, you must load them into Oracle Database instance and publish them to SQL. Loading and publishing are separate tasks. Many Java classes, which are referenced only by other Java classes, are never published.
To load Java stored procedures automatically, you can use the loadjava tool. It loads Java source, class, and resource files into a system-generated database table, and then uses the SQL CREATE JAVA {SOURCE | CLASS | RESOURCE} statement to load the Java files into Oracle Database instance. You can upload Java files from file systems, popular Java IDEs, intranets, or the Internet.
The following steps are involved in creating, loading, and calling Java stored procedures:
  Step 1: Create or Reuse the Java Classes
  Step 2: Load and Resolve the Java Classes
  Step 3: Publish the Java Classes
  Step 4: Call the Stored Procedures
  Step 5: Debug the Stored Procedures, if Necessary
You also didn't mention what you plan to do with the results.
Sql Developer (free from Oracle - http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html) can very easily query arbitrary data and produce a delimited result.
Here is what a simple query would look like:
SELECT /*csv*/ * from SCOTT.EMP;
THAT'S IT!
The data comes back in a grid and the user can save it to a file, open it in Excel or whatever. It doesn't get any simpler than that.
Take a look at this article by Jeff Smith (a moderator of the sql developer forum) that shows what you can easily do
http://www.thatjeffsmith.com/archive/2013/04/sql-developer-preferences-for-delimited-text-exports/
Even if you decide not to use these other options, or decide that are not a good fit, you should always strive to learn about other techniques and where to find info about them. Who knows, one of these days you may need one of them.
Just as important is that other forum readers understand that their are other, IMHO simpler, solutions out there for your problem.

Similar Messages

  • Can you pass a hidden value along with your select option in the form selec

    Can you pass a hidden value along with your select option in the html form select

    Off topic. Locking.

  • Pass SQL into a Function

    Is it possible to pass a SQL into a Function
    DECLARE
       f        sys_refcursor;
       RESULT   NUMBER;
       FUNCTION myfunction (r sys_refcursor)
          RETURN NUMBER
       IS
       BEGIN
          RETURN TO_NUMBER (TO_CHAR (r.dt, 'DD'));
       END;
    BEGIN
       OPEN f FOR
          SELECT SYSDATE dt
            FROM DUAL;
       RESULT := myfunction (f);
       CLOSE f;
    END;

    Yes you are allowed to pass ref cursor but they have to processed the way you processur cursor i.e. OPEN, FETCH, CLOSE.
    See demonostration of working code:
    SQL>DECLARE
      2     f        sys_refcursor;
      3     RESULT   NUMBER;
      4
      5     FUNCTION myfunction (r sys_refcursor)
      6        RETURN NUMBER
      7     IS
      8     v_currDate DATE;
      9
    10     BEGIN
    11        IF r%ISOPEN THEN
    12          FETCH r INTO v_currDate;
    13        END IF;
    14
    15        RETURN TO_NUMBER (TO_CHAR (v_currDate, 'DD'));
    16     END;
    17  BEGIN
    18     OPEN f FOR
    19        SELECT SYSDATE dt
    20          FROM DUAL;
    21
    22     RESULT := myfunction (f);
    23
    24     DBMS_OUTPUT.PUT_LINE('Date : ' || RESULT );
    25
    26     CLOSE f;
    27  END;
    28  /
    Date : 23
    PL/SQL procedure successfully completed.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can you use SQL as a data source for a project in the same way you can in Excel?

    Excel allows you to create a data source that executes a SQL stored procedure, display that data as a table in a spreadsheet and have that data automatically refresh each time you open the spreadsheet. Is it possible to do the same thing in MS Project, displaying
    the data from the stored procedure as a series of tasks?
    Here's what I'm trying to do - I have a stored procedure that pulls task data meeting a specific criteria from all projects in Project Server. We're currently displaying this data as an Excel report. However, the data includes start dates and durations so
    it would be nice to be able to display it as a Gantt Chart. I've played around with creating a Gantt chart in Excel and have been able to do a very basic one, but it doesn’t quite fit our needs.

    No, You can not use sql as a data source for a project.
    You have 3 options to achieve it:
    1. You can create a Sharepoint list with desired column ,fill desired data in that list then you can create a MS project from Sharepoint List.
    2. You can create a SSRS report in which you can display grantt chart Joe has given you that link.
    3. You can write a macro in MPP which will take data from your excel. In excel you will fetch data from your stored procedure. write a schedule which will run every day to update your data or
    create an excel report in which will update automatically and write macro in mpp which will fetch the data then publish it so that it would be available to team members.
    kirtesh

  • Can you pass multiple files to Business Catalyst at the same time?

    I need to pass information from a client. The infromation is split into several files. I can not access the files to combine them to send as one document to BC. Can I send the two files over even though they do not full fill the necessity of all the user information. File 1 is the personal information and has no other details. When this fill crosses over BC accepts with no trouble. When the second file goes across the personal information is not there but the form details are and this file wipesout the DB. Going through debug when the first file executes I see the data on the BC side. When the second file executes the data is all gone. I cannot combine both files to create one document. Files do not have the same number of users so import of file with file helper would not work since it needs to meet certain requirements to process correctly everytime. By combining the two files would give a different number of tabs than what file helper is looking for and by that matter the data may not be in the correct order. Retrieving the data from the file also would not work since I would have to retrieve from both files at the same time and there would be issues if the user does not occur on both files.
    Please help.
    Thank you,
    Carlos

    Wilderness08 wrote:
    To save time with videos that are not critical, can you capture one video to Premiere Pro at the same time you are authoring to Encore a previously captured video?
    The short answer is yes.
    I have just done that and I am happy to report that it worked like a charm.
    I captured from a DVCAM tape via firewire using PPro CS6 while authoring a Blu-ray disk in Encore CS6.
    No frames were lost during capture and my test blu-ray project was completed without a hitch.

  • Can you block the clear history function on safari?

    how do you block the clear history function and is it possible to limit the number of places visited in the history?

    I don't believe that you can "block" the clear history function but you can set the limit for the number of places visited in history.
    I don't know what OS or Safari versions you are using but select the appropriate version of "Safari Enhancer" at the authors website.
    http://www.lordofthecows.com/safari_enhancer.php

  • Can you have more than one function fire from creationComplete?

    I'd like to have several functions fire when I start a particular application.  Is that possible?   Currently I run one function from the creationComplete .
    Thanks.

    You can also do creationComplete="firstFunction();secondFunction()". If you have more than two function calls or you need to call them all together later on I would do something like an init() function.
    creationComplete="init()"
    private function init():void
         firstFunction();
         secondFunction();

  • Can you mix VISA drivers & GPIB functions?

    Can you mix VISA instrument drivers & GPIB I/O functions on the same block diagram? I am using VISA drivers to control a LeCroy LT344L oscilloscope - they are working fine, but I need to perform a query of some specific scope parameters and the VISA drivers cannot provide the exact command that I need. I used the GPIB send and receive for these query commands, but now am getting an error message:
    "Error -1073807265 occured at VISA Write in LCDSO Utility Default Instrument Setup.vi->LCDSO Initialize.vi->ReadMeas.vi Possible reasons: VISA: (Hex 0xBFFF005F) No listeners condition is detected (both NRFD and NDAC are deasserted).
    Is there a possible confict when both these protocols are used together? Thanks fo
    r any help or insight.
    Mike Selecky

    I just want to clarify a few things about mixing VISA and GPIB.
    If all your I/O is done on the diagram with VISA functions and GPIB
    functions, you should be okay. LabVIEW has code that tries to keep the two
    from stomping on each other. You have to know what you're doing--you can't
    have two VIs trying to control the instrument at once, for example.
    This is _not_ true for C-based instrument drivers (aka, VXIPNP,
    including IVI). We have no protection between the VISA calls inside those
    drivers and the builtin functions. If one is in progress and you try to use
    the other, you'll get an error. One way to demonstrate this would be to
    start a GPIB Read (which is asynchronous by default, meaning that LabVIEW
    starts the Read and then looks for other stuff to do),
    then use an
    instrument driver for a device on the same bus. The instrument driver will
    return an error. You just have to be using the same bus--it doesn't matter
    if you use the same device.
    Fortunately, this doesn't come up that often in practice. When needed,
    there are workarounds--e.g., keeping all GPIB I/O in a single thread (at
    least per bus) and using synchronous VISA and GPIB Reads/Writes. Yes, we're
    working on ways to make this less of an issue, but I won't go into details
    yet.
    Brian Powell
    Sr. Group Manager
    LabVIEW R&D
    [email protected]

  • Is there a max number of parameters that can be passed to a C function in test stand v. 1.0.1

    I have had an issue with test stand version 1.0.1 (yes, I know; it's quite old) and calling a C function thru an action step. when I call this function with 18 parameters, it seems to hang. I have called a function with 16 and it seems to work. Is this a limit of the software? I am calling the function from a windows DLL that we've created. When I try to pull the function from the dll into test stand I also get a { error...but I get that in the other function's call and it seems to work fine. Any ideas?

    ok, upon re-reading what I posted I can clearly see your confusion. haha. I think there are two separate issues.
    1) Are there a maximum number of parameters one can use when calling a C function from a DLL? Yes, i'm trying to call a C function from test stand.
    2) when I select the "module" tab, and select which DLL contains my function, the prototype has no information associated with it (by clicking the reload prototype button). I'm not sure why, as I'm using a declspec to send the function information out of the dll, but that's another topic. So I click on the source file tab and point the window to the .cpp of my function (within the DLL's project workspace) and when it begins to parse the file, I get an error about mis-matched curly brackets and if I wish to continue, and skip the rest of the parsing.
    I click "OK" and when I go back to the module tab, I am able to see all my functions, along with the parameters in the drop down menu below. I fill in all the parameters and everything looks ok; no syntax errors, or anything else seemingly suspicious. I then run my test stand code and when I get to the step which calls this function, the system hangs and cannot proceed.
    Any thoughts as to what might cause these issues? 

  • Can you pass an array URL variable

    Hi,
    Doing a form which I want to validate, then re-display with
    error messages and the keyed data still in place should there be
    errors, or go onto a second form if all ok.
    I have tried to use <form
    action="<?=$_SERVER['PHP_SELF']?>" but as the various
    outcomes result in different screens I can't see how to do it
    without having reams of duplicate code - I couldn't make it work
    satisfactorily anyway.
    So I decided to do it in two stages - form (user screen) + a
    separate validation routine which passes validation results back if
    there are errors by calling the first screen but with URL variables
    to trigger process variations or go onto screen 2 if all ok.
    But I'm struggling with this .. two questions:
    i) Ideally I would like to use a session variable to pass
    actual error messages back to screen one in the event of errors but
    if I undertand things correctly (which is by no means certain)
    $S_Session is already an associatve array so it wouldn't be so easy
    to just add a variable number of messages to it and then know what
    you are unpacking elsewhere ... do you know what I mean?
    Perhaps if I give you my second question it may help
    illustrate what I'm going on about in part 1
    ii) The way I have tried to do it is to set it up as an array
    ($ERRORS) in the validation module and then added a text string
    each time I hit a specific error. The hope was that I could then
    send this back via the URL for further process but I'm getting
    syntax problem so maybe this is not possible .... a brief example
    Input Form php:
    $ERRORS = array();
    $ERRORS = $_GET['errors']
    if (sizeof($ERRORS) > 0) {
    echo "<p class=\"val_err_hdr\"> *** Validation
    error(s) - please correct the entries and try again ***
    </p>";
    blah blah
    Validation php:
    $ERRORS=array();
    if(!$loginFoundUser) {
    $ERRORS[] = "This e-mail address entered has already been
    registered on our database - if you have already registered you
    can"; }
    header("Location: input.form.php?errors=$ERRORS");
    When I run this I get a syntax error 'unexpected T_IF' on the
    'sizeof'' function condition.
    Any help much appreciated.

    .oO(patricktr)
    > Doing a form which I want to validate, then re-display
    with error messages and
    >the keyed data still in place should there be errors, or
    go onto a second form
    >if all ok.
    OK, quite common.
    > I have tried to use <form
    action="<?=$_SERVER['PHP_SELF']?>"
    Avoid short open tags, they are unreliable. Use "<?php
    print " instead
    of just "<?=" to be safe and independent from the server
    configuration.
    >but as the
    >various outcomes result in different screens I can't see
    how to do it without
    >having reams of duplicate code - I couldn't make it work
    satisfactorily anyway.
    What's a "screen" in this case? Just another part of the form
    or a
    completely different page?
    > So I decided to do it in two stages - form (user screen)
    + a separate
    >validation routine which passes validation results back
    if there are errors by
    >calling the first screen but with URL variables to
    trigger process variations
    >or go onto screen 2 if all ok.
    Don't use URL parameters in such a form processing scenario.
    Use a
    session instead, that's what they are for. The length of URLs
    is limited
    and there are things you simply don't want to pass between
    pages, but
    keep on the server instead.
    > But I'm struggling with this .. two questions:
    >
    > i) Ideally I would like to use a session variable to
    pass actual error
    >messages back to screen one in the event of errors but if
    I undertand things
    >correctly (which is by no means certain) $S_Session is
    already an associatve
    >array so it wouldn't be so easy to just add a variable
    number of messages to it
    >and then know what you are unpacking elsewhere ... do you
    know what I mean?
    The $_SESSION array itself is strictly associative, the used
    indexes
    must be strings or the serialization of the session data will
    fail.
    But if course you can always do things like this:
    $_SESSION['errors'] = array();
    $_SESSION['errors'][] = 'something went wrong';
    > Perhaps if I give you my second question it may help
    illustrate what I'm going
    >on about in part 1
    > ii) The way I have tried to do it is to set it up as an
    array ($ERRORS) in the
    >validation module and then added a text string each time
    I hit a specific
    >error. The hope was that I could then send this back via
    the URL for further
    >process but I'm getting syntax problem so maybe this is
    not possible .... a
    >brief example ...
    As said above - use the session instead.
    > Input Form php:
    > $ERRORS = array();
    > $ERRORS = $_GET['errors']
    There's a ';' missing at the EOL (this causes the error you
    mentioned
    below).
    Just a naming hint: Variables should not be named all
    uppercase (except
    for the predefined superglobal arrays). Such names should be
    reserved
    for constants. The most common style looks like this:
    myNiceFunction()
    $myNiceVariable
    MY_NICE_CONSTANT
    > if (sizeof($ERRORS) > 0) {
    if (!empty($_SESSION['errors'])) {
    > header("Location: input.form.php?errors=$ERRORS");
    The Location URI must be absolute including scheme and
    hostname. This is
    required by the HTTP spec:
    header("Location:
    http://$_SERVER[HTTP_HOST
    But I'm still not sure why you would need this redirect. The
    entire
    handling of a form (validation, processing) can be done on a
    single
    page. Only if the processing succeeds, you might want to
    redirect to
    some result page.
    Micha

  • Can you pass a session variable in a CFC bind?

    I have a page (dsp_compReqSCM.cfm) that (via a session variable) displays an application value.  From this page (via a CFFORM) I would like to have that session variable passed along to a cfc(getDistinct.cfc).  I can't quite get the syntax correct and am hoping to get some assistance.  When I code #session.this_appl# in dsp_ReqComps.cfm, I get an error stating Element not found PTS (which is the value of session.this_appl) and that the bind cannot occur.  If I pass session.this_appl (NO ##) in dsp_ReqComps.cfm, I get an error stating Element not found session and that the bind cannot occur.   If I pass 'session.this_appl' or "session.this_appl" in dsp_ReqComps.cfm, I get an error stating Element not found 'session (or "session) and that the bind cannot occur.
    dsp_compReqSCM.cfm calls dsp_ReqComps.cfm via cfform
    <!---dsp_ReqComps.cfm--->
    <cfwindow initshow="true" center="true" width="430" height="340">
    <cfform>
         <cfgrid name="componentsGrid"
                 format="html"
                 pagesize=10
                 striperows="yes"
                 bind="cfc:distinctComponents.getDistinct({cfgridpage},{cfgridpagesize},{cfgridsortcolumn} ,{cfgridsortdirection},#session.this_appl#})"
                 selectmode="row" >
             <cfgridcolumn name="Component_type" header="Component Type" width="400">
         </cfgrid>
    </cfform>
    </cfwindow>
    <!---getDistinct.cfc--->
    <cfcomponent>
        <cffunction name="getDistinct" access="remote" returntype="struct">
            <cfargument name="page">
            <cfargument name="pageSize">
            <cfargument name="gridsortcolumn">
            <cfargument name="gridsortdir">
            <cfargument name="appl_in"  type="string" required="true">
      <cfset var Qcomponents = ''>
        <cfif gridsortcolumn EQ "">
       <cfset gridsortcolumn = "ASC">
      </cfif>
            <cfif gridsortdir EQ "">
       <cfset gridsortdir = "ASC">
      </cfif>
       <cfquery name="Qcomponents" datasource="Tax">
          select DISTINCT(component_type) from ctl_components 
         where app_abbrev = #appl_in#
       </cfquery>
        <cfreturn QueryConvertForGrid(Qcomponents, page, pageSize)>
      </cffunction>
    </cfcomponent>
    Any advice you can give is greatly appreciated!
    Libby H.

    @Libby H
    There are 2 things.
    1) The name of the component the grid binds to(distinctComponents) is different from the name of the CFC(getDistinct).
    2) Session variables are also available to components. There is therefore no need to pass them explicitly to a function. In any case, it is always advisable to test for the existence of a session variable before using it.
    Your code would then be something like
    <cfform>
         <cfgrid name="componentsGrid"
                 format="html"
                 pagesize=10
                 striperows="yes"
                 bind="cfc:distinctComponents.getDistinct({cfgridpage},{cfgridpagesize },{cfgridsortcolumn},{cfgridsortdirection})"
                 selectmode="row" >
             <cfgridcolumn name="Component_type" header="Component Type" width="400">
         </cfgrid>
    </cfform>
    </cfwindow>
    <!---distinctComponents.cfc--->
    <cfcomponent>
        <cffunction name="getDistinct" access="remote" returntype="struct">
            <cfargument name="page">
            <cfargument name="pageSize">
            <cfargument name="gridsortcolumn">
            <cfargument name="gridsortdir">
      <cfset var Qcomponents = ''>
        <cfif gridsortcolumn EQ "">
       <cfset gridsortcolumn = "ASC">
      </cfif>
            <cfif gridsortdir EQ "">
       <cfset gridsortdir = "ASC">
      </cfif>
    <cfparam name="session.this_appl" default="your_default_value">
       <cfquery name="Qcomponents" datasource="Tax">
          select DISTINCT(component_type) from ctl_components 
         where app_abbrev = #session.this_appl#
       </cfquery>
        <cfreturn QueryConvertForGrid(Qcomponents, page, pageSize)>
      </cffunction>
    </cfcomponent>

  • How  can you avoid that an ABAB-Function works with an  EXPORT_PARAMETER

    Hello everybody,
    I have to call the ABAP-Function ECATT_EXECUTE via JCO.
    In SAP 7.0 there is a new EXPORT_PARAMETER for the function ECATT_EXECUTE, which is called E_RESULT_XML.
    There is a statement "IF E_RESULT_XML is requested" which gives always TRUE, so that the function tried to fill this Parmeter and an error occurred while processing.
    How you can avoid this ?
    What you can do, that this IF-Statement gives FALSE ?
    Every helpful hint is welcome !

    Hi Klaus,
    It may be because when calling a function via JCO all import/export/table parameters are always passed with the call.  Have you tried running the function from a test ABAP program and NOT requesting the parameter E_RESULT_XML?  If that works ok, the simple solution is to create a custom wrapper function module that you can call from JCO, which will call ECATT_EXECUTE for you ignoring E_RESULT_XML and then return the results to your Java.
    Hope this helps,
    Gareth.

  • How can you get rid of Genius function without losing iTunes 8.0?

    I recently updated iTunes to Version 8.0 with the Genius function, but I have the feeling that this program is taking up space on my hard drive that I don't want to lose. I understand that you can turn off Genius in the Store menu, but it's still on my computer.
    So, how do I eliminate the Genius function altogether from the version of iTunes on my computer? Is it possible? Or will I have to just go back to an older version that doesn't have Genius at all. I want to free up the space on my hard drive that the Genius program is using.
    In a previous thread <http://discussions.apple.com/thread.jspa?threadID=1703834&tstart=15>, a user seemed to ask this question, but it never really was answered.
    Any help from other users would be greatly appreciated.
    Thanks.

    AS it says in the thread you referred to you can turn off the genius function so it is not active.
    You do this on the Store menu.
    You can delete iTunes Library Genius.itdb in the iTunes folder. Normally if genius is switched on, it gets recreated, but I guess it may not if Genius is turned off, or at least it would remain small.
    You can't remove genius from iTunes, it is part of the program.

  • How can i pass sql string in proc as in parameter and use in cursor forloop

    Dear Experts ,
    Please help me in below code.
    create or replace PROCEDURE Sample_Spool_Data (SQLSTRING IN VARCHAR2, FILENAME in VARCHAR2) IS
    v_spool_file UTL_FILE.FILE_TYPE ;
    SQLSTRING VARCHAR2(1000);
    BEGIN
    v_spool_file := UTL_FILE.FOPEN('MPLD_DQMT',FILENAME,'w');
    UTL_FILE.PUT_LINE(v_spool_file,'Start: '||to_char(sysdate,'dd/mm/yyyy hh:mi s'));
    FOR c1_rec in SQLSTRING
    LOOP
    UTL_FILE.PUT_LINE(v_spool_file,c1_rec.rec);
    end loop;
    UTL_FILE.PUT_LINE(v_spool_file,'End: '||to_char(sysdate,'dd/mm/yyyy hh:mi s'));
    SQL String is having like select col1, col2, col3 from table_name;

    Looks like you're tring to write a generic way of outputting the results of a query to a file.
    You won't do it the way you're trying to, because your dynamic SQL means that you don't know the resultant columns of the query so that you can output them. To do that you need to use the DBMS_SQL package to describe the query and fetch the returned columns by position e.g.
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Can you pass more than on variable with getURL in flash form

    I needed to call another page from inside a form not with the submit button and fournd this piece of code
    <cfinput type="button" id="btEdit" name="btEdit" value="View" onClick="getURL('../../forms/Program_populate.cfm?<cfoutput>#SESSION.URLToken#</cfoutput> &Reference='+data.dataProvider[data.selectedIndex]['ID'],'_blank')" >
    "Reference" is passed in the URL, I have tried to tweek this to pass an additional field "ID" , Vendor_Number" , but have been unable to find the correct syntax.  If anyone can help that would be great.
    Thanks,
    Mike

    url variables are passed as follows
    after the file name a question mark (?) then,
    name=value with an ampersand (&) between name value pair
    You may be having problems with escaping the action script code.
    If the value is a coldfusion value just cfoutput the value as in your example.
    If the value is from a form element then you need to escape it as in the example
    remove the comments from below
    getURL('../../forms/Program_populate.cfm?
    <cfoutput>#SESSION.URLToken#< /cfoutput>
    &Reference='+data.dataProvider[data.selectedIndex]['ID']
    // need to add more info so put in the plus and add the text of the url variable name (let's assume the id is from CF)
    + '&ID=<cfoutput>#queryName.ID#</cfoutput>&Vendor_Number='
    //we have add the url variable name above, but let's assume it is coming from a form field
    // then we need to close the string, done above and add the value
    + data.dataProvider[data.selectedIndex]['Vendor_Number']
    ,'_blank')
    Hope this helps.
    If you still have problems, assing all this to a cf variable and output it so you can read what it is to debug it.
    Ken

Maybe you are looking for