Store results into a variable...

How can I get a result I need into a variable, that I can use in a subsequent query.
My initial thought was something like:
select emp_id into MyVariable
from emp where emp_NAME='Kevin';
select * from emp
where emp_id='&MyVariable';
I'm doing this in TOAD, and I need to manually type the 'Kevin' once, and use the MyVariable in a series of queries; otherwise I would just use ACCEPT, and ask for the Name, and lookup the emp_id. But this is not what I need for this.
I've tried OBG (Oracle By Google) which suggested something like:
DECLARE
MyVariable number;
BEGIN
select emp_id into MyVariable
where emp_NAME='Kevin';
dbms_output.put.line ('My Variable is ' || MyVariable);
END
But I'm getting and error on the dbms_output statement, and I can't seem to use the variable in a subsequet select statement!
Appreciate any thoughts on this!

I would advise putting the sql statements into a pl/sql block - then you could reuse the value
declare
    v_my_var NUMBER;
begin
    -- Get your value
    select ... into v_my_var from ... where name = 'Kevin' ...
    -- your first sql statement
    select  .... from .... where id = v_my_var;
    -- your second sql statement
    select .... from .... where id = v_my_var;
    etc.
end;Toad does also provide for using the same value multiple times - for example, if you execute
select &name from dual;   (any select statement)it will prompt you for a value for &name
You can then have multiple statements after that in your sql tab
select .... from .... where name = &nameand it will replace the &name with the value you previously entered. You need to use Editor -> Run as Script (F5) to run all the sql statements in your tab.
Hope this helps.

