Substring in select statement

i have a selection screen where year is only input field, and in my table there is a date field, so i have to retrieve the data only of the given year only, so how do i substring the date field of that table and compare with my input in select statement

If your corresponding database table has the year field and you want to get the data according to the fiscal year
then try the following ways : .
parameters : p_date type datum. " Ur date field.
data : g _year type i.
at selection-screen:.
move p_date+0(4) to g_year.
Then pass g_year in your where clause.
or you can use the FM.
CALL FUNCTION 'GET_CURRENT_YEAR'
    EXPORTING
      bukrs = u2018ur company code'u2019
      date  = ur date field.
    IMPORTING
*      currm = fiscalmonth
      curry = g_year.
here also pass g_year in your where clause.
Regards
Abhinab.

Similar Messages

  • Substring in the select statement

    Hi,
    Have a table with 5 columns in it...
    Table A
    col1
    col2
    col3
    col4
    col5
    Want to retrieve some columns from that table using the select query, in which substring will be used to extract a part of string from each value contained in the col3 on executing select statement.
    How to use the substring in the select statement to perform the above?
    Regards

    What's wrong with <tt>SUBSTR(col3,4,2)</tt> etc? What do the other columns have to do with it?

  • Getting error while executing this select statement

    Hi All,
    I am new to this community.
    I am getting error whie compiling the below code. Its telling 'Text' is invalid identifier. Also i want to know how can we obtain 'parseable' version of the below query?
    my basic intention is to create a trigger header through a select statement and show it the complete text as a single column..
    select text from
    (select 'CREATE OR REPLACE TRIGGER '||SUBSTR(column_name,2,4)||'aud
    AFTER INSERT
    OR UPDATE
    OF '||column_name||',
    OR DELETE ON '||table_name||'
    FOR EACH ROW'
    FROM(SELECT lower(REPLACE(column_name,'O_','')) column_name , /*changing O to O_*/
    lower(replace(t.table_name,'_A_','_')) table_name,
    lower(t.table_name) table_name1,
    c.column_id
    FROM all_tab_columns c,
    (SELECT object_name table_name
    FROM all_objects
    WHERE object_name LIKE '%/_A/_%' ESCAPE '/') t
    WHERE c.table_name(+) = t.table_name
    AND SUBSTR(column_name(+),1,2) = 'O_'))

    thanks prathamesh. it solved the problem. i have one more question.
    as of now it creates single create trigger statement for each column on a table.
    example:
    CREATE OR REPLACE TRIGGER ust_aud
    AFTER INSERT
    OR UPDATE
    OF cust_id,
    OR DELETE ON characteristic_t
    FOR EACH ROW
    however, i want to create trigger for all columns in a single statement. can you please help me how to do it?
    basically want to 'CREATE TRIGGER' for all columns in a table. i am finding difficult how to change my query to suit this!!
    i am pasting my original query again for your reference. pls advise...
    example:
    CREATE OR REPLACE TRIGGER ust_aud
    AFTER INSERT
    OR UPDATE
    OF cust_id,
    fixed_item_val,
    copy_item_val,
    rgn_id,
    txn_id,
    OR DELETE ON characteristic_t
    FOR EACH ROW
    ORIGINAL QUERY
    select text from
    (select 'CREATE OR REPLACE TRIGGER '||SUBSTR(column_name,2,4)||'aud
    AFTER INSERT
    OR UPDATE
    OF '||column_name||',
    OR DELETE ON '||table_name||'
    FOR EACH ROW' text
    FROM(SELECT lower(REPLACE(column_name,'O_','')) column_name , /*changing O to O_*/
    lower(replace(t.table_name,'_A_','_')) table_name,
    lower(t.table_name) table_name1,
    c.column_id
    FROM all_tab_columns c,
    (SELECT object_name table_name
    FROM all_objects
    WHERE object_name LIKE '%/_A/_%' ESCAPE '/') t
    WHERE c.table_name(+) = t.table_name
    AND SUBSTR(column_name(+),1,2) = 'O_'))

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • Edit an object's select statement of OLAP universe SAP BW

    Hi everybody
    I am new at working with Olap Universes BW, and I have to edit one universe SAP BW, I don't know if I can to use substring function on a select statement, for example  substring([0D_DIV].[LEVEL01],5,5), I try to use this function but I have a error,
    Could you help me? I need to returns part of a string, is correct to do it on a universe or is better to do at BW.

    Hi,
    First of all I recommend you read the documentation that gives you information about OLAP universes and especially SAP BW universes.
    I also recommend to download documents related to SAP universes deployment, administration and customization:
    [OLAP Universes - how to samples and recommendations |https://wiki.wdf.sap.corp/wiki/display/globalregions/OLAPUniverses-howtosamplesand+recommendations]
    [SAP Integration |https://wiki.wdf.sap.corp/wiki/display/globalregions/SAP+Integration]
    Now you can customize expression using MDX in OLAP universes. MDX expressions must be enclosed with <EXPRESSION></EXPRESSION> XML tags.
    Unfortunately SAP BW MDX does not support calculations that return string or date values.
    The onlyway to return string is to use NAME or UNOIQUENAME attribute.
    See answers I already in the forum: [Forum answer |Re: Create new dimension on top of SAP BW data]
    Regards
    Didier

  • Decode in the select Statement

    Hi All,
    I am using the decode function in the select statement....but as i am using the group by in the select statement....i am not able to run the same query
    How to tackle this problem of handling the decode ....while we have group by also.
    This is bit urgent
    Thanks for your help
    Ramya

    Hi,
    Thanks for the quick reply.
    Here is the code...i have included the decode for the customer carrier code...
    SELECT c.trx_number invoice_number,
    c.trx_date invoice_date,
    ctl.sales_order_date order_date,
    c.ship_date_actual ship_date,
    c.purchase_order,
    ctl.sales_order order_number,
    olv.ordered_item item,
    msi.description item_description,
    olv.ordered_quantity quantity,
    olv.unit_selling_price unit_price,
    olv.unit_selling_price * olv.ordered_quantity amount,
    olv.tax_value,
    rc.customer_number,
    csta.customer_carrier_code,
    (SELECT decode(customer_carrier_code, NULL, 'Shipping & Handling', 'Shipping') sh
    FROM xx_cust_ship_to_addresses_v cstaa,
    ra_addresses ara
    WHERE cstaa.location_id = ad.location_id
    AND ara.location_id = ad.location_id) SH,
    rc.customer_name invoice_to_name,
    rct.name invoice_type,
    olv.sold_to,
    olv.ship_to_location,
    olv.ship_to_address1,
    olv.ship_to_address2,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -2, LENGTH(olv.ship_to_address5)) ship_to_country,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -9, 6) ship_to_postalcode,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -12, 2) ship_to_state,
    SUBSTR(olv.ship_to_address5, 1, LENGTH(olv.ship_to_address5) -15) ship_to_city,
    olv.invoice_to_address1,
    olv.invoice_to_address2,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -2, LENGTH(olv.invoice_to_address5)) invoice_to_country,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -9, 6) invoice_to_postalcode,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -12, 2) invoice_to_state,
    SUBSTR(olv.invoice_to_address5, 1, LENGTH(olv.invoice_to_address5) -15) invoice_to_city,
    olv.flow_status_code,
    olv.terms net_terms,
    olv.freight_terms_code freight_terms,
    olv.fob_point_code fob
    FROM ra_customer_trx_all c,
    ra_customer_trx_lines_all ctl,
    ra_cust_trx_types rct,
    jtf_rs_salesreps rs,
    ra_customers rc,
    ra_addresses ad,
    ra_site_uses su,
    mtl_system_items msi,
    oe_order_headers_v ohv,
    oe_order_lines_v olv,
    rcv_lot_transactions tl,
    rcv_shipment_lines sl,
    rcv_shipment_headers rsh,
    rcv_transactions rt,
    wsh_delivery_details wdd,
    xx_cust_ship_to_addresses_v csta
    WHERE to_char(ohv.order_number) = ctl.sales_order
    AND ctl.customer_trx_id = c.customer_trx_id
    AND c.cust_trx_type_id = rct.cust_trx_type_id
    AND c.org_id = rs.org_id
    AND c.primary_salesrep_id = rs.salesrep_id
    AND c.ship_to_site_use_id = su.site_use_id
    AND su.address_id = ad.address_id
    AND ad.customer_id = rc.customer_id
    AND ctl.inventory_item_id = msi.inventory_item_id
    AND ohv.header_id = olv.header_id
    AND olv.line_id = wdd.source_line_id(+)
    AND to_char(olv.line_id) = ctl.interface_line_attribute6
    AND tl.shipment_line_id = sl.shipment_line_id
    AND sl.shipment_header_id = rsh.shipment_header_id
    AND tl.transaction_id = rt.transaction_id
    AND csta.location_id = ad.location_id;
    GROUP BY c.trx_number,
    csta.customer_carrier_code,
    c.trx_date,
    c.creation_date,
    c.ship_date_actual,
    c.sold_to_customer_id,
    c.bill_to_customer_id,
    c.bill_to_site_use_id,
    c.ship_to_customer_id,
    c.ship_to_site_use_id,
    c.purchase_order,
    (SELECT decode(customer_carrier_code, NULL, 'Shipping & Handling', 'Shipping') sh
    FROM xx_cust_ship_to_addresses_v cstaa,
    ra_addresses ara
    WHERE cstaa.location_id = ara.location_id
    AND ara.location_id = ad.location_id),
    ctl.sales_order,
    ctl.sales_order_date,
    ctl.tax_rate,
    ctl.customer_trx_id,
    ctl.taxable_amount,
    rc.customer_number,
    olv.ordered_item,
    olv.unit_selling_price,
    olv.unit_list_price,
    olv.tax_value,
    olv.unit_cost,
    olv.ordered_quantity,
    rs.name,
    rc.customer_name,
    rc.customer_id,
    rc.party_id,
    rc.party_number,
    ad.address_id,
    rct.name,
    msi.description,
    olv.unit_selling_price * olv.ordered_quantity,
    c.org_id,
    ohv.header_id,
    olv.sold_to,
    olv.ship_from,
    olv.ship_to_location,
    olv.ship_to_address1,
    olv.ship_to_address2,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -2, LENGTH(olv.ship_to_address5)),
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -9, 6),
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -12, 2),
    SUBSTR(olv.ship_to_address5, 1, LENGTH(olv.ship_to_address5) -15),
    olv.invoice_to_location,
    olv.invoice_to_address1,
    olv.invoice_to_address2,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -2, LENGTH(olv.invoice_to_address5)),
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -9, 6),
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -12, 2),
    SUBSTR(olv.invoice_to_address5, 1, LENGTH(olv.invoice_to_address5) -15),
    olv.flow_status_code,
    olv.terms,
    olv.freight_terms_code,
    olv.shipping_method_code,
    olv.fob_point_code,
    olv.line_id,
    rsh.attribute1,
    rsh.attribute2,
    su.tax_code,
    su.ship_via,
    wdd.tracking_number
    ORDER BY invoice_number;

  • Benchmarks on select statements

    Hi,
    I'm during preparing test on select statement to check what clause cause the most slow down. Therefore I prepare 3 select statement:
    1) select which transform all columns in source table for oracle's functions like: substr, rpad, decode, nvl,upper, mod, greatest, length, power, instr etc..
    2) select with big where clause (about 7 lines) which take from 2 tables
    3) select which have where, group by, having and order by clauses
    Perhaps I will have first result today. But I am very interested what is your experience in this subject?? Which case cause the biggest slow down?
    Best.

    Hi Tut,
    what is your experience in this subject?? Every database is different, but in general:
    1) select which transform all columns in source table for oracle's functions like: substr, rpad, decode, nvl,upper, mod, greatest, length, power, instr etc..Very low overhead.
    2) select with big where clause (about 7 lines) which take from 2 tablesLong time to parse, and sometime Oracle does not get the cardinality right and joins the tables in the wrong order. To fix this issue:
    1 - apply histograms. I have my notes here: http://www.dba-oracle.com/art_otn_cbo_p4.htm
    2 - Use an ORDERED hint to enforce the best table join order: I have my notes here: http://www.dba-oracle.com/t_table_join_order.htm
    3) select which have where, group by, having and order by clausesJust make sure that you have a large enough PGA to void sorts to disk (sort_area_size, pga_aggregate_target)
    Hope this answers your questions . . .
    Donald K. Burleson
    Oracle Press author
    Author of "Oracle Tuning: The Definitive Reference":
    http://www.dba-oracle.com/bp/s_oracle_tuning_book.htm

  • ORA-24333 on Select Statement

    Last night I attempted to roll a Crystal Reports .NET project to my production web server. This app has 3 new Crystal Reports. The Reports are all based upon the same Oracle Views on the same Oracle Database. Two of the reports work while the third report returns an ORA-24333 error. The exact reports and .NET code, connecting to the same Oracle database work fine in Preview mode and when published to my development IIS web server. The ONLY thing that is different is that the report is now being run on the production IIS web server. (But it is still the same Oracle Database we are connecting to in all environments.)
    Here is the Command used for the Crystal Report that fails. Sorry it is so long. Basically, it is 4 Select statements joined together with Unions. Stuff in {} are parameters that are passed to it.
    SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.PROJECTNAME as ProjectName, A.INVOICENO as InvoiceNO, A.INVDATE, A.PAYDATE, A.ORDERNO as OrderNo, A.TOTALAMT as TotalAmt, A.ELIGIBLEAMT as EligibleAmt, A.SALESPOINTERD as SalesPointErd, 0 as FORFEIT, 0 as BONUSPOINTERD, 0 as PAYPTSEARNED, P.POINTPERCD as POINTPERCD, case when A.PAYDATE is null and A.INVDATE>SYSDATE-30 then round(P.POINTPERCD*A.ELIGIBLEAMT/100,0) else 0 end as PAYPTSELIG, case when A.PAYDATE is null and A.INVDATE>SYSDATE-30 then TO_CHAR(A.INVDATE+30,'MM/DD/YYYY') else '' end as PAYBYforPAYPTS
    FROM VW_TRIPPOINTS A
    left join VW_POINTS P on A.COMPANY=P.COMPANY and substr(A.FISCALPRD,1,4)=to_char(P.FISCALYEAR) and P.CODE='P'
    join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
    join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
    where A.POINTCODE='S' and A.COMPANY='30' and A.ELIGIBLEAMT<>0 and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
    Union --Bonus Points
    SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.Notes as ProjectName, Cast((Row_Number() over (Order By CustNo, OrderNo, InvoiceNo, IDKey)) as varchar(10)) as InvoiceNO, A.INVDATE, Null as PAYDATE, Cast((Row_Number() over (Order By IDKey)) as varchar(10)) as ORDERNO, Coalesce(A.TOTALAMT,0) as TotalAmt, Coalesce(A.ELIGIBLEAMT,0) as EligibleAmt, Coalesce(A.SALESPOINTERD,0) as SalesPointErd, 0 as FORFEIT, A.BONUSPOINTERD as BonusPointErd, 0 as PAYPTSEARNED, 0 as POINTPERCD, 0 as PAYPTSELIG, '' as PAYBYforPAYPTS
    FROM VW_TRIPPOINTS A
    join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
    join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
    where A.POINTCODE='B' and A.COMPANY='30' and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
    Union --Pay Points
    SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.PROJECTNAME as ProjectName, A.INVOICENO as InvoiceNO, A.INVDATE, A.PAYDATE, A.ORDERNO as OrderNo, 0 as TotalAmt, 0 as EligibleAmt, 0 as SALESPOINTERD, 0 as FORFEIT, 0 as BONUSPOINTERD, coalesce(A.PAYPOINTERD,0) as PAYPTSEARNED, 0 as POINTPERCD, 0 as PAYPTSELIG, '' as PAYBYforPAYPTS
    FROM VW_TRIPPOINTS A
    join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
    join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
    where (A.POINTCODE='P' or A.POINTCODE='C') and A.COMPANY='30' and A.PAYPOINTERD<>0 and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
    Union --Sales Points Forfeited
    SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.PROJECTNAME as ProjectName, A.INVOICENO as InvoiceNO, A.INVDATE, A.PAYDATE, A.ORDERNO as OrderNo, 0 as TotalAmt, 0 as EligibleAmt, 0 as SalesPointErd, Coalesce(A.SalesPointErd,0) as FORFEIT, 0 as BONUSPOINTERD, 0 as PAYPTSEARNED, 0 as POINTPERCD, 0 as PAYPTSELIG, '' as PAYBYforPAYPTS
    FROM VW_TRIPPOINTS A
    join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
    join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
    where A.POINTCODE='R' and A.COMPANY='30' and A.SalesPointErd<>0 and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
    order by custno, OrderNo, InvoiceNo

    Because we don't all have the Oracle error numbers and messages memorized:
    ORA-24333: zero iteration count
    Cause: An iteration count of zero was specified for the statement
    Action: Specify the number of times this statement must be executed

  • Convert NVARCHAR2 to VARCHAR2 in select statement

    I need to convert NVARCHAR2 values to VARCHAR2 in a select statement. Is this possible? The COUNTY_PARCEL_DATA colums are the NVARCHAR2 columns that need converting. I've tried TRANSLATE(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER USING CHAR_CS), CAST(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER AS VARCHAR2(100)), CONVERTCS(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER, 'CHAR_CS') and others directly in the statement for each column. Anything I'm missing? Thanks.
    SELECT BENEFICIARY.NAME_FIRST || ' ' || BENEFICIARY.NAME_LAST AS NAME,
    COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_DIRECTION
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_NAME
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_TYPE
    AS ADDRESS,
    COUNTY_PARCEL_DATA.SITUS_CITY AS CITY,
    'AZ' AS STATE,
    COUNTY_PARCEL_DATA.SITUS_ZIP AS ZIP,
    'T4' AS TRACER
    FROM BENEFICIARY
    LEFT OUTER JOIN
    VARS_PARCEL
    ON BENEFICIARY.AVNUM = VARS_PARCEL.AVNUM
    LEFT OUTER JOIN
    COUNTY_PARCEL_DATA
    ON VARS_PARCEL.APN = COUNTY_PARCEL_DATA.APN
    LEFT OUTER JOIN
    OWNER
    ON BENEFICIARY.BENEFICIARY_ID = OWNER.BENEFICIARY_ID
    WHERE (SUBSTR (VARS_PARCEL.AVNUM, 0, 4) IN
    (SELECT COLUMN_VALUE
    FROM TABLE(SPLIT_STRING (
    R_VARS_MAILING_NOTICES.NEIGHBORHOODS
    OR R_VARS_MAILING_NOTICES.NEIGHBORHOODS IS NULL)
    AND BENEFICIARY.BENEFICIARY_TYPE = 'Tenant';
    Edited by: Guddie on Apr 6, 2010 12:23 PM

    Are you doing the NVARCHAR2 to VARCHAR2 conversions everywhere, see comments below
    SELECT BENEFICIARY.NAME_FIRST || ' ' || BENEFICIARY.NAME_LAST AS NAME,
    COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER                        <==== Here, obviously
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_DIRECTION                <==== Here
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_NAME                        <==== Here
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_TYPE                        <==== Here
    AS ADDRESS,
    COUNTY_PARCEL_DATA.SITUS_CITY AS CITY,                            <==== Here
    'AZ' AS STATE,
    COUNTY_PARCEL_DATA.SITUS_ZIP AS ZIP,                                 <==== Here
    'T4' AS TRACER
    FROM BENEFICIARY
    LEFT OUTER JOIN
    VARS_PARCEL
    ON BENEFICIARY.AVNUM = VARS_PARCEL.AVNUM
    LEFT OUTER JOIN
    COUNTY_PARCEL_DATA
    ON VARS_PARCEL.APN = COUNTY_PARCEL_DATA.APN                   <==== Here, maybe not so obvious
    LEFT OUTER JOIN
    OWNER
    ON BENEFICIARY.BENEFICIARY_ID = OWNER.BENEFICIARY_ID
    WHERE (SUBSTR (VARS_PARCEL.AVNUM, 0, 4) IN
    (SELECT COLUMN_VALUE
    FROM TABLE(SPLIT_STRING (
    R_VARS_MAILING_NOTICES.NEIGHBORHOODS
    OR R_VARS_MAILING_NOTICES.NEIGHBORHOODS IS NULL)
    AND BENEFICIARY.BENEFICIARY_TYPE = 'Tenant';This is assuming that all fields in COUNTY_PARCEL_DATA are NVARCHAR2.
    Edited by: AlanWms on Apr 6, 2010 3:53 PM changed "joins" to "conversions" in 1st sentence.

  • Calling a user defined function in a select statement

    PLS-00231: function 'F_GET_PROJECT_ID' may not be used in SQL
    I am caling a user defined function 'F_GET_PROJECT_ID' in a select statement and getting the above error .
    Can any one help me to resolve it.
    I can not replace the function with a local variable nor can I assign the output of the function to a variable and use the variable in the sql stmt. cos, the in put parameters of the function comes from the same select statement.
    Please help
    Thanks in advance

    Can you provide your function code? Using a function like that is possible from the below example. I suspect something in your function code.
    SQL> create or replace function sample_func(p_sal number)
      2  return number
      3  is
      4  v_sal number;
      5  begin
      6     v_sal := p_sal+100;
      7     return v_sal;
      8  end;
      9  /
    Function created.
    SQL>
    SQL> select empno, ename, sal, sample_func(sal)
      2  from emp
      3  /
         EMPNO ENAME             SAL SAMPLE_FUNC(SAL)
          7839 KING             5000             5100
          7698 BLAKE            2850             2950
          7782 CLARK            2450             2550
          7566 JONES            2975             3075
          7654 MARTIN           1250             1350
          7499 ALLEN            1600             1700
          7844 TURNER           1500             1600
          7900 JAMES             950             1050
          7521 WARD             1250             1350
          7902 FORD             3000             3100
          7369 SMITH             800              900
          7788 SCOTT            3000             3100
          7876 ADAMS            1100             1200
          7934 MILLER           1300             1400
    14 rows selected.
    SQL>And yeah... your formatted code is this.
    cursor c1 is
       SELECT t.upi_nbr upi_nbr,
              f_get_project_id(l.pay_type_code,
                               l.charge_type_nme,
                               l.charge_code) project_id,
              LAST_DAY(TO_DATE(SUBSTR(t.Year_Month, 5, 2)||'/'||'01'||'/'||SUBSTR(t.Year_Month,1,4),
                               'MM/DD/YYYY'))reporting_period_end_date,
              SUM (c.hours_worked_qty) reported_hrs
       from trs.trs_timesheet@oraprod5 T,
            trs.trs_line@oraprod5 L,
            trs.trs_cell@oraprod5 C
    where T.upi_nbr=L.upi_nbr
    and T.year_month=L.year_month
    and L.row_nbr=C.row_nbr
    and L.upi_nbr=C.upi_nbr
    and L.year_month = C.year_month
    and L.invalid_activity_ind = 'V'
    and rtrim(L.charge_code) is not null
    AND L.Pay_Type_Code<>'REQ'
    and C.Hours_Worked_Qty > 0
    GROUP BY t.upi_nbr,
             t.year_month,
             t.oui_nbr,
             l.charge_code,
             l.activity_detail_code,
             l.charge_type_nme,
             l.pay_type_code;Cheers
    Sarma.

  • SQL insert with select statement having strange results

    So I have the below sql (edited a bit). Now here's the problem.
    I can run the select statement just fine, i get 48 rows back. When I run with the insert statement, a total of 9062 rows are inserted. What gives?
    <SQL>
    INSERT INTO mars_aes_data
    (rpt_id, shpdt, blno, stt, shpr_nad, branch_tableS, csgn_nad,
    csgnnm1, foreign_code, pnt_des, des, eccn_no, entity_no,
    odtc_cert_ind, dep_date, equipment_no, haz_flag, schd_no,
    schd_desc, rec_value, iso_ulti_dest, odtc_exempt, itn,
    liscence_no, liscence_flag, liscence_code, mblno, mot,
    cntry_load, pnt_load, origin_state, airline_prefix, qty1, qty2,
    ref_val, related, routed_flag, scac, odtc_indicator, seal_no,
    line_no, port_export, port_unlading, shipnum, shprnm1, veh_title,
    total_value, odtc_cat_code, unit1, unit2)
    SELECT 49, schemaP.tableS.shpdt, schemaP.tableS.blno,
    schemaP.tableS.stt, schemaP.tableS.shpr_nad,
    schemaP.tableM.branch_tableS, schemaP.tableS.csgn_nad,
    schemaP.tableS.csgnnm1, schemaP.tableD.foreign_code,
    schemaP.tableS.pnt_des, schemaP.tableS.des,
    schemaP.tableD.eccn_no, schemaP.tableN.entity_no,
    schemaP.tableD.odtc_cert_ind, schemaP.tableM.dep_date,
    schemaP.tableM.equipment_no, schemaP.tableM.haz_flag,
    schemaP.tableD.schd_no, schemaP.tableD.schd_desc,
    schemaP.tableD.rec_value,
    schemaP.tableM.iso_ulti_dest,
    schemaP.tableD.odtc_exempt, schemaP.tableM.itn,
    schemaP.tableD.liscence_no,
    schemaP.tableM.liscence_flag,
    schemaP.tableD.liscence_code, schemaP.tableS.mblno,
    schemaP.tableM.mot, schemaP.tableS.cntry_load,
    schemaP.tableS.pnt_load, schemaP.tableM.origin_state,
    schemaP.tableM.airline_prefix, schemaP.tableD.qty1,
    schemaP.tableD.qty2,
    schemaC.func_getRefs@link (schemaP.tableS.ptt, 'ZYX'),
    schemaP.tableM.related, schemaP.tableM.routed_flag,
    schemaP.tableM.scac, schemaP.tableD.odtc_indicator,
    schemaP.tableM.seal_no, schemaP.tableD.line_no,
    schemaP.tableM.port_export,
    schemaP.tableM.port_unlading, schemaP.tableS.shipnum,
    schemaP.tableS.shprnm1, schemaP.tableV.veh_title,
    schemaP.tableM.total_value,
    schemaP.tableD.odtc_cat_code, schemaP.tableD.unit1,
    schemaP.tableD.unit2
    FROM schemaP.tableD@link,
    schemaP.tableM@link,
    schemaP.tableN@link,
    schemaP.tableS@link,
    schemaP.tableV@link
    WHERE tableM.answer IN ('123', '456')
    AND SUBSTR (tableS.area, 1, 1) IN ('A', 'S')
    AND entity_no IN
    ('A',
    'B',
    'C',
    'D',
    'E',
    AND TO_DATE (SUBSTR (tableM.time_stamp, 1, 8), 'YYYYMMDD')
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'
    AND tableN.shipment= tableD.shipment(+)
    AND tableN.shipment= tableS.shipnum
    AND tableN.shipment= tableM.shipment(+)
    AND tableN.shipment= tableV.shipment(+)
    <SQL>
    Edited by: user11263048 on Jun 12, 2009 7:23 AM
    Edited by: user11263048 on Jun 12, 2009 7:27 AM

    Can you change this:
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'To this:
    BETWEEN TO_DATE('01-Mar-2009', 'DD-MON-YYYY')
    AND TO_DATE('31-Mar-2009','DD-MON-YYYY')That may make no difference but you should never rely on implicit conversions like that, they're always likely to cause you nasty surprises.
    If you're still getting the discrepancy, instead of and INSERT-SELECT, can you try a CREATE TABLE AS SELECT... just to see if you get the same result.

  • Need to wite pl sql procedure for dynamic select statement

    Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
    select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;

    I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
    TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM'))

  • SELECT statement throwing error in Pro*C

    Hi All,
    I have a Pro*C report that I am creating and the selmacro in the report has a SQL statement like
    EXEC SQL DECLARE cursor_000 CURSOR FOR
    SELECT (select 'Y' from dual)
    FROM spriden
    WHERE spriden_change_ind IS NULL;
    Now this throws me an error saying :
    Syntax error at line 538, column 16, file tzrages.pc:
    Error at line 538, column 16 in file tzrages.pc
    SELECT (select 'Y' from dual)
    ...............1
    PCC-S-02201, Encountered the symbol "'Y'" when expecting one of the following:
    ( ) * + - / . @ | at, day, hour, minute, month, second, year,
    Syntax error at line 1954, column 16, file tzrages.pc:
    Error at line 1954, column 16 in file tzrages.pc
    FROM DUAL;
    My Observation is that when I put a "select" statement in the select clause of the SQL, it throws the error. However if I write the query with out the "SELECT" in the select clause, it works just fine.
    Any clues on this. I need to have multiple "Select" statements in the SELECT clause, and cannot do without it.

    Thanks Satrap and Billy for replying to the post. Appreciate it.
    What the query actually looks like is
    SELECT college_name
    ,college_location
    ,student_category
    ,sum(30_day_balance)
    ,sum(60_day_balance)
    ,sum(90_day_balance)
    FROM ( SELECT college_name
    ,college_location
    , NVL ( (SELECT DECODE (substr(A.company_id,1,1)
    ,'V','Bad Debt'
    ,'D','Active SAC'
    FROM company_table A
    ,collections_table C
    WHERE C.student_id = B.student_id
    AND C.collector_id = A.collector_id
    ), 'Active'
    ) STUDENT_CATEGORY
    , ( SELECT NVL ( SUM ( D.balance),0)
    FROM balance_table D
    WHERE D.balance_date BETWEEN to_date(:report_run_date) - 30 AND to_date (:report_run_date)
    AND D.collection_code = :collection_code
    AND D.student_id = B.student_id
    ) 30_DAY_BALANCE
    , ( SELECT NVL ( SUM ( D.balance),0)
    FROM balance_table D
         WHERE D.balance_date BETWEEN to_date(:report_run_date) - 60 AND ( to_date (:report_run_date) - 30 + 1)
    AND D.collection_code = :collection_code
         AND D.student_id = B.student_id
         ) 60_DAY_BALANCE
         , ( SELECT NVL ( SUM ( D.balance),0)
    FROM balance_table D
         WHERE D.balance_date BETWEEN to_date(:report_run_date) - 90 AND ( to_date (:report_run_date) - 60 + 1)
    AND D.collection_code = :collection_code
         AND D.student_id = B.student_id
         ) 90_DAY_BALANCE
         FROM student_table B
         WHERE B.student_id IN ( SELECT E.student_id
         FROM collections_table E
         WHERE E.collection_code = :collection_code
         GROUP BY E.student_id
         HAVIN SUM(E.balance) BETWEEN :min_balance AND :max_balance
    GROUP BY college_name,college_location,student_category
    Please note that anything with a ':' as a prefix (:collection_code,:max_balance) is a parameter for the Query
    When I run the query in toad, it works fine, but when I compile it in Pro*C it throws an error as mentioned in the previous post.

  • Using a varchar field to select statement

    Hi all
    I have a single row and single column table
    T(command varchar2(4000))
    and the row is
    sno,name
    And I have another table T1(sno number,name varchar)
    Now can any body tell how can i use command column in table T to query T1 to get sno,name from T1
    I am looking for a select statement like this
    select (select command from T) from T1;
    but it is printing out the data in T i mean sno, name
    This is a copy of thread Selecting output of a select statement
    but explained more clearly
    Thanks,
    ganesh.

    I don't know why your tables are designed like this but what I think you want to do is join T1 with the data in T.
    select sno, name from T1
    where sno in (select substr(command,0,instr(command,',')-1) from T)
    and name in (select substr(command,instr(command,',')+1) from T);
    substr returns a string up to a position
    instr returns the position of a string
    and the other post you refer to as about as confusing as your one.

  • How to create a cursor on a union select statement?

    Hi,
    Using Oracle 10g RAC +ASM ( RELEASE 1002000300)
    What are is the proper way to create a cursor on a union select statement?
    Is it possible?
    code lines, Results in PLS-00201 error: sT := crsR.STATUS; sS := crsR.TIME;
    Procedure listed below:
    CREATE OR REPLACE PROCEDURE BUILD_SUMMARY IS
    CURSOR csrO IS
    SELECT
    STATUS,
    TIME
    FROM (
    SELECT
    SUBSTR(DESCRIPTION,1,50) STATUS,
    TO_CHAR(TIMESTAMP,'MM/DD/YY hh12:mi:ss') TIME
    FROM GLOBALSALES.CUBE_STATUS
    UNION ALL
    SELECT
    ' TOTAL BUILD TIME',
    TO_CHAR(TO_DATE('00:00:00','HH24:MI:SS') +(MAX(TIMESTAMP) - MIN(TIMESTAMP)), 'HH24:MI:SS')
    FROM GLOBALSALES.CUBE_STATUS);
    csrR csrO%ROWTYPE;
    sT LONG :='';
    sS LONG :='';
    BEGIN
    FOR csrR IN csrO
    LOOP
    sT := crsR.STATUS;
    sS := crsR.TIME;
    DBMS_OUTPUT.PUT_LINE(sT || ' ' || sS);
    END LOOP;
    END;
    /

    csrR csrO%ROWTYPE;
    Declares the csrR correct? Cursor Record of Cursor Object Type?That line declares one variable CSRR with your column structure described by the cursor (CSRO) type you declared above it. It means the CSRR variable has the columns you had in the SELECT statement in that cursor.
    When you run a cursor as you did you don't need to declare the record variable. Try this:
    CREATE OR REPLACE PROCEDURE build_summary IS
      CURSOR csro IS
        SELECT status, TIME
          FROM (SELECT substr(description, 1, 50) status, to_char(TIMESTAMP, 'MM/DD/YY hh12:mi:ss') TIME
                  FROM globalsales.cube_status
                UNION ALL
                SELECT ' TOTAL BUILD TIME',
                       to_char(to_date('00:00:00', 'HH24:MI:SS') + (MAX(TIMESTAMP) - MIN(TIMESTAMP)),
                               'HH24:MI:SS')
                  FROM globalsales.cube_status);
      --csrr csro%ROWTYPE;
      st   LONG := '';
      ss   LONG := '';
    BEGIN
      FOR csrr IN csro
      LOOP
        st := csrr.status;
        ss := csrr.time;
        dbms_output.put_line(st || ' ' || ss);
      END LOOP;
    END;Also why are you using LONG? It's a deprecated data type and Oracle recommends against using it. Either pick varchar2(4000) or CLOB.
    DBMS_OUTPUT.PUT_LINE will implicitly convert that LONG data type anyway.

Maybe you are looking for

  • In Business One, is the transaction time stored anywhere?

    Working with SAP Business One 2005 SP1 PL:29 The accounting team would like to know what time each transaction happened.  So far all I can see is the created date and update date on the transactions(OJDT) and in the Change Log (ADJT). Primarily this

  • Error in release procedure

    Hi Im facing an error in the release of PO. When item 0010 in the purchase order is either blocked or deleted the release indicator is not set in the ALV list of ME28. The PO is visible in the list but it is not possible for the users to release the

  • How to do outer join in data model view?

    Hi, I have 2 queries are needed to be joined in Oracle Report 6i Data Model View. What I want to do is below: where table1.receipt_no(+)=table2.receipt_no How do I use the 'Data Link' to do this in Data Model view? Thanks. Jun

  • How to disable Password field in Oracle User administration

    Hi , How can I personalize the password field on the user - define form not updatable ? I have tried forms personalization on this field but it didnt work. Can anyone have an idea whether this field can be personalized at all Thank you in advance !

  • IDOC Status message

    HI I have to pick IDOC status message in my report program.  For this I am referring the table EDIDS. My doubt is some times the IDOC status message is storing in the field ‘STATXT’ and some times the idoc status message is storing in the fields STAP