Sql function in COLDFUSION

Does anybody can suggest me how do i write SQL FUNCTIONS in
Coldfusion, i tried to run a SQL FUNCTION in a <cfquery> but
that returned me an Coldfusion Error. do i need to use
<cfstoredProc> for that or. any other <tag available>
<cfquery name="blahblah" datasource="#dsn#">
CREATE FUNCTION [dbo].[ConcatUserGroups](@UserID int)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @groupname Varchar(2000)
SET @groupname = ''
SELECT @groupname = @groupname + ', ' + CONVERT(varchar(20),
u.group_name)
FROM [user] A
JOIN UserGroup_combo UG
ON UG.ug_userID = a.[USER_ID]
JOIN usergroup U
ON UG.ug_groupID = u.group_ID
WHERE A.[USER_ID] = @userID
AND LEN(ISNULL(U.group_name,'')) > 0
ORDER BY U.GROUP_NAME
IF(LEN(@groupname) >= 2) BEGIN
SET @groupname = RIGHT(@groupname,(LEN(@groupname) - 2))
END
RETURN @groupname
END
GO
</cfquery>

There's no such thing as "coldfusion sql" (sic). Everything
between the
<cfquery> tags is simply resolved (ie: CF runtime
statements between
pound-signs) and passed straight to the DB drivers, and
thence to the DB
itself. CF does no SQL processing at all.
Your error kind of suggests a syntac error AFTER the query
has been
executed though.
Could you post some code, and point out which precise line is
erroring?
Adam

