A query with line numbers and colum?

Hello
I have my java code divided into if conditions and each if the article I need to select a certain field in a table. Is it somehow possible to select a table field that for example is in the third row and the fifth column? So basically, how to choose a certain element of the matrix?

Thanks :)

Published by: user10956166 on April 5, 2009 06:09

Hello

Assuming that you have a table called Distance:

Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr

SQL> DESCRIBE DISTANCE;
Name    Type         Nullable Default Comments
------- ------------ -------- ------- --------
LINN    VARCHAR2(30) Y
TALLINN NUMBER       Y
TARTU   NUMBER       Y
P2RNU   NUMBER       Y                         

SQL> select * from distance;

LINN                              TALLINN      TARTU      P2RNU
------------------------------ ---------- ---------- ----------
TALLINN                                 0        186        128
TARTU                                 186          0        174
P2RNU                                 128        174          0

SQL>
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
  2     v_sql         VARCHAR2(4000);
  3     v_column_name VARCHAR2(30):= 'TARTU';
  4     v_to          VARCHAR2(30):= 'P2RNU';
  5     v_distance    NUMBER;
  6  BEGIN
  7     v_sql := 'SELECT ' || v_column_name || ' FROM DISTANCE d WHERE d.LINN = ''' || v_to || '''';
  8     EXECUTE IMMEDIATE v_sql
  9        INTO v_distance;
 10
 11     dbms_output.put_line(v_distance);
 12
 13  EXCEPTION
 14     WHEN OTHERS THEN
 15        dbms_output.put_line(SQLERRM);
 16  END;
 17  /

174

PL/SQL procedure successfully completed

SQL> 

Kind regards

Tags: Database

Similar Questions

  • Write a SQL query with lines in columns

    All the

    I need help in writing a SQL query with lines in columns, let give u an example...

    drop table activity;

    CREATE TABLE 'ACTIVITY '.

    (

    "PROJECT_WID" NUMBER (22.0) NOT NULL,

    VARCHAR2 (150 CHAR) "PROJECT_NO."

    VARCHAR2 (800 CHAR) 'NAME '.

    );

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');

    drop table lonet;

    CREATE TABLE 'LONET.

    (

    VARCHAR2 (150 CHAR) "NAME."

    NUMBER OF THE "ROOT."

    VARCHAR2 (150 CHAR) "ENTRYVALUE".

    );

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");

    commit;

    Link: activity.project_wid = lonet.root

    look like output

    Project_wid Project_no NAME GAC NAM BAG RAC
    16836911000712-121LDELMELCELKE
    16849941000812-122MTEnullnullMAC
    16862961000912-123nullnullCAQQAQ
    2225222904012-124nullnullnullnull

    two problems, in that I am running

    1. I dono how simply we can convert rows to columns

    2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value

    3. There are undesirables who should be ignored

    Once again my thought process is that we join the activity and 4 alias table lonet.

    ask for your help in this

    Thank you

    Hello

    This is called pivoting.

    Here's a way to do it:

    WITH relevant_data AS

    (

    SELECT a.project_wid, a.project_no, b.SID

    , l.name AS lonet_name, l.entryvalue

    Activity one

    LEFT OUTER JOIN lonet l.root = a.project_wid l

    )

    SELECT *.

    OF relevant_data

    PIVOT (MAX (entryvalue)

    FOR lonet_name IN ("GAC" IN the gac

    "NAM" AS nam

    'BAG' IN the bag

    "RAC" AS cars

    )

    )

    ORDER BY project_wid

    ;

    Output:

    PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME

    ----------- ---------- ---------- ---------- ---------- ---------- ----------

    1683691 12 - 10007 121 LDE LME LCE LKE

    1684994 MAC MTE 10008 12-122

    1686296 12 - 10009 123 QAC QAQ

    2225222 9040 12 - 124

    To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • In v31.0, I can view is more 'raw' XML files with line breaks and ' < ' and ' / > ' characters. Is there a setting that will give me this option?

    Until a few days ago when I opened a file XML with Firefox, I see the content of the file appears with line breaks and ' < ' and ' / > ' and elements. Like this:

    fixed image in < typeOfResource > < / typeOfResource >

     <genre authority="marcgt">picture</genre>
     <genre authority="nmc">Print, Photographic</genre>
     <originInfo>
       <dateIssued encoding="marc">1884</dateIssued>
       <dateIssued encoding="marc">1884</dateIssued>
       <issuance>monographic</issuance>
     </originInfo>
     <language>
    

    Now, it will display like this:

     still image picture Print, Photographic 1884 1884 monographic eng electronic
    

    No tags or line breaks. I need to see the entire XML file. How can I configure FireFox to display this for me? One of my colleagues uses v31.0 and XML views with tags and the line breaks for him.

    For example, I was looking at files sitemap.xml (search Google for inurl:sitemap.xml). For those who have not declared a style sheet, you should always see the classic "source highlight: presentation

    Example: http://www.website.com/sitemap.xml

    Are the files that don't appear as similar planned by not declaring a style sheet?

    As a temporary workaround, you can view the source to see the original. Either:

    • CTRL + u
    • Right click > view Page Source
  • Call Service, run a query with a LimitFilter and a comparator, extend

    I have a lot of difficulties running an InvocationService. I'm relatively new to coherence, please excuse my ignorance

    Basically, I'm trying to get a web client access to a cluster of consistency (which uses * extend) and run a query with a LimitFilter and a comparator.
    It looks that I implement the PortableObject interface on the comparator. I don't know how to be honest, and I'm getting an exception
    : java.io.NotSerializableException:com.tangosol.util.internal.ConcurrentCounter

    Do I need to apply the laptop on the comparator? I have to add the Group of comparison in a pof config XML? I have configuration errors?

    Java code:
            InvocationService service = (InvocationService)  CacheFactory.getConfigurableCacheFactory().ensureService("ExtendTcpInvocationService");
            Map map = service.query(new LatestContentAgent(), null);
            Set result = (Set) map.get(service.getCluster().getLocalMember());
    public class LatestContentAgent extends AbstractInvocable {
    
         private static final long serialVersionUID = 5121824227545845101L;
    
         @Override
         public void run() {
              final Filter filter = new EqualsFilter("getStatusId", Status.LIVE);
                    final LimitFilter limitFilter = new LimitFilter(filter,200);
                    NamedCache cacheInstance = CacheFactory.getCache("dist-extend-cache");
                    setResult(cacheInstance.entrySet(limitFilter,  new ActivityContentVOComparator()));
         }
    }
    public class ActivityContentVO extends AbstractEvolvable implements Serializable, Cacheable {
    
         private static final long serialVersionUID = 1282169603551341131L;
         
         private static final int VERSION = 2; 
    
         private static final int WHEN_IDX = 2;
         private Date when;
    
         public ActivityContentVO() {     // hibernate needs this constructor
         }
         
         public Date getWhen() {
              return when;
         }
    
         public void setWhen(Date when) {
              this.when = when;
         }
    
         public void readExternal(PofReader reader) throws IOException {
              setWhen((Date) reader.readObject(WHEN_IDX));
         }
    
         public void writeExternal(PofWriter writer) throws IOException {
              writer.writeObject(WHEN_IDX, getWhen());
         }
    
         @Override
         public int getImplVersion() {
              return VERSION;
         }
    }
    public class ActivityContentVOComparator implements Comparator<ActivityContentVO>, Serializable,PortableObject {
    
        private static final long serialVersionUID = -8536328258251728594L;
    
        @Override
         public int compare(ActivityContentVO a1, ActivityContentVO a2) {
              if ( a1 == null) {
                return a2 == null ? 0 : 1;
            }
            if (a2 == null) {
                return -1;
            }
            
            final Date d1 = a1.getWhen();
            final Date d2 = a2.getWhen();
            if (d1 == null) {
                return d2 == null ? 0 : 1;
            } else if (d2 == null) {
                return -1;
            }
            
            return d2.compareTo(d1);
         }
    
        @Override
        public void readExternal(PofReader arg0) throws IOException {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void writeExternal(PofWriter arg0) throws IOException {
            // TODO Auto-generated method stub
            
        }
    }
    POF configuration file
    <pof-config>
      <user-type-list>
        <!-- coherence POF user types -->
        <include>coherence-pof-config.xml</include>
        <user-type> 
          <type-id>1004</type-id> 
          <class-name>net.tm.ActivityContentVO</class-name> 
        </user-type>
        ....
        <user-type>
          <type-id>1009</type-id> 
          <class-name>net.tm.ActivityContentVOComparator</class-name> 
        </user-type>
      </user-type-list>
      <allow-interfaces>true</allow-interfaces>
      <allow-subclasses>true</allow-subclasses>
    </pof-config>
    Configuration consistency client-side:
    <remote-invocation-scheme>
          <scheme-name>extend-invocation</scheme-name>
          <service-name>ExtendTcpInvocationService</service-name>
          <initiator-config>
            <tcp-initiator>
                   <remote-addresses>
                            <socket-address>
                                <address system-property="tangosol.coherence.extend.remote.node1"></address>
                                <port system-property="tangosol.coherence.extend.invocation.remote.port1">9094</port>
                            </socket-address>
                            <socket-address>
                                <address system-property="tangosol.coherence.extend.remote.node2"></address>
                                <port system-property="tangosol.coherence.extend.invocation.remote.port1">9094</port>
                            </socket-address>
                        </remote-addresses>
                        <connect-timeout>10s</connect-timeout>
                      </tcp-initiator>
                      <outgoing-message-handler>
                        <request-timeout>5s</request-timeout>
                      </outgoing-message-handler>
                    </initiator-config>
                <serializer>
                    <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
                    <init-params>
                        <init-param>
                            <param-type>String</param-type>
                            <param-value system-property="tangosol.pof.config">app-pof-config.xml</param-value>
                        </init-param>
                    </init-params>
                </serializer>           
    </remote-invocation-scheme>
    Consistent server configuration
            <proxy-scheme>
                <scheme-name>extend-proxy</scheme-name>
                <service-name>ExtendTcpProxyService</service-name>
                <thread-count>5</thread-count>
                <acceptor-config>
                    <tcp-acceptor>
                        <local-address>
                            <address>localhost</address>
                            <port system-property="tangosol.coherence.extend.port">9094</port>
                        </local-address>
                    </tcp-acceptor>
                </acceptor-config>
                <proxy-config>
                    <cache-service-proxy>
                        <lock-enabled>true</lock-enabled>
                    </cache-service-proxy>
                </proxy-config>
                <autostart 
                     system-property="tangosol.coherence.extend.enabled">
                     false
                </autostart>
            </proxy-scheme>
    It's filling stack trace
     TcpConnection(Id=0x000001297F449E980A640BB49B3E90457BFBA97FDB268F4DCF95962206C4C35D, Open=true, LocalAddress=10.100.11.180:90
    94, RemoteAddress=10.100.130.22:4989)
    2010-06-28 16:54:50.398/277.593 Oracle Coherence GE 3.5.3/465 <D6> (thread=Proxy:ExtendTcpProxyService:TcpAcceptor, member=3): Opened: Channel(Id=1588644627, Open=true, Connection=0x000001297F449E980A640BB49B3E90457BFBA97FDB268F4DCF95962206C4C35D)
    2010-06-28 16:54:50.528/277.723 Oracle Coherence GE 3.5.3/465 <Error> (thread=Proxy:ExtendTcpProxyService:TcpAcceptorWorker:3, member=3): An exception occurred while encoding a Response for Service=Proxy:ExtendTcpProxyService:TcpAcceptor: java.io.NotSerializableException: com.tangosol.util.internal.ConcurrentCounter
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
    
    ....
       at com.tangosol.io.pof.PofBufferWriter$UserTypeWriter.writeObject(PofBufferWriter.java:2092)
            at com.tangosol.coherence.component.net.extend.message.Response.writeExternal(Response.CDB:15)
            at com.tangosol.coherence.component.net.extend.Codec.encode(Codec.CDB:23)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.encodeMessage(Peer.CDB:23)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.peer.acceptor.TcpAcceptor.encodeMessage(TcpAcceptor
    .CDB:8)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.send(Peer.CDB:16)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.post(Peer.CDB:23)
            at com.tangosol.coherence.component.net.extend.Channel.post(Channel.CDB:25)
            at com.tangosol.coherence.component.net.extend.Channel.send(Channel.CDB:6)
            at com.tangosol.coherence.component.net.extend.Channel.receive(Channel.CDB:55)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer$DaemonPool$WrapperTask.run(Peer.CDB:9)
            at com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:32)
            at com.tangosol.coherence.component.util.DaemonPool$Daemon.onNotify(DaemonPool.CDB:63)
            at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
            at java.lang.Thread.run(Thread.java:619)
    Published by: user6122052 on June 28, 2010 09:46

    Hi user6122052,

    The problem is that you try to return the result of a query:

    setResult(cacheInstance.entrySet(limitFilter,  new ActivityContentVOComparator()));
    

    and this set is an instance of com.tangosol.util.ConverterCollections$ ConverterEntrySet, which is not serializable. So, you can either convert it, for example:

    Set setResults = cacheInstance.entrySet(limitFilter,  new ActivityContentVOComparator());
    Set setConverted = new HashSet(setResults.size());
    for (Iterator iter = setResults.iterator(); iter.hasNext(); )
        {
        Map.Entry entry = (Map.Entry) iter.next();
        setConverted.add(entry.getValue());
        }
    setResult(setConverted);
    

    or better yet - query the cache directly from your customer Extend.

    Kind regards
    Dimitri

  • Report of update SQL query with line selector. Update process.

    I have a report of update SQL query with the selectors in line.
    How to identify line selector in a process update on the page.

    I want to update some columns with a value of an area of selection on the page.

    With the help of the base:

    UPDATE table_name
    SET Column1 = value
    WHERE some_column = some_value

    I would need to do:

    UPDATE table_name
    SET column1 =: P1_select
    WHERE [line selector] =?

    Now sure how to identify [line selector] and/or validate it is checked.
    Thank you
    Bob

    Identify the name of the checkbox of the source of the page element, it should be of the fxx format (f01, f02... f50).
    Suppose that we f01.

    for i in 1 .. apex_application.g_f01.count
    loop
      UPDATE CONTRACTS
      SET SIP_LOAD_FLAG = :P16_STATUS
      where  =  apex_application.g_f01(i); --i'th checked record' primary key
    end loop;
    
  • Compare the result of a query with a number and return a message

    Hello
    I have the following query in oracle 9i:

    SELECT COUNT (*)
    OF hourly_files
    WHERE date_received = TO_DATE ((SELECT TO_CHAR (SYSDATE - INTERVAL '1' DAY, 'DDMMYYYY')
    (THE DOUBLE), 'DDMMYYYY');

    This will produce a number of lines required

    I need to compare the number of output with another number hardcoded (threshold) and print an appropriate example message

    If the result of the query above is 18000 and the number of threshold is fixed at 20000, then output a meesage:

    Number of files received less than 2000

    Any help will be very appreciated!

    Thank you.
    SQL> ed
    Wrote file afiedt.buf
    
      1  SELECT CASE WHEN COUNT(*) >5 THEN 'Number is > than 5'
      2              WHEN COUNT(*) <1 THEN 'Its less than 1'
      3  ELSE 'Its in between'
      4  END
      5  FROM emp
      6* WHERE deptno=20
    SQL> /
    
    CASEWHENCOUNT(*)>5
    ------------------
    Its in between
    
    SQL> SELECT COUNT(*) FROM emp
      2  WHERE deptno=10;
    
      COUNT(*)
    ----------
             3
    
  • Problems with line spacing and text in Indesign 6 rate

    Hello everyone. I'm a graphic designer working with new magazine layout in Indesign. I used Quark for years and recently fell on this problem...

    In a paragraph, we usually use a soft return back some words to the next line. However, there are opportunities, I notice that in doing so the lines above where I am bumping the word ebb and Exchange. I've never had a problem with this before and it is a serious problem for us. Is it a setting I have on that I'm not aware? What can I do to avoid what is happening?

    Thank you for any input or advice.

    It is one of the main differences between Quark and ID.

    ID has a "paragraph composer" for will as a simple line like Quark composer, and it is enabled by default. When you use the paragraph composer, text is constantly analyzed and spacing adjusted for better form and appearance (according to the spacing algorithm and parameters of your justification) for the whole paragraph. If force you a line break, ID can adjust all the lines above as well as the following lines.

    If it is a 'serious problem' you shoud probably witch to the composer line simple. You will find a drop down for it in the dialog box of the definitin of paragraph under the parameters of the Justification style, or you can change individual paragraph as a local override from the steering wheel to control panel menu.

    Most of us who've been ID user for some time find the paragraph composer include the forces of the ID, and feel that it generates more nice looking text than a single-line composer.

  • (Editable report) SQL query with line selector

    I used this code to get the update of the records in a query SQL (editable report).
    Updates a value in a selection box.

    because me in 1... apex_application.g_f01. Count
    loop
    UPDATE CONTRACTS
    SET LOAD_FLAG =: P8_SELECT
    WHERE ID = apex_application.g_f01 (i); -i'the checked the file 'primary key '.
    end loop;

    Here's my dilemma.
    Line selector seems to be in a fixed position.
    By linking the line for identification number selector (1, 2, 3, etc.)
    Sort by ID (1, 2, 3, etc.)
    It works perfectly, as long as the ID is sorted in order. < <
    If it is sorted by another field with say ID 29 now in the 1st row, by checking the box and update, you update ID #1 located elsewhere on the page.
    Any ideas how to make the line selector literally equal to the line, it is displayed in?
    Thank you
    Bob

    I think I have an idea of what is wrong and, eventually, how to fix it. Try this:

    make your field primary key (NO ROWID!) in a column in a table column, either through the "wizard" (i.e. through the report attributes screen), or using the APEX_ITEM api (as described by Vee). I often have my primary key as a hidden; If you really need to see it, you can use "DISPLAY_AND_SAVE".

    So if your primary key 'ID' colum is now in the 2nd table as a table (i.e. f02 - adjust accordingly!), your PL/SQL process should look like this:

    for i in 1 .. apex_application.g_f01.count
    loop
       UPDATE CONTRACTS
          SET LOAD_FLAG = :P8_SELECT
        where ID = apex_application.g_f02(apex_application.g_f01(i)); 
    
    end loop;
    

    It of a little confusing at first but it it makes sense when you train how tabular tables work with check boxes. The length of this array represents only what is verified - so if you have 3 values checked, the cardinality of the table in a particular table 3. On the other hand, your other tabular berries (containing the 'normal' values) has a cardinality of the count of all the visible lines.

    In this case, the record selector (F01) contains the ID of the relevant line in your report - so passing this value in the array index 2 (F02) should give you the correct primary key for that particular line value. If you subsequently order the report by another field, it should work again.

    I should add that Vee method will work well - the difference is that, instead of organizing the rowid, f01 contains the actual key value. Hope this helps

    Published by: Joel_C on March 21, 2011 11:50

  • 2d line, numbers and dates. How to take into account the date value when drawing a 2d line?

    Hello. I just encountered a problem when tracing a line 2d with numbers.

    I have the following table:

    Date

    Total

    2015 12-31

    R $150 000,00

    2016 03-19

    R $159 000,00

    2016-03-25

    R$ 166,090.00

    2016-04-01

    R$ 159,250.90

    2016 04-10

    R$ 165,343.41

    But when I create a 2d line chart it does take into account the fact that the 1st line is in December. Numbers do not fit the distance between the data symbols according to the date, but instead just consider the dates like any other label. Which causes the curve final not not to be specific

    Is it possible to make account numbers of dates when tracing of graphics?

    If you don't want the dates to be spaced when you do not have uniform intervals so you can use a cloud of points in 2D instead of a 2D line and turn on the connection line, something like this:

    Note that with the Scatter 2D (unlike with 2D line) you do not want to be defined as a column header in the left column.

    SG

  • How to write the query with parameters below and is null


    Hi, I need to recover the data if the parameter is passed on the ground, else retrieve all records where the field is null

    Example of


    CREATE TABLE DEPT
    (DEPTNO NUMBER (2),)
    DNAME VARCHAR2 (14).
    LOC VARCHAR2 (13));

    INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');
    INSERT INTO VALUES DEPT (20, 'SEARCH', 'DALLAS');
    insert into dept values (30, 'SALES', 'CHICAGO');
    INSERT INTO VALUES DEPT (40, 'OPERATIONS', 'BOSTON');

    ALTER table dept add (object_id number);
    insert into dept values (50, 'OPERATIONS', 'BOSTON', 1);
    insert into dept values (60, 'OPERATIONS', 'BOSTON', 1);
    INSERT INTO VALUES DEPT (70, 'OPERATIONS', 'BOSTON', 2);

    Select * from Department where object_id =: p_object_id

    If I pass the object_id 1, it shloud retrieve the values of dept with object_id 1, but if I don't pass the object_id, it must retrieve all records where object_id is null

    IF 1 is passed as the id of the object, he must recover, 50, 60, if 1 is not passed as object_id it should 10,20,30,40 retive

    It works fine for me separately as,.

    Select * from Department where object_id =: p_object_id - 1

    Select * from Department where the object_id is null;

    Is it possible to do in a single query.

    Thank you

    SELECT *
    FROM dept
    WHERE object_id = :p_object_id
    OR (object_id is null and :p_object_id is null)
    

    is an approach.  It's a little talkative, but the meaning is clear.  If you can identify a value that would never appear in the data (for example-1)

    WHERE nvl( object_id, -1 ) = nvl(p_object_id, -1 );
    

    Justin

  • Need help on query with decimal places and trailing 0

    Community of Oracle I need help in the following situations:

    I received the following query:
    SELECT (SUM ("VALUE1") COUNT ("VALUE2"))
    FROM sometable;

    This returns the following results:
    200
    222,5

    I want to display as 222.50 222,5 value so I tried ROUND(value,2) but then came to the conclusion that the tour will not show drags me 0.
    So now I tried to_char(value,'9999DD00') and of course he's back 200.00 both 222.50.

    Now how to make it conditional so when a number has no decimal place it shows the whole number and when it has a decimal, it shows it in the format to_char(value,'9999DD00')?

    I hope I have made my situation and question correctly and I hope a solution.

    P. S.
    I need to appear like that since it is an average of the prices of the products

    Published by: Jnijman on July 3, 2010 13:06

    You can use CASES and INSTR:

    SQL> with t as ( -- generating sample data:
      2  select 200 col from dual union
      3  select 222.5 from dual
      4  )
      5  --
      6  -- actual query:
      7  --
      8  select col
      9  ,      case
     10           when instr(col, ',') > 0
     11           then to_char(col, '999d00')
     12           else to_char(col, '999' )
     13         end formatted_col
     14  from   t;
    
           COL FORMATT
    ---------- -------
           200  200
         222,5  222,50
    
  • Need help in the optimization of the query with the Group and joins by clause

    I'm having the problem by running the following query... It takes a lot of time. To simplify, I added the two tables FILE_STATUS = stores the file load details and COMM table Board table job showing records treated successfully and which was communicated to the other system real. Records with status = T is trasnmitted to another system and traansactions with P is waiting.
    CREATE TABLE FILE_STATUS
    (FILE_ID VARCHAR2(14),
    FILE_NAME VARCHAR2(20),
    CARR_CD VARCHAR2(5),
    TOT_REC NUMBER,
    TOT_SUCC NUMBER);
    
    CREATE TABLE COMM
    (SRC_FILE_ID VARCHAR2(14),
    REC_ID NUMBER,
    STATUS CHAR(1));
    
    INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4);
    INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0);
    
    INSERT INTO COMM VALUES ('12345678', 1, 'T');
    INSERT INTO COMM VALUES ('12345678', 3, 'T');
    INSERT INTO COMM VALUES ('12345678', 4, 'P');
    INSERT INTO COMM VALUES ('12345678', 5, 'P');
    COMMIT;
    Here's the query I wrote to give me the details of the file that has been loaded into the system. He reads the table of State and the commission files to display the name of the file, total records loaded, total at the table of the commission and the number of records which has finally been passed successfully loaded (Status = T) with other systems.
    SELECT 
        FS.CARR_CD 
        ,FS.FILE_NAME 
        ,FS.FILE_ID
        ,FS.TOT_REC
        ,FS.TOT_SUCC
        ,NVL(C.TOT_TRANS, 0) TOT_TRANS
    FROM FILE_STATUS FS
    LEFT JOIN
    (
        SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS
        FROM COMM
        WHERE STATUS = 'T'
        GROUP BY SRC_FILE_ID
    ) C ON C.SRC_FILE_ID = FS.FILE_ID
    WHERE FILE_ID = '12345678';
    In production, this request has several joins and takes a long time to deal with... the main culprit for me is the join on the COMM table to count the number of number of transactions sent. Please can you give me tips to optimize this query to get results faster? What I need to delete the Group and use the partition or something else. Help, please!

    Don't know if it will be faster based on the information provided, but analytical functions offer an alternative approach;

    select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans
      from (select fs.carr_cd,
                   fs.file_name,
                   fs.file_id,
                   fs.tot_rec,
                   fs.tot_succ,
                   count(case
                            when c.status = 'T' then
                             1
                            else
                             null
                          end) over(partition by c.src_file_id) tot_trans,
                   row_number() over(partition by c.src_file_id order by null) rn
              from file_status fs
              left join comm c
                on c.src_file_id = fs.file_id
             where file_id = '12345678')
     where rn = 1;
    
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS
    ------- -------------------- -------------- ---------- ---------- ----------
    LIBM    CM_LIBM.TXT          12345678                5          4          2
    
  • HTMLEditFormat/HTMLCodeFormat with line breaks and newline

    I seeks to some user entered the information on the screen and hit my a problem of output formatting. If I use HTMLEditFormat(), I lose all the line breaks, but that Word wraps nicely. If I use HTMLCodeFormat(), I get line breaks, but the text isn't as word wrap, making some really large screens, even if I put the information in a table with specific to a specific width defined. Is there a way to get the best of both worlds? I need to be able to keep line breaks (sometimes they seized lists or have several paragraphs) but want to word wrap too so that it is easy to read without scrolling sideways. Any ideas?

    Thanks for your suggestions. Given that the information is entered by external users and displayed to the public, I use HTMLEditFormat and HTMLCodeFormat to help prevent script attacks, so don't really want to drop them altogether. However, I discover after playing with the suggestion listed here, it will work: #Replace (HTMLEditFormat (mytext), chr (10),')
    (', 'all') #.

    HTMLEditFormat gets rid of the carriage return character, but not the line supply, so it is possible to replace line breaks with
    to create the desired effect.

    Thanks for your suggestions.

  • New U2412M with lines green and other defects

    I just bought a U2412M for use as a secondary monitor, but when in use, there is a certain green lines dotted on the screen flicker. I also noticed persistent horizontal white lines in the areas of gray. I guess it's a driver issue, but I have since any updated drivers for the video card (NVidia GeForce GT 540 M running Win 7 on an ASUS A53S laptop) and not monitor itself - no change at all to the glitching.

    Note that I have at home an old 2405 FWP that works very well as a secondary monitor.

    Thank you for your time.

    The laptop is not a VGA output port? If so, test this way =

    Laptop output VGA-->--> U2412M input VGA VGA cable VGA

  • Hierarchical query with several parents and children without parents

    Hi all,

    I have a problem of follow-up:

    1, parent_1,.

    2, child_1, 1

    3, child_2, 1

    4, grandchild_1, 2

    5, parent_2,.

    6, child_3, 5

    7, child_0,.

    In this case, I can have multiple parents, and I also have children who do not have parents. Can someone help me solve this problem

    Concerning

    Hello

    So, if a node has itself or 0 as its parent_id, it's the same as with the NULL value?

    In this case, include all these possibilities in the START WITH clause:

    SELECT DLI

    , LPAD (' ' ')

    , (LEVEL - 1) * 3

    , ' '

    ) || descr AS descr

    parent_id

    T

    START WITH NVL (parent_id, 0) (0, DLI)

    CONNECT BY parent_id = PRIOR DLI

    AND idd <> parent_id

    ;

Maybe you are looking for

  • Headphones with iOS 10

    After the update my iPhone to iOS 10, I noticed that the button on my headset does not work like it used to. Originally, the button could pause / play music with a tap, move on to the next with two taps, song start the song with three, etc..  Now, wh

  • Mac mail Gmail expires

    I use Mac Mail with imap to access my institutional email account, which is managed by Google. Very, very often, when I put them to the top of my window in Mail for Mac, there will be a small triangle with an exclamation point inside, next to the ico

  • FF17 - Download button changes size

    The download to the first button seems ok until you click on it, its size expands: http://CL.LY/image/0x0R3p1X3H0u Is this a bug?

  • HP all-in-One: alarming of the boos and screams

    For the last two days, when I boot upwards, pressing the switch on the top of the screen, the computer emits a series of boos, then screams, then more boos and shouts. It sounds very alarming. It is start properly, but must it be of these noises? I f

  • Has anyone got a vista recovery disc that I could borrow?

    Original title: everyone has a recovery disk for vista I could lend I will return even as soon as I get my pc work ing im pensioner Email removed for privacy PC needs priming ing