Formatting of the Select query

The following select query returns the data in green.  How do I format to return the path that it is formatted in red?

Basically, if FIELD1 is "Customer A" and FIELD2 is "Gas" then I back to 'New customer' Field1 and Field2 'gas '.  If 'Customer E' FIELD1 and FIELD2 is 'Total' then it should return 'E rejection' in Field1 and 'Prod_Discharge' in the Field2.

Please let me know if my question is not sensible or need to be clarified.

SELECT

DECODE (Field1, 'Nine', ' A', 'Old', 'E', 'Term', 'F', Field1)

DECODE (Field2, 'Prod', 'Gas', Field2)

Customers

FIELD1 FIELD2

Customer A gas

Customer has oil

Total customers E

Customer F Total

Need to format as follows:

Field1 Field2       

New gas customer          

New customer oil      

E Prod_Discharged releases          

F Prod_Discharged releases

Try this:

SELECT CustomerID

, CASE WHEN field1 = 'Customer A' THEN 'new customer '.

WHEN field1 = 'Customer E' AND field2 = 'Total' THEN 'E releases '.

WHEN field1 = ' customer F ' AND field2 = 'Total' THEN 'F performs ".

Of ANOTHER Field1

FIELD1 AS END

, CASE WHEN Field1 IN ('E of customer', ' customer F ') AND field2 = 'Total' THEN 'Prod_Discharged '.

Of OTHER Field2

END AS FIELD2

Status

Customers

;

Tags: Database