Similar Messages

  • Group function in coldfusion

    Hello does anyone know how to use the group function in
    coldfusion
    my tables that out-puts to a html
    is outputing multiple CEENO
    for example CEENO
    11111
    11111
    11111
    11111
    someone here said to use the group function in coldfusion
    do you know where i can put it?
    <table border="2" cellpadding="2" cellspacing="0">
    <tr>
    <th>Record Number</th>
    <TH>PEA_id</TH>
    <th width="120">CEENO</th>
    <TH>Address</TH>
    <TH>ZipCode</TH>
    <th>AdvisoryDate</th>
    </tr>
    <cfloop query="getthecases">
    <tr bgcolor="<cfif currentrow mod
    2>GHOSTWHITE<cfelse>WHITE</cfif>">
    <td>#CurrentRow#</td>
    <td>#PEA_id</td>
    <Td>#CEENO#</td>
    <td>#ST_NO# #ST_initial# #st_dir#</td>
    <td>#ZipCode#</td>
    <td>#dateformat(ADVISORY_DATE,"mm/dd/yyyy")#</td>
    </tr>
    </cfloop>
    </table>

    What they are referencing is the group attribute of the
    CFOUTPUT tag:
    <cfoutput query="qryName" group="groupName">
    #dbgroupvar#
    <cfoutput>
    #otherdbdata#
    </cfoutput>
    </cfoutput>
    However, you have to write the correct SQL to get this to
    work and that includes using the ORDER BY clause in your SQL
    Statement to specify what column on which to group the output.
    For example, the following query would get all employees from
    the database and order them by the department for which they work:
    <cfquery name="qTest" datasource="dsn">
    SELECT name, title, department
    FROM employee
    ORDER BY department
    </cfquery>
    We can use the group attribute of cfoutput to show all
    employees for each department:
    <cfoutput query="qTest" group="department">
    <h1>#department#</h1>
    <table>
    <cfoutput>
    <tr>
    <td>#name#</td>
    <td>#title#</td>
    </tr>
    </cfoutput>
    </table>
    Hope this helps.
    Cheers,
    Craig

  • What is the latest version of SQL Server which ColdFusion 7 supports?

    What is the latest version of SQL Server which ColdFusion 7 supports? For example can Cold Fusion 7 connect to SQL Server 2012 or 2008 without any problem? Thanks

    First things first, I would advise you to apply the upgrades, if you haven't yet done so. I remember Coldfusion MX7 to be quite buggy. We could not wait to apply the upgrades and hotfixes. Version MX7.0.2 turned out to be the lasting upgrade. We used MySQL, however, not SQL Server.
    You can get the information you want from Adobe Support. But you can think it through yourself. The way I think about it is as follows.
    Coldfusion is an application that includes database functionality. I may therefore assume that Coldusion would be backwardly compatible in its support of database server versions. In other words, a new version of Coldfusion, say 9 or 10, would work with an older database server like SQL Server 2005.
    However, I would not expect a previous version of Coldfusion, say MX7, to be compatible with newer database server versions like SQL Server 2008 and SQL Server 2012. Even if someone told me they were compatible, I would still expect such a set-up to be an accident waiting to happen.

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

  • Passing Multiple Values from a worksheet to PL/SQL function.

    Hi All,
    Is there any way to pass multiple values selected in a worksheet to a PL/SQL function ?
    I will try to explain the scenario:
    We have a crosstab report that showing all the customer details, deposit sum of a customer in each date in a date range selected. With the customer details we are showing the Rank of a customer based on the deposit in the latest date selected. Filtering is based on the rank, ie Top50 or Top60 etc.( As I said rank is calculating based on the deposit in the latest date).This is working fine.
    Now the new requirement is to : For example, in Top50 report, list all the customers, who were in the Top50 list, in any of the dates selected. We are able to display the daywise rank, but when giving a condition like daywiserank <= 50, the result becomes uncertain. Some blank lines, wrong amounts etc..
    As a work around we tried to find out the rank in a PL/SQL function. But the issue there is : we have some multiple value parameters used in the worksheet.
    Is there any way to pass multiple values selected in a worksheet to a PL/SQL function ?
    Or any other work arounds for the scenario explained?
    Reagrds,
    Jeneesh

    Hi Russ,
    Thanks for the response.
    Russ Proudman wrote:
    1. I thought there was an analytical function similar to rank - or maybe an option of rank - that if there are duplicate records to have them all considered the same rank. So if you had 3 records all the same as rank=2 then a condition saying where rank=2 would return the 3 records. You could check into this.
    We are already using DENSE_RANK. But the issue is the output contains incorrect null values nd repeated rows.
    We got it solved as I explained in the previous post. But will that AGGREGATION MODE setting ( Which discoverer says - not recommended) have any issue? I mean side effects?
    Russ Proudman wrote:
    2. Another thought is that you can create a PL/SQL routine - that's called from a SQL function registered in Discoverer - where a table is created that does the first part of your query. Then a worksheet is created to use the data from that table. So, in essence, the table would have your top50 ranked customers. Then you can write any kind of worksheet against that table. However, DBAs are loath to allow tables - that they didn't create! - many times in a PROD environment.
    Here also the same problem will occur: as the top 50 will depend upon the parameters. I cannot pass those parameters to PL/SQL Function.And storing the top50 ( itmay be top100 or to 150 also) for all combinations of the parameters is impossible
    Russ Proudman wrote:
    3. Finally, are you sure you're rank function is correct in that if you're getting blank lines, maybe the 'over' part is not considering all columns needed to determine the rank?
    Yes the query we are using is correct. The output QUERY of discoverer gives correct results in Sqlplus.
    Regards,
    Jeneesh

  • Show refcursor returned by a PL/SQL function ?

    Is it possible to show the results returned by a
    PL/SQL function that returns a refcursor ?
    In sqlplus it goes like this:
    SQL> variable a refcursor;
    SQL> execute :a := p_front.get_invoice_list;
    PL/SQL procedure successfully completed.
    SQL> print a;
    INVOICE_ID CLIENT_ID INVOICE_D
    101 100 01-APR-06
    100 100 06-APR-06
    If not, this would be on the top of my wishlist...
    By the way: you did a good job on this tool!
    Regards,
    Willem

    Is it possible to show the results returned by a
    PL/SQL function that returns a refcursor ?
    In sqlplus it goes like this:
    SQL> variable a refcursor;
    SQL> execute :a := p_front.get_invoice_list;
    PL/SQL procedure successfully completed.
    SQL> print a;
    INVOICE_ID CLIENT_ID INVOICE_D
    101 100 01-APR-06
    100 100 06-APR-06
    If not, this would be on the top of my wishlist...
    By the way: you did a good job on this tool!
    Regards,
    Willem

  • Application Report Missing PL/SQL Functional Area

    All,
    I just wanted to bring to the ApEx developers something I just noticed... I use the Shared Components > Database Object Dependencies report to make sure all is well before moving applications into production.
    The Parsing Errors feature of that report is WONDERFUL! But it seems to be overlooking buttons that use a conditional display based on PL/SQL Function Body Returning a Boolean.
    Dan

    Hi Dan,
    I think the place is perfect, but I read once somewhere that "Bug" or "Bug Report" should be in the subject so that's easier to find for the Oracle guys.
    Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

  • Interactive report from PL/SQL function

    Hello All,
    i have a pl/sql function that dynamically builds up a sql query and returns it as a varchar2.
    when i create a new report then i can use this function in the report like
    return f_function(param1,param2,v('APP_ID'), v('APP_SESSION'));
    and this works fine.
    Except i cannot create an interactive report for this function, because it is not allowed !!!!
    So how can i use the function in an interactive report ?
    Thanks in advance,
    Marco

    Marco,
    Another rather extreme approach would be to go all the way and make your function pipelined (that is not only build but also execute the query) and then select from it in your interactive report.
    The disadvantage here would be that any supplementary filtering would act on the result set of the function (not as an addition to the where clause of the original query). But if you can live with that...
    The advantage would be that there's less fiddling with column headers.
    Regards,
    Iulian

  • Interactive Report with PL/SQL Function Source

    Is it possible to create interactive report with PL/SQL function source returing a query? If not, has anyone done any work to simulate the interactive reporting feature for a normal report using API?

    I haven't tried that before but you could:
    1. create a collection from your result set returned by a dynamic query,
    2. create a view on that collection,
    3. use the view in your interactive report.
    The usability of this proposal depends from a question how "dynamic" your query is - does it always have the same number of columns or not.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How to call a SQL function from an XSL expression

    Hi
    In R12, in Payroll Deposit adivce/Check writer, We need to sort the earnings tag <AC_Earnings> in to two different categories as regular and other earnings. In the DB and form level of element defintiion we have a DFF which differentiates between the two kinds of earnings. But the seeded XML that is gerneated by the check writer does not have this field.
    The seeded template displays all the earnings in one column. How can we achieve this in the template without modifying the seeded XML.
    The one approach i have is to write a function and based on the return value sort the data. For this I need to know :
    1) How to call a SQL function from an XSL expression that is allowed in BI template.
    If anyone ahs faced similar requirements please share your approach.
    Thanks
    Srimathi

    Thank u..
    but i'd seen that link wen i searched in google..
    Is it possible without using any 3rd party JARs and all?
    and more importantly plz tell me what should be preferred way to call a javascript function?
    Do it using addLoadEvent() or Windows.Load etc
    OR
    Call it thru Xsl? (I donno how to do dis)
    Thanks in Advance..
    Edited by: ranjjose on Jun 3, 2008 8:21 AM

  • SQL report region source to call a pl/sql function using DB link

    Hi - I have a pl/sql function fn_dbtype(id NUMBER) defined in database X. The pl/sql function executes couple DML statements and returns a string (a SELECT query). I am able to call this function using SQL Plus (Connected to Database X) as below and it works fine:
    declare
    vSQL VARCHAR2(100);
    begin
    vSQL := fn_dbtype(1);
    end;
    The DML operations completed fine and vSQL contains the "Select" query now.
    In APEX:
    I am trying to create a SQL report in APEX using SQL query(PL/SQL function returning a sql statement) option. I am trying to figure out what to put in the region source so that the output of the "Select" query is displayed in the report.
    Moreover APEX is hosted in a different database instance. So I would need to call this pl/sql function using a DB Link.
    Please let me know what I need to put in the region source to execute the pl/sql function which returns the "Select" query thereby displaying the query output in the report. Thanks.
    Edited by: user709584 on Mar 19, 2009 2:32 PM
    Edited by: user709584 on Mar 19, 2009 2:34 PM

    try something like this:
    return fn_dbtype(1)@dblink;

  • Problem to create a link with parameters using a PL/SQL function body

    Hi everybody,
    I need some help to create a link on a SELECT statement.
    I have a region report with type "PL/SQL function body return SQL query".
    I would like to use a link using HTML tag <a href>.
    I know how to do the link, but I don't know to pass a parameters in <a href> statement.
    Always I tried it doesn't work well.
    My PL/SQL anonimous block is, (just with link) :
    DECLARE
    q vARCHAR2(4000);
    BEGIN
    q:='select     "INDICADOR"."NRINDICADOR" as "NRINDICADOR",';
    q:=q||'     "INDICADOR"."DSINDICADOR" as "DSINDICADOR",';
    q:=q||'''<span style="font-weight:bold;">';
    q:=q||'''||TO_CHAR("TOTAL_INDICADOR"."VL_INDICADOR", ''999G999G999G990D00'')||''</span>''';
    q:=q||' as "VL_INDICADOR",';
    q:=q||'     "TOTAL_INDICADOR"."VL_META" as "VL_META" ';
    q:=q||' from     "TOTAL_INDICADOR" "TOTAL_INDICADOR",';
    q:=q||'     "INDICADOR" "INDICADOR" ';
    q:=q||' where "INDICADOR"."NRINDICADOR"="TOTAL_INDICADOR"."NR_INDICADOR"';
    RETURN q;
    END;
    Thanks for any help,
    Alessandra

    Your code is in a default value for an item, right?
    You need to make sure :P33_YEAR is not null and handle the error in the PL/SQL if it is.
    How is P33_YEAR populated? do you pass it in? check to see if it is making it there..
    Message was edited by:
    Bill Carlisle

  • Problem with empty report parameters when passed to PL/SQL function

    Hi,
    We have come across what appears to be a bug in the JRC. When passing a report parameter to a PL/SQL function as a parameter, empty parameters are changed before being sent to the function. More specifically, an empty string "" ends up as the value "(')" in the PL/SQL function parameter. In our report we print the report parameters on the first page so we know that the parameters are OK before being passed to the database.
    The problem exists for version 12.2.203, 12.2.204 and 12.2.205 of the JRC.
    We have identified a workaround, but it is not exactly elegant: Before executing the report we modify all empty  parameters ("") to " " . In the PL/SQL function, we trim all parameters before using them.
    We call the function using a command object with a sql syntax like this example:
    select * from table (qa_batch_release.get_qa_br('{?p_report_id}','{?p_reg_set_number}','{?p_cr_number}','{?p_change_id_decode}','{?p_country_id}','{?p_mfg_item_no}','{?p_4_no}','{?p_5_no}','{?p_7_no}'))
    The PL/SQL function is a table returning function.
    Best regards, Thor

    Hi Kishore,
    using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
    What you can do to make it more generic is to use for example
    #CHECK_AMOUNT#
    in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
    SELECT NAME
         , BALANCE
         , BALANCE AS CHECK_AMOUNT
    FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
    Thope that helps
    Patrick

  • Passing #COLUMN_VALUE# as parameter to pl/sql function in column template

    Hi all,
    I want to color negative amounts in red in sql report using column template.
    I created a pl/sql function"isNegativeNum" which returns 1 or -1.
    create or replace function isNegativeNum(p_column_value varchar2) return number
    as
    l_dummy number;
    begin
          l_dummy := to_number(p_column_value,'999G999G990D00PR');
          IF l_dummy < 0
             THEN
                RETURN 1;
          else
                return -1;
          END IF;
    exception
    when others then
       RETURN -1;
    end;Below is column template.
    Column Template 1
    <td class="t3dataalt" #ALIGNMENT#><p color=red>#COLUMN_VALUE#</p></td>Column Template 1 Condition
    isNegativeNum('#COLUMN_VALUE#') = -1The issue is #COLUMN_VALUE# value is not being passed to the function, Insert statement in function reveals p_column_value as a string "#COLUMN_VALUE#". When I try without quotes like isNegativeNum(#COLUMN_VALUE#) = -1, I get below error.
    ORA-06550: line 1, column 48: PLS-00103: Encountered the symbol "#" when expecting one of the following: ( ) - + case mod new not null others select table avg count current exists max min prior sql stddev sum variance execute multiset the both leading trailing forall merge year month DAY_ hour minute second timezone_hour timezone_minute timezone_region timezone_abbr time timestamp interval date
         Error      ERR-1025 Error processing PLSQL expression. isNegativeNum(#COLUMN_VALUE#) = 1
    Any help is appreciated.
    Kishore

    Hi Kishore,
    using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
    What you can do to make it more generic is to use for example
    #CHECK_AMOUNT#
    in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
    SELECT NAME
         , BALANCE
         , BALANCE AS CHECK_AMOUNT
    FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
    Thope that helps
    Patrick

  • Passing parameters to PL/SQL function called in VO

    Hi,
    I am writing a VO that is calling a PL/SQL function. The VO query looks like this.
    select xx_dummy_func (:1,:2) from dual
    Now, how can I assign these two parameter values at run time?
    Generally when we have a query parameters We do xxVO.setwhereclauseparam. But in the above scenario, its not a whereclause but instead a procedure parameter. Please let me know how to do it.
    Thanks in advance,
    Regards,
    -Abm

    Thats correct, basically, setwherecaluse param api, just replaces bind variables with the index values, whereever they are in the query!
    --Mukul                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • How long Oracle plans to support Forms/Reports 6i ?

    Hello dear Oracle Forms users/developers, The "Oracle Forms: Features Obsolescence for Release 9i", which I downloaded from OTN, clearly indicates that the client-server runtime will be obsolete in 9i, and (quote) "users who currently deploy their ap

  • SUBSTR and INSTR query

    Hello all, I need help in simple query how can show only MCCODE SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'VMTOPIC=')+8,20) AS output  FROM DUAL;But also when i used SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'HHH')+8,20) AS

  • Data objects and code objects in oracle application

    Hi, can any one please help me out with following question? 1. what are data objects and code objects in oracle apps and why is that difference? 2. How does the objects gets created in Oracle Applications, like during the installation which part is r

  • Playing .mkv with mplayer-vdpau does not work

    Hi, My System is a Atom 330 with an Nvidia ION. The Atom is running at 2 GHz. I installed the mplayer-vdpau-svn from aur. With this i tried to play a .mkv file. Without the vdpau parameters the Movie is running, but too slow. When i use the parameter

  • Want to Take Backup Of Programs Done in ECC6 IDES Server

    Hi Experts, Want to Take Backup Of Programs Done in ECC6 IDES Server like, Fico related Company Code,Configuration.... Abap Realted Programs....I Did my Practice in client 800 in IDES ECC6. My Moto, Here is to Format the old server and Install new se