Similar Messages

  • Copy the result of Execute immediate result into a variable.

    Hi All,
    Is there any way to copy the result of execute immediate result into a variable.
    am doing following steps but am getting an error.
    varSQLstmt1:='select count(*) into'||vararch_ct||' from '||vararch_count;
    dbms_output.put_line(varSQLstmt1);
    execute immediate varSQLstmt1;
    But am getting sql statement as select count(*) into from SALES
    the variable(vararch_ct) is missing in select statement .
    please help me to solve this issue. Or is there any way to insert the count of records into any variable.
    Thanks
    Sree

    declare
    varSQLstmt1    varchar2(4000);
    v_count          number;
    begin
    varSQLstmt1:='select count(*) from '||vararch_count;
    dbms_output.put_line(varSQLstmt1);   
    execute immediate varSQLstmt1 into v_count;
    dbms_output.put_line('Coutn :: ' || v_count);
    end;

  • Mapping proc output to vars gets error extracting result into a variable of type (DBTYPE_UI2)

    Hi, we run std 2012.  I have a proc (sets nocount on) whose params r shown in the first block .   My execute ssis sql task mapping is shown in the block following that (same order as shown, the param sizes are all -1).  The variable
    characteristics and initial values are shown in the 3rd block.  The execute sql task command is
    exec usp_fileArrivalStatus ?,?,?,?,?,? output,? output,? output
    when I run the proc in ssms followed by a select on the output fields, I get stat 0, instance id -1 and file name empty string (aka tick tick aka '')
    The error is:
    [Execute SQL Task] Error: Executing the query "exec usp_fileArrivalStatus ?,?,?,?,?,? output,? ou..." failed with the following error:
    "An error occurred while extracting the result into a variable of type (DBTYPE_UI2)".
    Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Does anybody know what is wrong?
    CREATE PROCEDURE [dbo].[usp_fileArrivalStatus] @NewFilePattern varchar(500),
    @PkgName varchar (257),
    @appid int,
    @MsgHistCreateDate date,
    @messageFriendlyName varchar(500),
    @arrivalStatus int output,
    @instanceId bigint output,
    @fileName varchar(500) output
    VariableName Direction DataType ParamName
    User::TranFilePattern Input VARCHAR 0
    System::PackageName Input VARCHAR 1
    User::AppID Input SHORT 2
    User::todaysDate Input DATE 3
    User::TranFileArriveStatus OUTPUT SHORT 5
    User::TranFileInstanceId OUTPUT LARGE_INTEGER 6
    User::TranFileName OUTPUT VARCHAR 7
    User::TranFileFriendlyName Input VARCHAR 4
    User::TranFilePattern,string,tranfile05-Nov-2014
    User::fileDate,string,05-Nov-2014
    System::PackageName,
    User::AppID,int32,12
    User::todaysDate,DateTime, set by select getdate()
    User::TranFileArriveStatus,int32,0
    User::TranFileInstanceId,Int64,0
    User::TranFileName,string
    User::TranFileFriendlyName,string,Tran File

    I may have gotten past this.  The ui showed the first execution of that proc as the aborting component but when I looked at my error code (-1073548784), and component name in the
    message sent with notification email, I noticed the second component name.  It too executes that proc and still had ushort for appid in sql task mapping and long for instance id.  I changed these characteristics to match what I posted and got green
    on the seq container that runs both.
    I think I go thru this kind of adventure every time I try to map proc output to ssis vars.   

  • Problem to store a oracle sql result into a variable

    Hello everyone,
    I'm working on a little project that use c#, Oracle ODT and asp.net, so here is the thing, I need to save the result of a sequence (SECNUM.NEXTVAL ) into a variable, then call that value from many inserts and querys and for last make the commit. My problem is that I don't know how to convert the string result to a number and the call it from the statements. Always brings two errors, one is invalid number because Im sending a string and the another is that if I comment the line cmd.ExecuteNonQuery(); the script runs but no commit happens.
    This is my code, is attached to a button:
    C# Syntax (Toggle Plain Text)
    string oradb = "Data Source=BBDD;User Id=DEMO;Password=DEMO;";
    string cmd1 = "SELECT SECNUM.NEXTVAL FROM DUAL";
    OracleConnection conn = new OracleConnection(oradb);
    conn.Open();
    OracleParameter parm = new OracleParameter();
    parm.OracleDbType = OracleDbType.Decimal;
    OracleCommand cmd = new OracleCommand();
    cmd.Connection = conn;
    cmd.Parameters.Add(parm);
    cmd.CommandText = "INSERT INTO DEMOINCI (CODINCI, CODCLI) VALUES (('" + cmd1 +"'), 'TEST')";
    cmd.CommandText = "INSERT INTO DEMOINCILIN (CODINCI,CODLIN) VALUES (('" + cmd1 +"'),1)";
    cmd.CommandType = CommandType.Text;
    cmd.ExecuteNonQuery();
    So my problem is that the column CODINCI is a column number of (9) and not a VARCHAR and can not be changed because is already have data, so when I use the code of the example, Oracle return an error saying Invalid number (of course).
    With the help of a friend I tried to put with the cast like this cmd.CommandText = "INSERT INTO DEMOINCI (CODINCI, CODCLI) VALUES (" + "CAST(" + cmd1 + "AS NUMBER), 'TEST')"; and it works but only if I comment the line cmd.ExecuteNonQuery();, so the commit never happend and of course there is no insert in the database.
    ¿It is so difficult to store a result of an SQL into a variable and then call it back on a statement?, on Oracle Forms you create a cursor like cursor=CVAL SELECT SECNUM.NEXTVAL VAL FROM DUAL and that it you can then use the VAL result into all other queries of the same form an retrieving with the :VAL option.
    Thanks for all the help.

    I just had to do something similar for my C# class, using SQL Server. The primary key for a "Customers" table was an auto-incrementing integer. After inserting a new customer I had to retrieve and display the primary key:
    string selectStatement = "SELECT IDENT_CURRENT('Customers') from Customers";
    SqlCommand selectCommand = new SqlCommand(selectStatement, connection);
    int customerID = Convert.ToInt32(selectCommand,ExecuteScalar());
    The ExecuteScalar() method of selectCommand returned the first column of the first row of the dataset, which in this case was the key of the new Customers record, as an object. Convert.ToInt32() converted the key to an integer.
    Once you store SECNUM.NEXTVAL as an integer, you can use it to create a Parameter for the Command object.
    HTH.

  • XMLELEMENT/ XMLAGG functions - Fetching the result into a variable

    Hi, I have a query to generate an XML output. I have the following questions:
    1) I am typecasting the result from this query to a VARCHAR2 and I want to assign the output to a VARCHAR2 variable. Can you please help me with that. When I try to get this into a varchar variable, i get the following error:
    declare
    x varchar2(6000);
    begin
    SELECT CAST(xmlelement("itemMaster",
    xmlelement("itemNumber",lpad(d.dept_i,3,0)||lpad(d.class_i,2,0)||lpad(d.item_i,4,0)),
    xmlelement("itemDesc",NVL(d.ITEM_DESC_T,lpad(d.dept_i,3,0)||lpad(d.class_i,2,0)||lpad(d.item_i,4,0))),
    xmlelement("paltSize",p1_test),
    xmlelement("stdUOM",p1_test),
    xmlelement("sellByDayQty",d.sell_by_day_q),
    xmlelement("shflfUOM",p1_test),
    xmlelement("minShflfDayQty",d.min_shflf_day_q),
    xmlelement("itemCatgCode",NVL(d.dc_item_catg_c,'GM')),
    xmlelement("strgTempZoneCode",NVL(d.strg_tmpr_zone_c,'01')),
    xmlelement("retailAmt",retl_a),
    xmlelement("expireDateFlag",NVL(d.expire_date_f,'N')),
    xmlelement("randomWtFlag",NVL(d.rndm_wt_f,'N')),
    xmlelement("wetFlag",NVL(d.wet_f,'N')),
    xmlelement("areaCode",d.area_c),
    xmlelement("vcpQty",d.vcp_q),
    xmlelement("sspQty",d.ssp_q),
    xmlelement("hndlTypeCode",d.hndl_type_c),
    xmlelement("mstrPackTypeCode",d.mstr_pk_type_c),
    xmlelement("mstrItemTypeCode",NVL(d.mstr_item_type_c,'00')),
    xmlelement("sszCode",d.reg_ssz_excpt_c),
    xmlelement("agriFlag",NVL(d.agrl_f,'N')),
    xmlelement("itemRankCode",d.item_rank_c),
    xmlelement("hazardFlag",NVL(d.hazd_mtrl_f,'N')),
    xmlelement("createDate",to_char(d.create_d,'MM-DD-YYYY HH24:MI:SS')),
    xmlelement("updateDate",to_char(d.modf_ts,'MM-DD-YYYY HH24:MI:SS')),
    xmlelement("actvnDate",to_char(d.actvn_d,'MM-DD-YYYY HH24:MI:SS')),
    xmlelement("organicCode",d.ognc_c),
    xmlelement("lotCntlFlag",NVL(d.lot_cntl_f,'N')),
    xmlelement("flammableFlag",NVL(d.flam_c,'N')),
    xmlelement("recordMode",c.action_c),
    xmlelement("areaType",p1_test),
    xmlelement("uoms",
    xmlelement("uom",
    xmlelement("prodUOM",p1_test),
    xmlelement("ratioDen",p1_test),
    xmlelement("consldtRule",p1_test),
    xmlelement("unitWtQty",NVL(d.unit_wt_q,1)),
    xmlelement("vcpHeightQty",NVL(d.vcp_ht_q,1)),
    xmlelement("vcpWidthQty",NVL(d.vcp_wth_q,1)),
    xmlelement("vcpLengthQty",NVL(d.vcp_lgth_q,1)),
    xmlelement("layerQty",p1_test)
    (SELECT xmlelement("aliases",
    xmlagg(xmlelement("upcCode",trunc(b.bar_code_i))
    ORDER BY b.dept_i,b.class_i,b.item_i
    FROM dc_item_bar_code b,
    dc_item a
    WHERE a.dept_i = b.dept_i
    AND a.class_i = b.class_i
    AND a.item_i = b.item_i
    AND a.dept_i = c.dept_i
    AND a.class_i = c.class_i
    AND a.item_i = c.item_i
    AS VARCHAR2(4000)
    ) INTO x
    FROM dc_item d, item_wm_trigger_w c
    WHERE d.dept_i = c.dept_i
    AND d.class_i = c.class_i
    AND d.item_i = c.item_i;
    end;
    ERROR at line 1:
    ORA-06550: line 49, column 33:
    PLS-00306: wrong number or types of arguments in call to 'XMLAGG'
    ORA-06550: line 49, column 33:
    PL/SQL: ORA-00904: "XMLAGG": invalid identifier
    ORA-06550: line 4, column 1:
    PL/SQL: SQL Statement ignored
    When I run this query without the
    declare
    begin
    select....
    into...
    end
    construct, it's working perfectly fine.
    Any help would be greatly appreciated.
    Thanks,
    Nitin

    I think I confused you. The 'pre' tags are for this Oracle Forum ( not your code). If your code was formatted we can look at it better .
    For example, I have put your code in those tags(you won't see them), they are for the forum software to process.
    See, how I didn't lose the formatting?
    DECLARE
      x VARCHAR2(6000);
    BEGIN
      SELECT CAST(xmlelement("itemMaster",
                             xmlelement("itemNumber",
                                        lpad(d.dept_i, 3, 0) || lpad(d.class_i, 2, 0) ||
                                        lpad(d.item_i, 4, 0)),
                             xmlelement("itemDesc",
                                        NVL(d.ITEM_DESC_T,
                                            lpad(d.dept_i, 3, 0) ||
                                            lpad(d.class_i, 2, 0) ||
                                            lpad(d.item_i, 4, 0))),
                             xmlelement("paltSize", p1_test),
                             xmlelement("stdUOM", p1_test),
                             xmlelement("sellByDayQty", d.sell_by_day_q),
                             xmlelement("shflfUOM", p1_test),
                             xmlelement("minShflfDayQty", d.min_shflf_day_q),
                             xmlelement("itemCatgCode", NVL(d.dc_item_catg_c, 'GM')),
                             xmlelement("strgTempZoneCode",
                                        NVL(d.strg_tmpr_zone_c, '01')),
                             xmlelement("retailAmt", retl_a),
                             xmlelement("expireDateFlag", NVL(d.expire_date_f, 'N')),
                             xmlelement("randomWtFlag", NVL(d.rndm_wt_f, 'N')),
                             xmlelement("wetFlag", NVL(d.wet_f, 'N')),
                             xmlelement("areaCode", d.area_c),
                             xmlelement("vcpQty", d.vcp_q),
                             xmlelement("sspQty", d.ssp_q),
                             xmlelement("hndlTypeCode", d.hndl_type_c),
                             xmlelement("mstrPackTypeCode", d.mstr_pk_type_c),
                             xmlelement("mstrItemTypeCode",
                                        NVL(d.mstr_item_type_c, '00')),
                             xmlelement("sszCode", d.reg_ssz_excpt_c),
                             xmlelement("agriFlag", NVL(d.agrl_f, 'N')),
                             xmlelement("itemRankCode", d.item_rank_c),
                             xmlelement("hazardFlag", NVL(d.hazd_mtrl_f, 'N')),
                             xmlelement("createDate",
                                        to_char(d.create_d, 'MM-DD-YYYY HH24:MI:SS')),
                             xmlelement("updateDate",
                                        to_char(d.modf_ts, 'MM-DD-YYYY HH24:MI:SS')),
                             xmlelement("actvnDate",
                                        to_char(d.actvn_d, 'MM-DD-YYYY HH24:MI:SS')),
                             xmlelement("organicCode", d.ognc_c),
                             xmlelement("lotCntlFlag", NVL(d.lot_cntl_f, 'N')),
                             xmlelement("flammableFlag", NVL(d.flam_c, 'N')),
                             xmlelement("recordMode", c.action_c),
                             xmlelement("areaType", p1_test),
                             xmlelement("uoms",
                                        xmlelement("uom",
                                                   xmlelement("prodUOM", p1_test),
                                                   xmlelement("ratioDen", p1_test),
                                                   xmlelement("consldtRule", p1_test),
                                                   xmlelement("unitWtQty",
                                                              NVL(d.unit_wt_q, 1)),
                                                   xmlelement("vcpHeightQty",
                                                              NVL(d.vcp_ht_q, 1)),
                                                   xmlelement("vcpWidthQty",
                                                              NVL(d.vcp_wth_q, 1)),
                                                   xmlelement("vcpLengthQty",
                                                              NVL(d.vcp_lgth_q, 1)),
                                                   xmlelement("layerQty", p1_test))),
                             (SELECT xmlelement("aliases",
                                                xmlagg(xmlelement("upcCode",
                                                                  trunc(b.bar_code_i))
                                                       ORDER BY b.dept_i,
                                                       b.class_i,
                                                       b.item_i))
                                FROM dc_item_bar_code b, dc_item a
                               WHERE a.dept_i = b.dept_i
                                 AND a.class_i = b.class_i
                                 AND a.item_i = b.item_i
                                 AND a.dept_i = c.dept_i
                                 AND a.class_i = c.class_i
                                 AND a.item_i = c.item_i)) AS VARCHAR2(4000))
        INTO x
        FROM dc_item d, item_wm_trigger_w c
       WHERE d.dept_i = c.dept_i
         AND d.class_i = c.class_i
         AND d.item_i = c.item_i;
    END;
    /

  • How to pass the grep result into a variable in Unix

    I have the following statements in my unix batch script:
    JOBNAME=`grep "$1" rssc_plsbatch.txt|awk -F'~' '{print $1}'`;
    PROCNAME=`grep "$1" rssc_plsbatch.txt|awk -F'~' '{print $2}'`;
    JOBDESC=`grep "$1" rssc_plsbatch.txt|awk -F'~' '{print $3}'`;
    PARMS=`grep "$1" rssc_plsbatch.txt|awk -F'~' '{print $4}'`;
    I want to grep the the first line in the text file and pass it to a variable and then using awk programming, I want to print for each variable (JOBNAME, PROCNAME, JOBDESC and PARMS), instead of using grep 4 times.
    Can somebody please help.
    Each line of my text file is in the the following format:
    00001JOB1~PROCNAME1~This is a procedure~10,'A','B'~
    And also I want to check whether $1 passed (part of JONAME) is not fount, then it should exit with error message, if $1 (input parameter) does not match, I want to exit the program, instead of processing further statements.

    If you want to return error codes, you can do that with the return command.
    If the process name isn't found, grep will return a specific error code... from man grep
    Normally, exit status is 0 if selected lines are found and 1 otherwise.
    But the exit status is 2 if an error occurred, unless the -q or quiet or silent option is used and a selected line is found.
    So you can use the exit code of grep in an if statement to decide what return code you want to return with your own script.
    Mike

  • Fetches more values into one variable

    Hi, inside a cursor loop I'd like to assign, each fetch, a value to a variable, in order, at the end to have a collection of all the values fetched into the same variable.
    The code is the following:
    CREATE OR REPLACE procedure APPS.AAA as
    v_pino varchar2(64);
    CURSOR tks_opened_range IS
    SELECT incident_number AS YP_TKS_OPENED_WITHIN_RANGE FROM cs.cs_incidents_all_b a, cs_incident_statuses_b b, Cs_Incident_Statuses_Tl c
    WHERE b.incident_status_id = c.incident_status_id
    AND a.incident_status_id = b.incident_status_id
    AND (b.attribute1 <> '3' OR b.attribute1 IS NULL)
    AND c.language = 'EL'
    AND ((sysdate - to_date(incident_attribute_6, 'dd-mm-yyyy hh24:mi'))*1440) BETWEEN 1 AND 11111111111
    AND incident_attribute_2 IN ('ΓΕΝΙΚΗ ΔΙΕΥΘΥΝΣΗ ΤΕΧΝΟΛΟΓΙΑΣ')
    ORDER BY incident_number;
    rec_tks_opened_range tks_opened_range%ROWTYPE;
    begin
    FOR rec_tks_opened_range IN tks_opened_range
    LOOP
    v_pino := rec_tks_opened_range.YP_TKS_OPENED_WITHIN_RANGE;
    DBMS_OUTPUT.PUT_LINE('v_pino: ' || v_pino);
    end loop;
    end AAA;
    This works with the variable v_pino!....but at the end, the value of the variable v_pino is ONLY the last fetched by the cursor.
    Is there a way to declare a variable (or better a collection) or a new type in order to have all the data fetched into this variable and the end of the fetching ?
    I need to know this trick because, after, I have to assign this variable to a pipelined table function.
    Thanks in advance
    Alex
    /

    Great Devang !! Thanks a lot ! It works ! Now I am able to retrieve all the values I need and store them into my variable gino
    I searched on the note you mentioned in your mail in order to pass an array as a variable to a table function (PIPE ROW call), but I didn't find nothing about it.
    Now I explain to you my situation.
    I already implemented a table function that works perfectly. I have 2 cursors declared and 2 PIPE ROW calls.
    FUNCTION statistic_report_2_1 (p_resolv_time_ll varchar2, p_resolv_time_ul varchar2, p_ypiresia varchar2)
    RETURN xxi_statistic_rep_2_1_tab PIPELINED
    IS
    -- CURSORS FOR THE FIRST SHEET - Tickets opened per group and per duration
    -- Cursor for tickets opened within 1 hour --
    CURSOR tks_opened_1_h IS
    SELECT incident_number AS YP_TKS_OPENED_WITHIN_1_HOUR
    FROM cs.cs_incidents_all_b a, cs_incident_statuses_b b, Cs_Incident_Statuses_Tl c
    WHERE b.incident_status_id = c.incident_status_id
    AND a.incident_status_id = b.incident_status_id
    AND (b.attribute1 <> '3' OR b.attribute1 IS NULL)
    AND c.language = 'EL'
    AND ((sysdate - to_date(incident_attribute_6, 'dd-mm-yyyy hh24:mi'))*1440) < 60
    AND incident_attribute_2 IN (SELECT * FROM TABLE(CAST(xxi_szf_discoverer.ypiresia_values(p_ypiresia) AS xxi_ypiresia_list_tab)))
    ORDER BY incident_number;
    rec_tks_opened_1_h tks_opened_1_h%ROWTYPE;
    -- Cursor for tickets opened between 1 hour and 3 hours --
    CURSOR tks_opened_1_3_h IS
    SELECT incident_number AS YP_TKS_OPENED_BE_1_3_HOURS FROM cs.cs_incidents_all_b a, cs_incident_statuses_b b, Cs_Incident_Statuses_Tl c
    WHERE b.incident_status_id = c.incident_status_id
    AND a.incident_status_id = b.incident_status_id
    AND (b.attribute1 <> '3' OR b.attribute1 IS NULL)
    AND c.language = 'EL'
    AND ((sysdate - to_date(incident_attribute_6, 'dd-mm-yyyy hh24:mi'))*1440) BETWEEN 60 AND 179
    AND incident_attribute_2 IN (SELECT * FROM TABLE(CAST(xxi_szf_discoverer.ypiresia_values(p_ypiresia) AS xxi_ypiresia_list_tab)))
    ORDER BY incident_number;
    rec_tks_opened_1_3_h tks_opened_1_3_h%ROWTYPE;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    -- FIRST SHEET OPEN CURSORS --
    TICKETS NUMBER OPENED WITHIN 1 HOUR
    FOR rec_tks_opened_1_h IN tks_opened_1_h
    LOOP
    PIPE ROW(stat_rep_2_1_type(
    rec_tks_opened_1_h.YP_TKS_OPENED_WITHIN_1_HOUR
    END LOOP;
    -- TICKETS NUMBER OPENED BETWEEN 1 HOUR AND 3 HOURS --
    FOR rec_tks_opened_1_3_h IN tks_opened_1_3_h
    LOOP
    PIPE ROW(stat_rep_2_1_type(
    ,rec_tks_opened_1_3_h.YP_TKS_OPENED_BE_1_3_HOURS));
    END LOOP;
    RETURN;
    END statistic_report_2_1;
    But, in this way and with this syntax, I obtain for each PIPE ROW call only one field filled each time, because I can’t call 2 cursors in a nested loop together (data duplication);
    For example:
    1st PIPE ROW call : only the first field is filled and into the second I have to put ‘’
    2nd PIPE ROW call : only the second field is filled and into the first I have to put ‘’
    ….and I cant’ call with a single PIPE ROW call two cursor variables…..
    Into a Discoverer report this data layout is really bad (you can imagine with thousand
    of records).
    For this reason I thought to use an array variable (gino) to pass to a single PIPE ROW call outside the cursor loop……but it doesn’t work !!!
    Can you suggest me how to resolve this problem….if it possible ?
    Did I have to declare other TYPE or collection ?
    Thanks you so much
    Alex

  • Input result from a SQL-query into a Variable in ProcessFlow

    I am trying to select a value from a table with file names.
    This file name should be input to an ftp function. I use a owb function to read the file name then I try to asign the result to a variable.
    The function GET_FILENAME looks like
    f_name varchar2(30);
    BEGIN
    select distinct FILENAME_SOURCE into f_name from CTL_SOURCE_FILES
    where FILEID = (select min(FILEID) from CTL_SOURCE_FILES where status is null);
    RETURN f_name;
    END;
    When running it as a SQL-script it returns only one row/name.
    When I am running it in the ProcessFlow the following message is found:
    RPE-02040: Internal error: GET_FILENAME cannot be converted to a constant value.

    Let me talk about this in context of a mapping:
    create a mapping :
    use a function within a mapping
    assign the output of the mapping to a mapping input variable"
    use this mapping within your process flow and see if it works.
    if you are directly going to use the output of a function in a process flow , the FTP should be able to accept the filename from the outparam of the function which i am not sure how it works.
    try using the first approach as it is relatively simple and straightforward.

  • Store multiple values into a variable

    I was wondering if it was possible to store multiple values into one varaible. Something along the lines of...
    Oracle: 10g
    --Table xSample (this is obviously a dumbed down version of the table for the sake of showing what I want to accomplish
    S_ID   YEAR
    1         2009
    2         2009
    3         2009
    4         2009
    --Query
    select     s_id
    into       pID
    from      xSample
    where    year = 2009;Basically the reason I was trying to figure out how to store multiple values into a variable is b/c I was going to use that variable (pID) as a parameter and have it's values passed dynamically when the proc was called. The values would go into a query that would look something like:
    select *
    from cust_data
    where person_id in (pID)
    aka
    select *
    from cust_data
    where person_id in (1,2,3,4)Not sure if this is possible, but if anyone knows of a way I could accomplish this that would be great.
    Edited by: user652714 on Dec 23, 2009 9:37 AM

    Here's a basic idea building a comma seperated list, then consuming it in another query (taking the in list approach from Tom's post, linked earlier).
    create table xsample (s_id number not null, year number);
    insert into xsample select level, 2009 from dual connect by level <=4;
    commit;
    declare
       --4000 should be lots ... hopefully?
       v_parameter_list varchar2(4000);
    begin
      --create the comma seperated list
      select
        substr(max(sys_connect_by_path(s_id, ',') ), 2, 4000)
      into
        v_parameter_list
      from
        select s_id, row_number() over(order by 1) as rn
        from xsample
        where year = 2009
      start with rn = 1
      connect by prior rn = rn - 1;
      --consume the comma seperated list
      for x in
        with data as
          select
            trim( substr (txt,
            instr (txt, ',', 1, level  ) + 1,
            instr (txt, ',', 1, level+1)
            - instr (txt, ',', 1, level) -1 ) ) as token
          from
            select ','||v_parameter_list||',' txt
            from dual
          connect by level <= length(v_parameter_list)-length(replace(v_parameter_list,',',''))+1
        select *
        from xsample
        where s_id in (select * from data) 
      loop
        dbms_output.put_line('next item = ' || x.s_id);
      end loop;
    end;
    /

  • Want to read a Query list of results into a defined variable "as Collection" for later use (ie create reports)

    The following code works great (Functions Main and OpenThisFile ) to select files from a folder and read into defined variable "FileToProcess As Collection" (I guess then renamed fil) and use that list of files to run through
    an import process defined in a function "StartMe". 
    What I want to do is read the results of a query into a similar collection variable and then use in a function like "StartMe" to run a series of reports.  The functions to do that below (PrintCKListTables and ReadQueryOfSDGs) currently
    don't work erring out "For Each s In .selectedQuery".  I would appreciate any help guiding me how to fix function
          ReadQueryOfSDGs() As Collection
    Thank you very much in advance for your help!
    Public Function Main()
    Dim FilesToProcess As Collection, fil
    Dim initialFilePath As String
    initialFilePath = CreateObject("WScript.Shell").specialfolders("C:\temp")
    Set FilesToProcess = OpenThisFile(initialFilePath)
    For Each fil In FilesToProcess
    StartMe fil
    Next fil
    End Function
    Public Function OpenThisFile(initialFilePath As String) As Collection
    'Requires reference to Microsoft Office 12.0 Object Library.
    Dim fDialog As Office.FileDialog
    Dim varFile As Variant
    'Clear listbox contents.
    'Me.FileList.RowSource = ""
    'Set up the File Dialog.
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
    'Allow user to make multiple selections in dialog box.
    .AllowMultiSelect = True
    .InitialFileName = initialFilePath
    'Set the title of the dialog box.
    .Title = "Please select one or more files"
    'Clear out the current filters, and add our own.
    .Filters.Clear
    .Filters.Add "XML Files", "*.XML"
    'Show the dialog box. If the .Show method returns True, the
    'user picked at least one file. If the .Show method returns
    'False, the user clicked Cancel.
    If .Show = True Then
    'Loop through each file selected and add it to the list box.
    Dim s
    Set OpenThisFile = New Collection
    For Each s In .SelectedItems
    OpenThisFile.Add s
    Next s
    Else
    MsgBox "You clicked Cancel in the file dialog box."
    NotContinue = True
    End If
    End With
    End Function
    Public Function PrintCkListTables()
        Dim FilesToProcess As Collection, fil
        Dim ListSDGs As String
        Set FilesToProcess = ReadQueryOfSDGs(ListSDGs)
        For Each fil In FilesToProcess
            fNameExportpdfReport (fil)
        Next fil
    End FunctionPublic Function ReadQueryOfSDGs() As Collection       DoCmd.OpenQuery "y_qs_DataIn_All_SDGList"
           Dim s
           Set ReadQueryOfSDGs = New Collection
           For Each s In .selectedQuery
           ReadQueryOfSDGs.Add s
           Next s
    End Function

    There are a few problems here. In function PrintCkListTables() you define a string variable ListSDGs and then use that as an argument to the function ReadQueryOfSDGs(), but ReadQueryOfSDGs() as written does not accept any arguments.  It's also not clear
    what ListSDGs represents...a list of files, names of queries? Also, the line
    For Each s In .selectedQuery in
    ReadQueryOfSDGs()
    references something called .selectedQuery which is undefined. 
    Is it that you want ReadQueryOfSDGs() to loop through the records returned by a query and add a field from each record to a collection?  If so, something like the following might better serve you:
    Public Function ReadQueryOfSDGs() As Collection
        Dim C As New Collection
        Dim rst As DAO.Recordset
        Set rst = DBEngine(0)(0).OpenRecordset("y_qs_DataIn_All_SDGList", dbOpenForwardOnly, dbReadOnly)
        Do Until rst.EOF
            C.Add rst!MyField ' where MyField is the field in y_qs_DataIn_All_SDGList you want to add to your collection
            rst.MoveNext
        Loop
        rst.Close
        Set rst = Nothing
        Set ReadQueryOfSDGs = C
    End Function

  • How to save the results of patindex into a variable?

    I would like to save the results of a patindex into a variable. The commented out line below is the line with the problem.
    CREATE TABLE #LocalTempTable(
    UserID int,
    UserName varchar(50),
    UserAddress varchar(150))
    insert #LocalTempTable (UserID,UserName,UserAddress) values (0,'user1','1209 West 9999 East|$75|this one')
    declare @var1 int
    set @var1 = -99
    select patindex('%West%', UserAddress) from #LocalTempTable
    --select patindex('%West%', UserAddress) into @var1 from #LocalTempTable
    select @var1
    -- The desired result would be a number 6 in the variable @var1

    Assume you will have a where condition as well:
    CREATE TABLE #LocalTempTable(
    UserID int,
    UserName varchar(50),
    UserAddress varchar(150))
    insert #LocalTempTable (UserID,UserName,UserAddress) values (0,'user1','1209 West 9999 East|$75|this one')
    --insert #LocalTempTable (UserID,UserName,UserAddress) values (0,'user1','1209 East 9999 East|$75|this one')
    declare @var1 int
    set @var1 = -99
    select @var1=patindex('%West%', UserAddress) from #LocalTempTable --where UserID=0
    --select patindex('%West%', UserAddress) into @var1 from #LocalTempTable
    select @var1
    Drop table #LocalTempTable

  • Trying to store result in xml format in variable sql server

    i am just trying to compare two xml and try to store the difference into another variable called
    @DiffXML but getting error called Incorrect syntax near the keyword 'SET'.
    just guide what to fix. thanks
    DECLARE @XML1 XML
    DECLARE @XML2 XML
    DECLARE @DiffXML nvarchar(max)
    SET @DiffXML=''
    SET @XML1 =
    '<NewDataSet>
    <Employee>
    <EmpID>1005</EmpID>
    <Name> keith </Name>
    <DOB>12/02/1981</DOB>
    <DeptID>ACC001</DeptID>
    <Salary>10,500</Salary>
    </Employee>
    </NewDataSet>'
    SET @XML2 =
    '<NewDataSet>
    <Employee>
    <EmpID>1006</EmpID>
    <Name> keith </Name>
    <DOB>05/02/1981</DOB>
    <DeptID>ACC002</DeptID>
    <Salary>10,900</Salary>
    </Employee>
    </NewDataSet>'
    ;with XML1 as
    select T.N.value('local-name(.)', 'nvarchar(100)') as NodeName,
    T.N.value('.', 'nvarchar(100)') as Value
    from @XML1.nodes('/NewDataSet/Employee/*') as T(N)
    XML2 as
    select T.N.value('local-name(.)', 'nvarchar(100)') as NodeName,
    T.N.value('.', 'nvarchar(100)') as Value
    from @XML2.nodes('/NewDataSet/Employee/*') as T(N)
    SET @DiffXML=(select * from
    select coalesce(XML1.NodeName, XML2.NodeName) as FieldName,
    XML1.Value as OldValue,
    XML2.Value as NewValue
    from XML1
    full outer join XML2
    on XML1.NodeName = XML2.NodeName
    where coalesce(XML1.Value, '') <> coalesce(XML2.Value, '')
    ) x FOR xml AUTO,elements XSINIL)
    print @DiffXML

    hey it is solved
    i should use select instead of set
    SELECT @DiffXML=(select * from
    select coalesce(XML1.NodeName, XML2.NodeName) as FieldName,
    XML1.Value as OldValue,
    XML2.Value as NewValue
    from XML1
    full outer join XML2
    on XML1.NodeName = XML2.NodeName
    where coalesce(XML1.Value, '') <> coalesce(XML2.Value, '')
    ) x FOR xml AUTO,elements XSINIL)
    print @DiffXML

  • 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

  • Parsing SOAP Results into Variables

    Can someone assist me in figuring out what way I need to go
    to parse SOAP results into an array?
    I have setup the <MX:WEBService> correctly, created my
    resultEvent(event) handler and faultEvenet(event) handler as
    needed. Below is the web service:
    <mx:WebService
    id="srvGetTagHistory" wsdl="{SOAP_URL}"
    result="CreateTagHistory(event)" fault="faultEvenet(event)"
    useProxy="false">
    <mx:operation name="GetTagHistory" resultFormat="e4x">
    <mx:request>
    <RSWID>{vRSWID}</RSWID>
    </mx:request>
    </mx:operation>
    </mx:WebService>
    This works perfectly. I can return the results of the
    webservice to a text area control, and the complete SOAP results
    are displayed.
    My problem is I cannot and have not figured out how to make
    the SOAP results into some type of arraycollection for using in,
    lets say, a dataGrid.
    Here is an example of a SOAP result for the above webservice:
    <NS1:GetTagHistoryResponse
    xmlns:NS1="urn:myresaleworldserviceIntf-myresaleworldserver"
    xmlns:NS2="urn:myresaleworldserviceIntf" xmlns:SOAP-ENV="
    http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="
    http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="
    http://www.w3.org/2001/XMLSchema-instance"
    xmlns:SOAP-ENC="
    http://schemas.xmlsoap.org/soap/encoding/">
    <NS2:return href="#1"/>
    <SOAP-ENC:Array id="1">
    <item href="#2"/>
    <item href="#9"/>
    <item href="#16"/>
    <item href="#25"/>
    <item href="#29"/>
    </SOAP-ENC:Array>
    <NS2:rswTagHistory id="2">
    <OrderDate>2005-12-08T11:15:24.857-05:00</OrderDate>
    <TagType>CB Tags</TagType>
    <NS2:ColorDetail href="#3"/>
    </NS2:rswTagHistory>
    <SOAP-ENC:Array id="3">
    <item href="#4"/>
    <item href="#5"/>
    <item href="#6"/>
    <item href="#7"/>
    <item href="#8"/>
    </SOAP-ENC:Array>
    <NS2:rswTagColorDetail id="4">
    <TagColor>Lavender</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="5">
    <TagColor>Light Blue</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="6">
    <TagColor>Green</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="7">
    <TagColor>Pink</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="8">
    <TagColor>Yellow</TagColor>
    <Total>1</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagHistory id="9">
    <OrderDate>2005-12-08T11:18:44.233-05:00</OrderDate>
    <TagType>CB Tags</TagType>
    <NS2:ColorDetail href="#10"/>
    </NS2:rswTagHistory>
    <SOAP-ENC:Array id="10">
    <item href="#11"/>
    <item href="#12"/>
    <item href="#13"/>
    <item href="#14"/>
    <item href="#15"/>
    </SOAP-ENC:Array>
    <NS2:rswTagColorDetail id="11">
    <TagColor>Lavender</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="12">
    <TagColor>Light Blue</TagColor>
    <Total>3</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="13">
    <TagColor>Green</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="14">
    <TagColor>Pink</TagColor>
    <Total>3</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="15">
    <TagColor>Yellow</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagHistory id="16">
    <OrderDate>2006-08-07T13:56:22.513-05:00</OrderDate>
    <TagType>CB Tags</TagType>
    <NS2:ColorDetail href="#17"/>
    </NS2:rswTagHistory>
    <SOAP-ENC:Array id="17">
    <item href="#18"/>
    <item href="#19"/>
    <item href="#20"/>
    <item href="#21"/>
    <item href="#22"/>
    <item href="#23"/>
    <item href="#24"/>
    </SOAP-ENC:Array>
    <NS2:rswTagColorDetail id="18">
    <TagColor>Lavender</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="19">
    <TagColor>Light Blue</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="20">
    <TagColor>Green</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="21">
    <TagColor>Orange</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="22">
    <TagColor>Pink</TagColor>
    <Total>1</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="23">
    <TagColor>Red</TagColor>
    <Total>2</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="24">
    <TagColor>Yellow</TagColor>
    <Total>1</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagHistory id="25">
    <OrderDate>2007-04-10T12:08:03.950-05:00</OrderDate>
    <TagType>CB Tags</TagType>
    <NS2:ColorDetail href="#26"/>
    </NS2:rswTagHistory>
    <SOAP-ENC:Array id="26">
    <item href="#27"/>
    <item href="#28"/>
    </SOAP-ENC:Array>
    <NS2:rswTagColorDetail id="27">
    <TagColor>Light Blue</TagColor>
    <Total>3</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagColorDetail id="28">
    <TagColor>Green</TagColor>
    <Total>1</Total>
    </NS2:rswTagColorDetail>
    <NS2:rswTagHistory id="29">
    <OrderDate>2007-12-19T12:52:30.883-05:00</OrderDate>
    <TagType>Thermal Tags</TagType>
    <NS2:ColorDetail href="#30"/>
    </NS2:rswTagHistory>
    <SOAP-ENC:Array id="30"/>
    </NS1:GetTagHistoryResponse>
    Any assistance to this issue would be greatly appreciated.

    If you have set resultFormat="e4x" than you can handle the
    result very easily.
    I guess you already find out that your result is in
    event.result.
    Your example is too hard to parse by human.
    You can read:
    http://livedocs.adobe.com/labs/flex3/html/help.html?content=13_Working_with_XML_01.html
    Especially: Traversing XML structures and Using XML
    namespaces
    I hope this will help

  • Store current Order from ShoppingCart.current into a variable..?

    Hi All,
    how to get current Order from /atg/commerce/ShoppingCart.current into a variable in ShoppingCart.jsp and use it in the Page instead of using ShoppingCart.current every time.
    Thanks,
    Vishnu

    Try this:
    <dsp:param name="order" bean="ShoppingCart.current"/>
    ${orde}
    or
    <dsp:getvalueof var="order" bean="ShoppingCart.current" vartype="atg.commerce.order">
    <body bgcolor="${order}" >
    </dsp:getvalueof>
    Peace
    Shaik

Maybe you are looking for

  • CSG2 Release 6 - Attribute Mapping

    Hi, I am currently configuring CSG2 in order to processed accounting services on ALL transactions generated when a single user visits YAHOO. It is done by matching attribute "host" against "*.yahoo.com". But I found 2 difficulties in this approach. B

  • Priority queues for external loading

    Hi, I was wondering if there was a way to load multiple external files (via the Loader class) in parrallel, but with a priority queue. That is, I want to load 5 images, but I want image 1 loaded as fast as possible. Obviously I could make my own load

  • Use of zero-pole.vi

    Hello! Can any body explain to me why the step-response of the given transferfunction depends on dt? Many thanks for your kind endavours Peter Attachments: Test Zero-Pole1.vi ‏42 KB

  • How to generate check from Payment Run

    How to generate check, if by mistake we forgot to check mark "Create payment medium" in payment run. Because the payment goes through but there is no check, Is there a transaction that can create a check from that payment run?

  • How to return to Lion?

    I bought a mid 2012 13" MBP last year with Lion installed. Later I upgraded to Mountain Lion. I originally successfully used it with a M-Audio Firewire 1814 audio interface. Now, having upgraded to ML, I'm having problems. Since M-Audio have declared