RPAD

Dear all,

Kindly asking you to make me understand under use of ' ' in the Sql below:

SELECT last_name, RPAD (' ', salary/1000/1,' *') 'salary '.

Employees

"Paycheck" is a string with space (' ') which is just stuffed with asterisk (*) (salary/1000) number of times. Check this

SQL> select ename
  2       , sal
  3       , floor(sal/1000/1) rpad_count
  4       , '"' || rpad(' ', sal/1000/1, '*') || '"' salary
  5    from emp
  6   order
  7      by sal;

ENAME         SAL RPAD_COUNT SALARY
------ ---------- ---------- --------------------
KING         5000          5 " ****"
ADAMS       11101         11 " **********"
WARD        11250         11 " **********"
MARTIN      11250         11 " **********"
TURNER      11500         11 " **********"
ALLEN       11600         11 " **********"
CLARK       12450         12 " ***********"
BLAKE       12850         12 " ***********"
JONES       12975         12 " ***********"
SMITH       12975         12 " ***********"
SCOTT       13000         13 " ************"

11 rows selected.

SQL>

Tags: Database

Similar Questions

  • How to use the rpad, lpad or substr function in the out put files in oracle plsql?

    Hi all

    Declare
       v_account varchar2(30) := '01-000-000-0000-000-0000 ';
       v_WIP varchar2(30) := '123435';
       v_code varchar2(30) := 'PURCHASE_PRICE_VARIANCE';
       v_dr number:=248.8;
       v_cr number:=248.8;
    Begin
     dbms_output.put_line('        Account Segments          '||'   '||' WIP Entity Name      '||'   '||'       Accounting class code          '||'  '||' Accounted DR '||'  '||' Accounted CR ');
     dbms_output.put_line('----------------------------------'||'   '||'----------------------'||'   '||'--------------------------------------'||'  '||'-------------------'||'  '||'------------------- ');
     dbms_output.put_line(rpad(v_account,30)||rpad(v_WIP,25)||rpad( v_code,34)||' '||rpad(v_dr,20)||rpad(v_cr,20));
    End;
    

    Out to

           Account Segments                  WIP Entity Name             Accounting class code               Accounted DR          Accounted CR 
    ----------------------------------   ----------------------   --------------------------------------  -------------------  ------------------- 
    01-000-000-0000-000-0000                  123435                   PURCHASE_PRICE_VARIANCE               248.8                    248.8               
    

    But if I v_code value is "ABCDGE" then

            Account Segments                  WIP Entity Name             Accounting class code                 Accounted DR      Accounted CR 
    ----------------------------------   ----------------------   --------------------------------------  -------------------  ------------------- 
    01-000-000-0000-000-0000                     123435            ABCDGE                             248.8               248.8               
    

    can you please help me how to solve this type of questions?

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    Thank you

    Rajesh123,


    If you do not have it still works, you can use the code below.

    This is based on the details below, you have given

    Account Segments--> left-aligned--> to 26 characters

    Entity name WIP--> Center--> 18 characters length

    Accounting--> left-aligned class--> character length 28 code

    NTS DR--> Center--> 15 character length

    NTS-> Center CR--> 15 character length

    I used the function line given by Karthick_Arp.

    Add the function below to your package:

    function align(p_str in varchar2, p_justify varchar2, p_size integer)
      return varchar2
      is
        l_str    varchar2(4000);
        l_temp   number;
        l_temp_1 number;
        l_left   number;
        l_right  number;
      begin
        case p_justify
          when 'RIGHT' then
            l_str := lpad(p_str, p_size);
          when 'LEFT' then
            l_str := rpad(p_str, p_size);
          when 'CENTER' then
            l_temp   := p_size - length(p_str);
            l_temp_1 := l_temp/2;
            l_left   := floor(l_temp_1);
            l_right  := ceil (l_temp_1);  
    
            l_str := lpad(' ', l_left) || p_str || rpad(' ', l_right);
          else
            raise_application_error(-20001, 'Invalid parameter for p_justify specified -- ' || p_justify);
        end case;  
    
        return l_str;
    end;
    

    Then copy the Sub lines to your code.

     fnd_file.put_line(fnd_file.output,align('Account Segments','CENTER',26)||'   '||align('WIP Entity Name','CENTER',18)||'   '||align('Accounting class code','CENTER',28)||'   '||align('Accounted DR','CENTER',15)||'   '||align('Accounted CR','CENTER',15));
     fnd_file.put_line(fnd_file.output,'--------------------------'||'   '||'------------------'||'   '||'----------------------------'||'   '||'---------------'||'   '||'---------------');
     fnd_file.put_line(fnd_file.output,align(nvl(v_account,' '),'LEFT',26)||'   '||align(v_WIP,'CENTER',18)||'   '||align(v_code,'LEFT',28)||'   '||align(v_dr,'CENTER',15)||'   '||align(v_cr,'CENTER',15));
    

    Once the above code 2 is added to your code, please compile the package and run the concurrent program. Check your output.

    See you soon

    AJ

  • RPAD space in an element of the display does not work?

    4.2.1

    THM 2

    Hello world

    I tried to add space on a point of display value using something like this

    It's the source of the displayed item

    Select rpad (table_column, 10, ' ') table.

    It shows the values less spaces rpad (works fine on sqlplus)

    But if I put something like

    Select rpad (table_column, 10, 'X') table. It then adds the XX correctly.

    I changed the display point setting

    Escape special characters to-> no and limited character-> all characters allowed for this element of the screen. Still, it removes the white spaces. Solutions alternative or ways to do?

    Thank you!

    ryansun wrote:

    Not sure I understand this. You mean, I use the span with padding html tag in the sqls? Some of these items have sql as source, some static text based on certain conditions, then for one with sqls do you need consistent with html in the SQL itself?

    Are you suggesting that I can make detailed recommendations on the Visual presentation and formatting of the page without being able to see content that requires formatting?

    Display elements are rendered as HTML span elements with the name of the element used as attribute to the ID of the item. You can apply the style to an element by using a style attribute in the HTML attributes of the element form of property element, or by using the name of the element as an ID selector in rules in the page CSS CSS properties. You can apply styles to several elements affecting a class attribute in the item property for Classes CSS to HTML form elements and using them as a class selector in the rules in the CSS page properties.

    The possibilities are endless.

    Just to be more precise. What I did is, I have a page on load before the process of the header, where I compare the lengths of some of the elements of the page, and then set a page_item with the lpad value and then use it in the select sql when filling out the element.

    This will work only if the values are displayed using a monospaced font, which is rarely the case in the web today (and ever default in the APEX). Most of the time ' 0 'is wider than 1', W is more broad that 'i's and spaces are somewhere between the two. By using this method with a proportional font, these differences in pixel will simply never become more fussy.

    We'll see this for real, with none of the usual simplification...

  • Problem with RPAD

    Hi friends I have a problem with RPAD I wrote a procedure for sending emails with the body of the message, I'm Kaleidoscope columns using RPAD (name of the Variable, length (Variable_name) + 5,' '). For some specific columns it works fine, but for some columns, is not the working title is is moved to the left side and move to the right. I don't know why this is happening. I ask soembody to help me on the issue, if you want I can post the code also means

    I guess it has something to do with the format of string of cushion in option. If you want to add empty spaces, there is no need to add

    as ". Here is my test scenario and the results.

    SQL > declare
    2 v_name varchar2 (20): = 'ISHAN ";
    3 v_val varchar (200) value default null;
    4 v_length number;
    5. start
    6 select rpad (v_name, length (v_name) + 5 cm) double v_val;
    7 dbms_output.put_line(v_val||) '   '|| Length (v_val));
    8 end;
    9.

    PL/SQL procedure successfully completed.

    Elapsed time: 00:00:00.07
    SQL > declare
    2 v_name varchar2 (20): = 'ISHAN ";
    3 v_val varchar (200) value default null;
    4 v_length number;
    5. start
    6. Select rpad (v_name, length (v_name) + 5) in double v_val;
    7 dbms_output.put_line(v_val||) '   '|| Length (v_val));
    8 end;
    9.
    ISHAN 10

    PL/SQL procedure successfully completed.

    Try to imitate the same thing and see if it meets your needs.

    Ishan

  • LPAD and rpad

    Hi all

    I still don't get the concept of lpad and rpad
    IF l_amount-TRUNC(l_amount) = 0 THEN
              str_footer := 'TRL'||' '||'0353'||'  '||LPAD(l_count,4,'0')                    ||'         '||
                            LPAD(TRUNC(l_amount),8,'0')||'.'||RPAD((l_amount-TRUNC(l_amount)),3,'0')||L_HASH||'.'||
                            RPAD((L_HASH-TRUNC(L_HASH)),3,'0');
           ELSE
              str_footer := 'TRL'||' '||'0353'||'  '||LPAD(l_count,4,'0')||'         '||
                             LPAD(TRUNC(l_amount),8,'0')||RPAD((l_amount-TRUNC(l_amount)),4,'0')||L_HASH;
           END IF;
    
    
    
    the output is  TRL 0353  0018         00002587.0006737164521635025.000
    
    the output required is 
    
    TRL 0353  0018         00002587.000000000000000000000000000000000006737164521635025.000
    have Pad zeros of the 36 th position so that the chain stops at 87
    kindly guide me on how this product can be obtained

    Published by: makdutakdu on March 20, 2012 12:46

    LPAD (RPAD ((l_amount-trunc (l_amount)), 3, '0') |) L_HASH, 50, '0')

    RPAD ((l_amount-trunc (l_amount)), 3, '0'). L_HASH - you wrote for your put

    I added lpad pad left to 50 characters by '0', as you put it outside as specified in your first post

  • Weird RPAD translates 11g using SQLPLUS

    OK, I have two different versions of Oracle.

    My 10g database...
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

    I have run in SQLPLUS SQL
    SELECT RPAD(FIRST, 20), RPAD(LAST, 20) FROM (
    SELECT 'James' FIRST, 'Brown' LAST FROM dual
    UNION
    SELECT 'Christopher' FIRST, 'Columbus' LAST FROM dual
    )
    And I get the following resutls...
    RPAD(FIRST,20)       RPAD(LAST,20)       
    -------------------- --------------------
    Christopher          Columbus            
    James                Brown               
    
    2 rows selected.
    But if I do the same things on my database 11g...
    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    I get...
    RPAD(FIRST,20)                                                                  
    --------------------------------------------------------------------------------
    RPAD(LAST,20)                                                                   
    --------------------------------------------------------------------------------
    Christopher                                                                     
    Columbus                                                                        
                                                                                    
    James                                                                           
    Brown                                                                           
                                                                                    
    
    2 rows selected.
    Why is it formatted oddly, and how can I solve this problem?

    Published by: selectsplat on July 7, 2010 07:42

    TRUE is the default and recommended value setting cursor_sharing

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e10820/initparams041.htm#REFRN10025

    It must only be on another value to fix a buggy application that does not use bind variables, preference only at the level of the session for the broken application connections.

    You will need to discuss with your DBA to find why they put a default value and why they apparently did the scale of the entire base of the system.

  • IF NEW VARIABLE in SQL QUERY, DISPLAYS as the LAST COLUMN + rpad does not

    Hello all and thanks in advance.


    (1) if I add a new variable to my sql query to select a column, which was already on the table, it shows it in the report of the table as the last column on the right. In other words, if I add "the street" to

    something like city, postal code, street, store, Manager, etc., instead of placing the Street between CP and the Bank, the place like I said as the last column on the right.


    (2) when the values entered in the cells of the tables, Yes, they extend to their length, but, only if it is a Word. If it is two, as when I enter the value of 'very good '.

    then two lines as well as by a newline within the cell, for example, which in fact too high the rank. I tried sdap spaces with rpad but this did not work. something like rpad (stock, 20,' ')

    I have to say that the table is in the same page where there is a form, as the table grows in length it's actually squeezing the form on the left.


    (3) rpad did not work with the simpler syntax, but less would be with what I need, because it turns out that I am using DECODE to perform a conversion between the displayed value and

    value returned in my select list of values, something like: DECODE (TO_CHAR (stock), '1', 'Black', '2', 'Average', '3', 'good', '4', 'Very good', null) AS stock

    so, I tried to put the rpad there in several places, but either he gave the parse error or it has left empty do not pick up all the values in the column.


    Thank you very much

    Alvaro

    Alvaro

    (1) this is the standard behavior of the constructor of the apex. You can change the order of display with arrows in the report column attributes.

    (2) you have to play with the style of the column attributes to accomplice this. For the style of the instance = "" white-space: pre; ' in the attributes of the element column attributes. " White-space: normal would be put on several space (' ') 1. So no matter how you add with rpad, they will display as 1.
    Set a width or as attribute in a class style for this column.

    Nicolette

  • Output conversion RPAD of VARCHAR2 to CHAR

    I am trying to create a file with fixed width of 1000 characters using SQL * more. The query consists of 3 fields with a block of 25 characters each, with the other 925 characters as filler by using spaces. RPAD using I can insert spaces between the values of three fields, but because that the RPAD function use VARCHAR2 to return the result is not to recognize the filling spaces 945 ~ I need at the end of each line.

    Is it possible to convert the RPAD output to a CHAR data type in the query itself? Maybe something equivalent to the CONVERT function in t - SQL?


    The query I use:

    Select RPAD (Col1, 25, ' ') | RPAD (Col2, 25, ' ') | RPAD (Col3, 950, ' ') From Table1;

    Thank you

    Matt

    Hello

    Welcome to the forum!

    You can ihave spaces (950 of them if you want, no problem) in a VARCHAR2 column. I suspect that your main font tool is not displayed them.

    SQL * most orders

    SET  TRIM        OFF
    SET  TRIMSPOOOL  OFF
    

    should ensure that spaces on the right are displayed in screen - and out of the SPOOL file, respectively.
    Additionally, make sure that your lines are pretty long:

    SET  LINESIZE    1000
    

    If you still have a problem, after a complete test script (including all the SQL * PLus formatting of the commands that you use) as well as a query. (Something using the double nationality or scottt.dept should illustrate the problem correctly).

  • How rpad after comma decimal?

    Hi all

    I want that all numbers have 2 zeros after the decimal point, as below.

    14 is > 14.00

    4.6 is > 4.60

    2.4 is > 2.40

    5.45 is > 5.45

    However, at the same time it should be NUMBER, no CAR. I am using the following formula. However, it does not work.

    Select to_number (to_char (4.2, '99 D 99')) of double; == > 4.2 (the result should be instead of 4.2 4.20)

    Select to_number (to_char (4.2, '99.99')) of double; == > ORA-01722: ERROR


    So, what should I do?

    Thanks in advance.

    Hello

    As others have said, end '0' are a property of strings, not numbers.

    SELECT TO_CHAR (x, '99990 D 00') AS str

    DOUBLE;

    will produce a chain of exactly 2 digits after the decimal point, regardless of the NUMBER x.

    (Well, not if x > = 100000)

  • Is there a function to adjust the length of a string to 8 multiple bytes?

    Hello

    I have a function to encrypt a password.

    FUNCTION encodeit (p_name IN VARCHAR2, p_password IN VARCHAR2) RETURN VARCHAR2
       IS
          l_password   VARCHAR2 (4000);
          l_salt       VARCHAR2 (4000) := 'hdjikndbbhitasuihfnnkqyhiplwmneuyndnloidj';
       BEGIN
          l_password :=
             UTL_RAW.cast_to_raw (
                DBMS_OBFUSCATION_TOOLKIT.md5 (
                   input_string => p_password ||
                                   SUBSTR (l_salt, 10, 13)||
                                   LOWER (p_name)||
                                   SUBSTR (l_salt, 4, 10)));
          RETURN l_password;
       END;
    

    I want to decrypt the password to send to users when they forget it.  I wrote this function:

    FUNCTION decodeit (p_name IN VARCHAR2, p_password in VARCHAR2) RETURN VARCHAR2 IS
        l_salt       VARCHAR2 (4000) := 'hdjikndbbhitasuihfnnkqyhiplwmneuyndnloidj';
        BEGIN
          RETURN DBMS_OBFUSCATION_TOOLKIT.desdecrypt(input_string =>  p_password ||
                                                                      SUBSTR (l_salt, 10, 13)||
                                                                      LOWER (p_name)||
                                                                      SUBSTR (l_salt, 4, 10),
                                                     key_string   => l_salt) ;
        END;
    

    The problem is that the DBMS_OBFUSCATION_TOOLKIT.desdecrypt function needs a multiple of the input string of 8 bytes. And p_name and p_password are not of fixed length. Is there a function to adjust the length of a string to 8 multiple bytes?

    Best regards.

    They used to work - could be almost ten years (I think version 9 - not tested yet)

    As you can see, you can 'encode' the number of characters, padded in order to set the right length of the decrypted string


    create or replace FUNCTION ' CRYPTIN "(p_str in varchar2) return varchar2 as". "

    l_data VARCHAR2 (255);

    function pad_DES (p_string in varchar2) return varchar2 is

    -platelets p_string with pad_chr containing the number of characters padded (1 to 8)

    -make the string length a multiple of 8 as required by decipher

    pad_length pls_integer;

    pad_char char: = chr (0);

    pad_chars varchar2 (8);

    Start

    pad_length: = 8 - mod (length (p_string), 8);

    pad_chars: = chr (pad_length);

    Return concat (p_string, rpad (pad_chars, pad_length, pad_chars));

    end;

    Start

    l_data: = pad_DES (p_str);

    dbms_obfuscation_toolkit. Decrypt (input_string-online l_data, key_string => 'MagicKey' encrypted_string-online l_data);

    return UTL_RAW. CAST_TO_RAW (l_data);

    end;

    create or replace FUNCTION ' CRYPTOUT "(p_str in varchar2) return varchar2 as". "

    l_data VARCHAR2 (255);

    function unpad_DES (p_string in varchar2) return varchar2 is

    -Removes from p_string upholstered characters (1 to 8)

    pad_length pls_integer;

    Start

    pad_length: = length (p_string);

    pad_length: = pad_length - ascii (substr(p_string,pad_length,1));

    Return substr(p_string,1,pad_length);

    end;

    Start

    l_data: = p_str;

    dbms_obfuscation_toolkit. DESDecrypt (input_string-online l_data, key_string => 'MagicKey', decrypted_string-online l_data);

    Return unpad_DES (l_data);

    end;

    Concerning

    Etbin

  • Romove spooled sqlplus flatfile return transport between requests.

    I'm trying to export the following to a flatfile. It is what is in my SQLPLUS script. Export works without problem, but I have a cartridge back and forth between the two applications. How can I remove the space of line carriage return and exit to the flatfile as one.

    DEFINE the TERM
    SET ECHO OFF;
    SET FEEDBACK OFF;
    SET SERVEROUTPUT ON;
    GAME CHECK;
    DEFINE the LINES 1000;
    SET ARRAYSIZE 100000;
    NEWPAGE the VALUE NONE;
    SET PAGESIZE 0;
    SET PAGES 0;
    ALIGN the HEAD;
    SET SPACE 0;
    SET TRIMSPOOL;
    The VALUE TRIMOUT;
    DEFINE the TAB;

    SELECT rpad (EMP, 25): rpad (PRODUCT, 37) | rpad (ACCOUNT, 25): rpad (CC, 25) | RPAD (NUMBER 25). RPAD ('00', 25). RPAD ('0', 25). RPAD ('000000', 25). RPAD ('00', 25)
      || RPAD ('0000 ', 25). RPAD (AMT, 19). RPAD (D, 1)
    OF W_EMP_D;
    SELECT rpad (RECORD_INDICATOR, 1) | rpad (PK 2) | rpad (FILE, 10): rpad (REC, 11). LPAD (TOTAL, 8, '0'). RPAD (D 18) | RPAD (C, 18)
    OF W_RECORD_IND;

    spool OFF;
    SET COMMENTS ON;
    SET TO on;

    Help appreciated.

    How about you or UNION all THE

    see you soon

  • Missing parenthesis on a delete statement

    Hi all, I have a problem, this script does not work (I changed the names of tables and fields to my company privacy):

    Start

    delete from TABLE1

    WHEN THERE IS)

    Select G.FIELD1

    , lpad (cm.c001, 6,' ') LIKE Field2

    cm.c002 AS field3

    cm.c003 AS FIELD4

    m.codart AS sphere5

    cm.c005 AS case FIELD6

    cm.c006 AS FIELD7

    nvl(cm.c007,0) AS FIELD8

    of apex_collections cm

    Join TABLE2 on c.FIELD2 = lpad c (cm.c001, 6,' ')

    Join TABLE3 g on g.FIELD2 = lpad (cm.c001, 6,' ')

    Join table 4 m on m.FIELD0 = rpad (cm.c004, 32,' ')

    where g.FIELD10 = 'C '.

    and g.FIELD2 = lpad (cm.c001, 6,' ')

    and collection_name = "COLLECTION1.

    order of seq_id

    );

    APEX_COLLECTION. CREATE_OR_TRUNCATE_COLLECTION ("COLLECTION1");

    end;

    because it gives me the error:

    Report error-

    ORA-06550: line 20, column 3:

    PL/SQL: ORA-00907: lack the right parenthesis

    ORA-06550: line 3, column 1:

    PL/SQL: SQL statement ignored

    06550 00000 - "line %s, column % s:\n%s".

    * Cause: Usually a PL/SQL compilation error.

    * Action:

    I do not understand where is the missing parenthesis...

    Now, then you should do something like:

    delete from TABLE1

    WHERE (column, column, column, column, column, column, column, column))

    Select G.FIELD1

    , lpad (cm.c001, 6,' ') AS Field2

    cm.c002 AS field3

    cm.c003 AS FIELD4

    m.codart AS sphere5

    cm.c005 AS case FIELD6

    cm.c006 AS FIELD7

    nvl(cm.c007,0) AS FIELD8

    of apex_collections cm

    Join TABLE2 on c.FIELD2 = lpad(cm.c001,6) c

    Join TABLE3 g on g.FIELD2 = lpad(cm.c001,6)

    Table 4 m on m.FIELD0 = rpad(cm.c004,32) join

    where g.FIELD10 = 'C '.

    and cm.collection_name = 'COLLECTION1.

    );

    or

    remove table 1 t

    WHEN THERE IS)

    Select null

    of apex_collections cm

    Join TABLE2 on c.FIELD2 = lpad(cm.c001,6) c

    Join TABLE3 g on g.FIELD2 = lpad(cm.c001,6)

    Table 4 m on m.FIELD0 = rpad(cm.c004,32) join

    where g.FIELD10 = 'C '.

    and cm.collection_name = 'COLLECTION1.

    and t.key1 = g.field1

    and t.key2 = lpad(cm.c001,6)

    ...

    );

    HTH

  • alignment of the text file column data

    Hi all

    I want to format the output file as shown in need. Suggestions appreciated. I tried with lpad, rpad in the query. Also tried with justify right in the column after A5 format... (A5 size frame right)

    It is part of an important application.

    Please suggest.

    SQL file

    --------

    set verify off
    Set feedback off
    NewPage 0 value
    set pagesize 63
    set linesize 280
    TOPIC ON THE VALUE

    coil c:\test.txt.
    column heading "CTY" A5 format Change_types

    termout off Set

    Select CT of
    tab;

    output in the text file

    CTY
    -----
    N

    Power required:

    CTY
    -----
    N

    (* See space above)
    Oracle 10g
    running sqlplus

    Thank you

    HA!

    Hello

    G2500 wrote:

    Hi all

    I want to format the output file as shown in need. Suggestions appreciated. I tried with lpad, rpad in the query. Also tried with justify right in the column after A5 format... (A5 size frame right)

    It is part of an important application.

    Please suggest.

    SQL file

    --------

    set verify off
    Set feedback off
    NewPage 0 value
    set pagesize 63
    set linesize 280
    TOPIC ON THE VALUE

    coil c:\test.txt.
    column heading "CTY" A5 format Change_types

    termout off Set

    Select CT of
    tab;

    output in the text file

    CTY
    -----
    N

    Power required:

    CTY
    -----
    N

    (* See space above)
    Oracle 10g
    running sqlplus

    Thank you

    HA!

    This sounds like a job for LPAD.  What exactly have you tried?  It is difficult to say what hurts you without knowing what you were doing.

    I don't have a copy of your table, so I'll use the scott.dept table to illustrate:

    SELECT LPAD (dname, 20) department_name

    OF scott.dept

    ;

    Output:

    DEPARTMENT_NAME

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

    ACCOUNTING

    SEARCH

    SALES

    OPERATIONS

    You want to justify the right title, like this

    DEPARTMENT_NAME

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

    ACCOUNTING

    SEARCH

    SALES

    OPERATIONS

    ?

    If so, make this SQL * more order

    Department_name RIGHT-JUSTIFIED COLUMN

    before running the query.  COLUMN... JUSTIFICATION applies only to the topic, not the data.

  • SQL Query hierarchical select 2 level parent over sheet.

    Here, we use Oracle 11 g R1. Here is a sample of our Tables of the employee.

    I want you select all managers managers above them (which we call the Site Manager) and direct (that we call the Service Manager)

    Here is the example for the base table.

    SET DEFINE OFF;
    CREATE TABLE EMP_SAMPLE 
    (
      AGENT_ID VARCHAR2(100 BYTE) 
    , FULL_NAME VARCHAR2(100 BYTE) 
    , AGENT_MANAGER VARCHAR2(100 BYTE) 
    ) ;
    
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('JS001','JOHN SMITH',null);
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('AL001','ANN LEE','JS001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('JD001','JOHN DOE','AL001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('MB002','MARY BAKER','AL001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('HM003','HOWARD MONROE','MB002');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('RM001','ROBYN MILLER','MB002');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('DJ002','DAVID JONES','RM001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('WW001','WENDY WONG','MB002');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('PB001','PETER RABBIT','JS001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('BB002','BEN BUNNY','PB001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('TM001','TONY MILLER','BB002');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('PP002','PETER PARKER','RM001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('PP003','PEPPA PIG','PB001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('DB002','daniel baker','HM003');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('TL001','Tom Lee','WW001');
    Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('MS001','Mary Smith',null);
    

    With the example like this data, I would like to that the result looks similar to

    Name of the Manager

    MARY BAKER - Manager of the Site

    HOWARD MONROE - Service Manager

    ROBYN MILLER - Service Manager

    WENDY WOND - Service Manager

    PETER RABBIT Site Manager

    BEN BUNNY - Service Manager

    I guess I should use the hierarchical query to achieve this. I googled to see all the solutions, I tried this under request

    SELECT agent_id, agent_manager, RPAD('.', (level-1)*2, '.') || full_name AS tree,
           level, CONNECT_BY_ROOT agent_id as root_id
           ,CONNECT_BY_ISLEAF AS is_leaf
    
    FROM EMP_SAMPLE
    START WITH agent_manager IS NULL
    CONNECT BY agent_manager = PRIOR agent_id
    ORDER SIBLINGS BY agent_id;
    

    But it seems that the level always starts from the root at the top of the page. I wonder, is it possible to identify even just the level two above the sheet.

    Here is some basic information. We are working on our oracle APEX application. One of the reports can be filtered by the Manager. The list currently shows a little all managers, regardless of what they are 1 senior as general manager, or the first line as a Service Manager Manager. Now, users want to be able to select only Service Manager and Site Manager.

    There is a DB work for updating the table Employee of LDAP. And the LDAP structure is not tidy this (we have some staff members who have no Manager, they are not even CEO). The Administrator told us that it is too busy to store it.

    We have about 20,000 employees in total including 800 East of managers.

    Thanks in advance.

    Ann

    Hi, Ann.

    Ann586341 wrote:

    Here, we use Oracle 11 g R1. Here is a sample of our Tables of the employee.

    I want you select all managers managers above them (which we call the Site Manager) and direct (that we call the Service Manager)

    Here is the example for the base table.

    1. TOGETHER TO DEFINE
    2. CREATE TABLE EMP_SAMPLE
    3. (
    4. AGENT_ID VARCHAR2 (100 BYTE)
    5. FULL_NAME VARCHAR2 (100 BYTE)
    6. AGENT_MANAGER VARCHAR2 (100 BYTE)
    7. ) ;
    8. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('JS001', 'JOHN SMITH', null);
    9. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('AL001', "ANN LEE", "JS001");
    10. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('JD001', 'JOHN DOE', "AL001");
    11. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('MB002', "MARY BAKER", "AL001");
    12. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('HM003', 'HOWARD MONROE', 'MB002');
    13. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('RM001", 'ROBYN MILLER', 'MB002');
    14. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('DJ002', 'DAVID JONES', "RM001");
    15. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('WW001', "WENDY WONG", "MB002");
    16. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('PB001', 'PETER RABBIT', "JS001");
    17. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('BB002', "BEN BUNNY", "PB001");
    18. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('TM001', 'TONY MILLER', "BB002");
    19. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('PP002","PETER PARKER","RM001");
    20. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('PP003', 'PEPPA PIG', "PB001");
    21. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('DB002', "daniel baker", "HM003");
    22. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('TL001', "Tom Lee", "WW001");
    23. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('MS001', 'Mary Smith', null);

    With the example like this data, I would like to that the result looks similar to

    Name of the Manager

    MARY BAKER - Manager of the Site

    HOWARD MONROE - Service Manager

    ROBYN MILLER - Service Manager

    WENDY WOND - Service Manager

    PETER RABBIT Site Manager

    BEN BUNNY - Service Manager

    I guess I should use the hierarchical query to achieve this. I googled to see all the solutions, I tried this under request

    1. SELECT agent_id, agent_manager, RPAD ('.) (', (level 1) * 2, '.') || full_name LIKE tree,
    2. level, agent_id CONNECT_BY_ROOT as root_id
    3. CONNECT_BY_ISLEAF AS is_leaf
    4. OF EMP_SAMPLE
    5. START WITH agent_manager IS NULL
    6. CONNECT BY PRIOR agent_id = agent_manager
    7. Brothers and SŒURS of ORDER BY agent_id;

    But it seems that the level always starts from the root at the top of the page. I wonder, is it possible to identify even just the level two above the sheet.

    Here is some basic information. We are working on our oracle APEX application. One of the reports can be filtered by the Manager. The list currently shows a little all managers, regardless of what they are 1 senior as general manager, or the first line as a Service Manager Manager. Now, users want to be able to select only Service Manager and Site Manager.

    There is a DB work for updating the table Employee of LDAP. And the LDAP structure is not tidy this (we have some staff members who have no Manager, they are not even CEO). The Administrator told us that it is too busy to store it.

    We have about 20,000 employees in total including 800 East of managers.

    Thanks in advance.

    Ann

    Here's one way:

    WITH leaves LIKE

    (

    SELECT agent_id

    Of emp_sample

    LESS

    SELECT agent_manager

    Of emp_sample

    )

    got_lvl AS

    (

    SELECT-full_name agent_id

    LEVEL AS lvl

    Of emp_sample

    START WITH agent_id IN)

    SELECT agent_id

    Sheets

    )

    CONNECTION BY agent_id = agent_manager PRIOR

    )

    SELECT full_name

    CASE

    WHEN MAX (lvl) = 3

    THEN 'Site Manager'

    ANOTHER "Service Manager"

    END AS title

    OF got_lvl

    GROUP BY full_name-, agent_id

    WITH MIN (lvl) > = 2

    AND MAX (lvl)<=>

    ORDER BY full_name

    ;

    Output:

    FULL_NAME TITLE

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

    BEN BUNNY Service Manager

    MONROE HOWARD Service Manager

    MARY BAKER Site Manager

    PETER RABBIT Site Manager

    ROBYN MILLER Service Manager

    WENDY WONG Service Manager

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

    LEVEL does not always begin with the root; It starts with the lines that meet the condition to START WITH.  If you have a START WITH condition that only roots meet (as in the query you posted) then, Yes, LEVEL will start with the roots.  If you have a condition START WITH answering the criteria only the leaves (as in the query I posted), then LEVEL will start with the leaves.

    I guess just some of your needs.  If seems that a 'Site Manager' is the grandparent of a leaf, but "John Smith" (which is the grandmother of "John Doe", a sheet) is not considered to be a 'Site Manager'.  Similarly, it seems that a 'Service Manager' is the parent (but not the grand-parent) of the leaf, but "Ann Lee" (the mother of "John Doe") is not considered to be a 'Service Manager' for a reason any.

    I guess that full_name is unique.  If full_name is not unique, but agent_id is, then you will need a comment a few line above ends.  (I guess that agent_id is unique and not NULL).

  • How can I call ttOptUpdateStats from PL/SQL

    I would like to: call ttOptUpdateStats from within a PL/SQL block.

    An example of one: run immediately using the input arguments in the PL/SQL Developer's Guide.

    The examples cover only builtin procedures returning data.

    Thanks for the help!  Here's my working version:

    Create procedure UPDATE_STATS as

    type of TblList is the table sys. TBL_STATS. TYPE % TBLID;

    tblids TblList;

    TBL VARCHAR2 (255);

    flag for number: = 1;

    plsql_block VARCHAR2 (255);

    LASTDATE SYS. TBL_STATS. TYPE % LASTSTATSUPDATE;

    Start

    plsql_block: = "call ttOptUpdateStats(:tbl,:flag)";

    Select TBLID bulk collect into SYS tblids. TABLES where the TBLOWNER not in ('SYS', 'TTREP', 'GRID');

    because me in tblids. FIRST... tblids. LAST

    loop

    Select trim (TBLOWNER): '. ' || Trim (TBLNAME) tbl of SYS. TABLES where SYS. TABLES. TBLID = tblids (i);

    execute immediate plsql_block using tbl, flag;

    Select LASTSTATSUPDATE from SYS lastdate. TBL_STATS where SYS. TBL_STATS. TBLID = tblids (i);

    dbms_output.put_line ('< '="" ||="" rpad(tbl,45)="" ||="" '="" '="" ||="" lastdate="" ||="" '="">');

    end loop;

    exception

    while others

    then

    Rollback;

    end UPDATE_STATS;

    /

    Ed...

Maybe you are looking for

  • Satellite A40 - broken CD drive, startup options

    Hellomy CD ROM drive is broken and I need to use the Windows XP CD to update some corrupted files. Having bought an external CD ROM drive I now found it impossible to boot on this base, because she seems to be not supported by the BIOS options. Does

  • Connectivity to the Satellite M30X USB problem

    Hello everyone, I have a problem with the USB to the Satellite M30X connectivity. I purchased a M30X and had problems with connecting devices of differnet in one of the USB ports. I tried to solve his problem and but nothing resolved. Goodbye, Meier

  • Qosmio X 770-Bluetooth does not turn on

    Hello I have a toshiba Qosmio X 770 with built in without wireless/bluetooth. I've had the computer for almost a year and finally bought a bluetooth device to use. However, when you set up the bluetooth on my computer, the first error I recived was "

  • When I check IMIE it shows another I phone

    I use a 32GB Iphone 5 s gold one. But when I check the IMIE on google it ahows me totally different Iphone. It shows me 5 s Iphone 16 GB silver one? My Iphone is a fake? Or. What is wrong with him?

  • General protection fault with tabs and toolbars to the output of the application

    Hello It seems that if you have a tab control .. .and that tab has a tab with a child Panel control .. .and this child Panel has a sign callback function .. .and this same child Panel also has a toolbar .. .and you do not throw the toolbar when the a