Similar Questions

  • How to store results of the select query in the tables.

    I created a variable varray type and now want to assign some data of output of the select query in pl/SQL, as well as in reports 6i.

    You are in the wrong forum (this is for problems with the SQL Developer tool). You were the one where you have published first on the right, but not to reuse independent threads as you did.

    Kind regards
    K.

  • The select query-based search page...

    I want to create a basic search page at the base on a select query.

    The select query will not be based on Table.Its based on functions.

    I created a view like this object

    Select xx_test_accruals(:p_date) of ACCUMULATION: p_date double DT

    I created a search page

    In the area of provision of Home Page, I added a region of the query. In this region of request I created a result based research Table.

    When I run the page opens with the field

    DT

    When I get back the date and click go, I get the error message like this...

    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: 27122 Houston: SQL error in the preparation of the statement. Statement: SELECT * FROM (select xx_test_accruals(:p_date) of ACCUMULATION: p_date double DT) QRSLT WHERE ((UPPER (DT) like: 1 AND (DT as: 2 OR DT as: 3 OR DT as: 4 OR DT as: 5)))



    Help, please

    Published by: [email protected] on October 4, 2009 14:04

    Hello

    I tried it on my machine... There is a little change on the approach.

    See we have a display object: XxAccrualsSummaryVO

    the query is

    Select xx_test_accruals (to_date (: 1, 'YYYY-MM-DD')) DT ACCRUAL, double to_date(:2,'YYYY-MM-DD')

    Create a view property object: say DateTestPVO and create a transitional DATE type attribute say dated. MinValue. How to create the View Object(read in dev guide) property.

    Link the date to DateTestPVO text entry and the date attribute. MinValue.

    Now that the page will load in process request initialize the PVO not XxAccrualsSummaryVO.

    Public Sub initialisePVO()
    {

    OAViewObject vo = (OAViewObject) getDatePVO1 ();
    If (! vo.isPreparedForExecution ())
    {
    vo.setMaxFetchSize (0);
    }
    Line = vo.createRow ();
    vo.insertRow (row);
    row.setNewRowState (Row.STATUS_INITIALIZED);

    }

    And when you press the Go button and then enter the date entered and set the location where the XxAccrualsSummaryVO clause.

    If (PageContext.GetParameter ("Go")! = null)
    {
    Get the value entered by the user in the date field.

    DateField OAMessageDateFieldBean = (OAMessageDateFieldBean) webBean.findIndexedChildRecursive ("text");
    String datetest = (String) dateField.getValue (pageContext) m:System.NET.SocketAddress.ToString ();
    Now set the where clause VO settings.
    OAViewObject vodate = (OAViewObject) am.findViewObject ("invoicetestVO1");
    vodate.setWhereClauseParams (null);
    vodate.setWhereClauseParam(0,datetest);
    vodate.setWhereClauseParam(1,datetest);
    vodate.executeQuery ();
    }

    It works perfectly... I tested it.

    Thank you
    Gerard

  • How to optimize the select query executed in a cursor for loop?

    Hi friends,

    I run the code below and clocked at the same time for each line of code using DBMS_PROFILER.
    CREATE OR REPLACE PROCEDURE TEST
    AS
       p_file_id              NUMBER                                   := 151;
       v_shipper_ind          ah_item.shipper_ind%TYPE;
       v_sales_reserve_ind    ah_item.special_sales_reserve_ind%TYPE;
       v_location_indicator   ah_item.exe_location_ind%TYPE;
    
       CURSOR activity_c
       IS
          SELECT *
            FROM ah_activity_internal
           WHERE status_id = 30
             AND file_id = p_file_id;
    BEGIN
       DBMS_PROFILER.start_profiler ('TEST');
    
       FOR rec IN activity_c
       LOOP
          SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
                     INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
                     FROM ah_item --464000 rows in this table
                    WHERE item_id_edw IN (
                             SELECT item_id_edw
                               FROM ah_item_xref --700000 rows in this table
                              WHERE item_code_cust = rec.item_code_cust
                                AND facility_num IN (
                                       SELECT facility_code
                                         FROM ah_chain_div_facility --17 rows in this table
                                        WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                                          AND div_id = (SELECT div_id
                                                          FROM ah_div --8 rows in this table 
                                                         WHERE division = rec.division)));
       END LOOP;
    
       DBMS_PROFILER.stop_profiler;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN TOO_MANY_ROWS
       THEN
          NULL;
    END TEST;
    The SELECT inside the LOOP FOR cursor query took 773 seconds.
    I tried to use COLLECT in BULK instead of a cursor for loop, but it did not help.
    When I took the select query separately and executed with a value of the sample, and then he gave the results in a Flash of a second.

    All tables have primary key index.
    Any ideas what can be done to make this code more efficient?

    Thank you
    Raj.
    DECLARE
      v_chain_id ah_chain_div_facility.chain_id%TYPE := ah_internal_data_pkg.get_chain_id (p_file_id);
    
      CURSOR cur_loop IS
      SELECT * -- better off explicitly specifying columns
      FROM ah_activity_internal aai,
      (SELECT DISTINCT aix.item_code_cust, ad.division, ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
         INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
         FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
        WHERE ai.item_id_edw = aix.item_id_edw
          AND aix.facility_num = acdf.facility_code
          AND acdf.chain_id = v_chain_id
          AND acdf.div_id = ad.div_id) d
      WHERE aai.status_id = 30
        AND aai.file_id = p_file_id
        AND d.item_code_cust = aai.item_code_cust
        AND d.division = aai.division;         
    
    BEGIN
      FOR rec IN cur_loop LOOP
        ... DO your stuff ...
      END LOOP;
    END;  
    

    Published by: Dave hemming on December 4, 2008 09:17

  • passing parameters to the select query in DB link to call him...

    I have a DB link that executes the select query based on user specified parameter.

    Now, I created an invoke activity and specified input [which must be passed to the query] and output parameters [it is the result of the query]. That invoke link activity DB calls in which a parameter was created to be used in the select query. So my question is, DB link partner take the input parameter of call activity automatically or do we need to specify a mapping for this?

    When you create a partnerlink db the setting that you create for your chosen matches the entry and when you create the variable entry in the invoke for this partnerlink is created with the type of the parameter.

    Create an assignment before your invoke and assign a value to the input variable that you created in the invoke. This value will be passed and used as a parameter in the selection.

    Heidi.

  • When I pull the select query, but therefore cannot get the data that you check?

    Hello

    When I raised this query without get data then can you help me it's ok?

    DataSource {
                            id: durgSearch_dataSource
                            source: "sql/durg.db"
                            query: "select * from durg_detail where durg_name =" + "\"" + searchTextField.text + "\""
                            onDataLoaded: {
                                durgSearch_dataModel.insertList(data);
                            }
                        }
    

    Glance. I just tested your app and it works correctly. I entered Rock and search button and it returns a Rock record. If you want to get all records that contain a particular letter or Word, you can use the following query:

    "select * from medicin_detail where PharmacyName LIKE '%" + searchTextField.text + "%'"
    
  • Error in the SELECT query

    Hello

    Oracle version: 11g R2 (11.2.0.2)

    I get the following error message (I'm using TOAD for Oracle last version 12.1):

    ORA-12801: error reported in the parallel query P032 Server

    ORA-01114: block write IO file error (block #)

    ORA-01114: IO error to the file 201 (block # 2165248) writing block

    ORA-27072: IO file error

    Linux-x86_64 error: 28: no space is available on the device

    Additional information: 4

    When you run a SELECT query:

    SELECT field1, Field2...

    OF (REVENUE_SOURCE b

    INNER JOIN ACCOUNTS_CLASSIFICATION one

    WE b.SUB_ACCOUNT = a.SUB_ACCOUNT)

    INNER JOIN REPORT_PRODUCT_ID c

    ON b.REPORT_PRODUCT_ID = c.REPORT_PRODUCT_ID

    WHERE a.UC_BUSINESS_UNIT = 'ANX.

    AND b.report_mm > =.

    (SELECT ADD_MONTHS (MAX (report_mm),-13))

    OF REVENUE_SOURCE)

    AND b.REVENUE_FLAG = - 1

    AND (b.CALLS <>0 b.MINUTES <>0 b.CHARGE_AMOUNT GOLD <>GOLD 0);

    Please notify.

    NOTE: the query worked well for a while, no errors, then all suddenly it became much accentsr and then I started to get the error message above.

    Kind regards

    M.R.

    Hello

    ORA-27072: IO file error

    Linux-x86_64 error: 28: no space is available on the device

    Looks like a system or OS, no SQL or PL/SQL problem problem.  I think you will answer sooner if you check this issue as 'Response' and start a new question in the forum of "General Question":

    https://forums.Oracle.com/community/Developer/English/oracle_database/general_questions/content

    My guess is that Oracle tries to allocate space in the tablespace temp, but cannot because the disk is full.  If you have a full disk, then create the space to this topic.

    I see nothing wrong with your code; Certainly, nothing which would cause an error like that.  The fact that the query has worked well for some time confirms that there is noting wrong with the request itself; It is just triggering a mistake elsewhere.

  • as with the select query

    Hello

    I have a query something like...

    Select...

    ....

    where

    b.ProdName as 'GEAR of the TREE %' or b.prodname like '% FRONT GEAR %' or b.prodname like '% BREAK 4 %k '.

    and

    b.ProdName as

    (select the name of the society of companyms

    where < some comdition >

    )

    order of 3.6

    I have blocked in:

    b.ProdName as

    (select the name of the society of companyms

    where < some comdition >

    )

    How to give a select query with like operator.

    In above query I want to b.prodname as above and the name of the company for which I give condition.  Company names are stored in another table and I want to select and use them with like operator.

    Thank you.

    Hello

    It is not clear what you want to do.

    One possibility is an EXISTS subquery, like this:

    ...

    WHERE (b.prodname LIKE "% of the CYCLE of the TREE" - begins with this text

    OR b.prodname LIKE '% FRONT GEAR %' - contains this text

    OR b.prodname LIKE '% BREAK 4 %k' - contains this text

    )

    AND THERE ARE)

    SELECT 1

    OF companynms

    WHERE--a condition

    AND b.prodname AS business

    )

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • How to write the select query for it

    Hello

    I had an html form and the area I drop down and he needs to select several values in the drop-down box. When I select multiple values then I have to write the query to SQL select statement.

    When I try to write the select statement and trying to run I get the error message.

    Select * from Table

    where emo_no = '1,2,3 '.

    That's how I write the query please suggest me how to write the query to select several values in the drop-down box.

    Thank you

    Use the keyword sql 'in '.  If you don't know how, I've heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta.

  • Unable to display in the select query status

    Dear all,

    I have the case. I want to select data in difficult condition. I have three table follow:
    CREATE TABLE "TABLE1" ("vID" CHAR(2)
    ,"vDesc" varchar2(500)
    ,CONSTRAINT "PK_TEST_RTK1" PRIMARY KEY ("varID"));
    
    CREATE TABLE "TABLE2" ("varID" CHAR(2),"vID" CHAR(2)
    ,"varContent" varchar2(500)
    ,CONSTRAINT "PK_TEST_RTK2" PRIMARY KEY ("varID"));
    
    CREATE TABLE "TABLE3" ("variableID" CHAR(2)
    ,"variableDesc" varchar2(500)
    ,CONSTRAINT "PK_TEST_RTK3" PRIMARY KEY ("varID"));
    
    select * from TABLE1;
    vID | vDesc
    A1 | JAKARTA
    A2 | BANDUNG
    
    select * from TABLE2;
    varID | vID | vContent
    B1 | A1 | 121,222
    B2 | A2 | 444,334
    
    select * from TABLE3;
    variableID | variableDesc
    121 | goods1
    222 | goods2
    334 | goods3
    444 | goods4
    Then, I was query as below:
    select a.vID,a.vDesc,c.variableDesc,''''||replace(b.vContent,',',''',''')||'''' xxx
    from TABLE1 a 
    inner join TABLE2 b on a.vID=b.vID
    left join TABLE3 c on c.variableID in (''''||replace(b.vContent,',',''',''')||'''')
    the result is:
    vID | a.vDesc | c.variableDesc | xxx
    A1 | JAKARTA | | 121,222
    A2 | BANDUNG | | 444,334
    Why the c.variableDesc is null?
    What is the query assumes that the result only 1 as parameter below?
    c.variableID in (''''||replace(b.vContent,',',''',''')||'''') --> c.variableID in ( {'121','222'} )
    c.variableID in (''''||replace(b.vContent,',',''',''')||'''') --> not c.variableID in ( {'121'},{'222'} )
    Please please need your help. Thnks a lot.

    Published by: BluShadow on August 23, 2011 13:47
    applied {noformat}
    {noformat} tags.  Please read {message:id=9360002} to learn to format you code/data yourself.
    
    
    sorry correct
    
    CREATE TABLE "TABLE1" ("vID" CHAR(2)
    ,"vDesc" varchar2(500)
    ,CONSTRAINT "PK_TEST_RTK1" PRIMARY KEY ("vID"));
    
    CREATE TABLE "TABLE2" ("varID" CHAR(2),"vID" CHAR(2)
    ,"varContent" varchar2(500)
    ,CONSTRAINT "PK_TEST_RTK2" PRIMARY KEY ("varID"));
    
    CREATE TABLE "TABLE3" ("variableID" CHAR(2)
    ,"variableDesc" varchar2(500)
    ,CONSTRAINT "PK_TEST_RTK3" PRIMARY KEY ("variableID"));
    
    Edited by: Rahardi Trisna on Aug 23, 2011 7:15 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    Hello

    You need something like this:

    select  a.vID
    ,     a.vDesc
    ,     c.variableDesc
    ,     '''' || replace (b.vContent,',',''',''') || ''''     xxx
    from          TABLE1  a
    inner join  TABLE2  b  on   a.vID  = b.vID
    left join   TABLE3  c  on   0        < INSTR ( ',' || b.vcontent   || ','
                                                         , ',' || c.variableid || ','
                                )
    ;
    

    If you would care to post CREATE TABLE and INSERT instructions for the sample data, and then I could test it.

    Do not forget how TO MARKET:

    x to (y1, y2,..., yn)

    Returns TRUE if x is equal to one of the ys (there may be 1 to 50 points in the list). In your case, x is perhaps a 3 shot characters like "222", and there is only 1 point in the list, a long string such as

    '121','222'
    

    This string contains 11 characters, it will not equal to any string that contains only 3 characters.

  • SQL question - define multifields to a variable to use in the select query

    Hello

    I classified a, b, c, d, e,... good fields in Table1.

    my query is: select d, f, g, a, c from Table1

    I want to set these fields in a variable like y and use in a query select as below;

    y = "d, f, g, a, c '.

    Select y from Table1

    How can I achieve this?

    Kind regards

    Mustafa

    Hi, Mustafa,

    Sorry, I don't know anything about SQL Developer.

    Close this thread and start a new thread in the forum SQL Developer:

    https://forums.oracle.com/community/developer/english/development_tools/application_development_in_pl_sql/sql_developer _(not_for_general_sql_plsql_questions)

  • Transient attribute based on the selected query by using a function call

    Hello

    Post version is 11.1.1.7.0 JDeveloper.

    I'm not able to get the following work properly;

    1. I have a scenario header / detail.
    2. Calculate a value for each row returned detail that I find. This calculation is done using an existing database to function.
    3. The function requires 3 input parameters.
    4. Two of these parameters can be retrieved in the detail row and one is a value which is on the header.
    5. I created a transient attribute on the object of the detail view and selected the following properties of the 2 attribute;
      1. Mapped to the column or SQL
      2. Selected in SQL
    6. I entered the following SQL Expression;
      1. function_name (DetailTableAlias.value1, DetailTableAlias.value2, ViewLinkName.value3)
    7. Running AOS that contains the objects of view header / detail, I encounter a SQL error which indicates that ViewLinkName.value3 is an invalid identifier.
      1. I can understand why this error occurs.
    8. If I change the ViewLinkName.value3 to a literal value, the error will not occur.

    So, my question is how can I pass the third parameter to the transitional attribute database function call as the value literal and not as a reference to one, missing attachments header table, column?

    Concerning

    Leon.

    Hi Leon

    Have you explored solve this by an inline SQL query to derive the 3rd parameter of the function? In other words, the problem in SQL instead of ADF.

    DMI

  • Date formatting of the af:query component in ADF

    Hello

    I use < af:query > ADF Component.It is linked to a VO through which attributes are displayed in the search.

    "I have a date component in the vo and want the date format you should see 6 August 2013. How can I achieve this?

    You can set a date in full flight format the VO, go to 'Attributes' and double-click the attribute. In the window go to 'tips control. Choose "Simple Date" in the "Format Type" field. Then enter the size you want to be applied in the field 'Format' (e.g. dd-MMM-yyyy).

    Kind regards

    Linda

  • provide multiple values to the select query IN

    Hello

    I just wanted to know if there is a more effective way to provide values for my statement SELECT. Is what we do, gives us an excel file that contains a single column of serial numbers then we format the content so that it can be read by pl sql. By format, I mean put single quotes on the serial numbers, then separate then by comma.

    Like, we are sent

    8181818181818
    2323123525241
    1231231231234

    Then we have to get in shape to look like this (using formulas in excel)

    '8181818181818',
    '2323123525241',
    '1231231231234'

    in the process, I have to do a lot of copy and pasting that seems to take a long time.

    So, is there a way to make the process of sql pl serial passed to me as an excel file or is there any other alternative methods can I use?

    TABLE EXTERNAL research

  • Help in the Select query

    Dear all,

    I have oracle 10 G R2 on windows.

    Here's my query: -.


    Select a.foliono, a.schcode, sum (a.amount) - sum (b.amount) as Difference_Amount of
    processed_tran_split a, systematic_purchase b
    where a.folio = b.folio and a.schcode = b.schcode and a.trxntypcod = 'P' and a s = .trxsubtypc ' and
    Difference_Amount > 0
    A.foliono group, a.schcode


    When I run above the query identifier not valid to say "Difference_Amount".

    My need is foliono, schcode and processed_tran_split less systematic_purchase amount and the amount that results must be > 0.



    Help, please.




    Saludos.
    CHanchal Wankhade.

    Modification of the request as below

    select a.foliono,a.schcode,sum(a.amount)-sum(b.amount)as Difference_Amount from
    processed_tran_split a, systematic_purchase b
    where a.folio=b.folio and a.schcode=b.schcode and a.trxntypcod='P' and a.trxsubtypc='S' and
    group by a.foliono,a.schcode
    HAVING sum(a.amount)-sum(b.amount) >0
    

    Concerning
    Arun

Maybe you are looking for