SQL turning lines

Hello

create table x (a varchar2(30), b number(5));
insert into x values ('asdasd', 1);
insert into x values ('bbb', 2);


select x.a, x.b, nvl2(x.a, 'ERR_000', 'ERR_001') err_code, nvl2(x.a, 'OK', 'Something error desc..') err_desc
  from x
  where x.a = 'asdasd';

Is it possible somehow that if no rows are returned, however return a row with err_code "ERR_001" and other columns as null values? If a row is returned, then I want to return the appropriate values and err_code 'ERR_000 '.

Don't know if it's possible, but I'm just a matter

Thank you

SQL >

SQL > select x.a,.

2 x.b,

3 nvl2 (x.a, 'ERR_000', 'ERR_001') err_code

4 x

5 right join double

6 on x.a = "asdasd"

A                              B         ERR_CODE

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

asdasd ERR_000 1

SQL >

SQL > select x.a,.

2 x.b,

3 nvl2 (x.a, 'ERR_000', 'ERR_001') err_code

4 x

5 right join double

6 on x.a = 'test ';

A                              B         ERR_CODE

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

ERR_001

SQL >


----

Ramin Hashimzade

Tags: Database

Similar Questions

  • How to get sql % number of dynamic sql code lines

    Hello

    In this procedure I'm inserting and updating using dynamic sql. Now I want to go back two more PARAMETERS, the parameter should be back the number of lines inserted and how updated by stmtas of UPDATE as well as an INSERT. I'm not able to do can help you on that?

    CREATE OR REPLACE PROCEDURE Sp_Array_Test( PV_TGT_NAME   IN  VARCHAR2,
                                               PV_SRC_NAME   IN  VARCHAR2,
                                               PV_PK_COLS    IN  VARCHAR2,
                                               PN_ERR_CD     OUT NUMBER,
                                               PN_ERR_MSG    OUT VARCHAR2)
    AS
    
    
    TYPE ARR_TAB IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
    
    
    --UTL_FP        UTL_FILE.FILE_TYPE;
    LV_AN_
    
    
    
    BLOCK   VARCHAR2(32767);
    LN_CUR        BINARY_INTEGER := DBMS_SQL.OPEN_CURSOR;
    LN_DESC       DBMS_SQL.DESC_TAB;
    LN_COL_CNT    PLS_INTEGER := 0;
    LV_SEL_UPD_STMT   VARCHAR2(4000);
    LV_SEL_INS_STMT   VARCHAR2(4000);
    ARR_INDX      NUMBER := 1;
    LV_DATA_TYPE  VARCHAR2(8);
    LN_FIND_FLAG  NUMBER := 0;
    LN_TAB        ARR_TAB;
    LV_COLS_ARR   ARR_TAB;
    LV_ERR_MSG    VARCHAR2(500);
    
    
    
    
    --PROCEDURE FILE_WRITE ( FH_IN     IN UTL_FILE.FILE_TYPE,
    --                STRING_IN IN VARCHAR2 ) IS
    --BEGIN
    --   UTL_FILE.PUT_LINE(FH_IN,STRING_IN);
    --   LV_AN_BLOCK := LV_AN_BLOCK||STRING_IN;
    --EXCEPTION
    --   WHEN OTHERS THEN
    --      RAISE;
    --END FILE_WRITE;
    
    
    
    
    BEGIN
    
    
    --   UTL_FP := UTL_FILE.FOPEN('TEST_DIR', 'TEST.sql', 'W');
    
    
        LV_SEL_UPD_STMT := 'SELECT A.'||REPLACE(PV_PK_COLS,',','||A.')||' PK_COLS , A.* , B.ROWID FROM '||PV_SRC_NAME||' A, '||PV_TGT_NAME||' B WHERE ';
    
    
        LV_SEL_INS_STMT := 'SELECT A.* FROM '||PV_SRC_NAME||' A WHERE NOT EXISTS (SELECT ''1'' FROM '||PV_TGT_NAME||' B WHERE ';
    
    
        LN_TAB(ARR_INDX) := 'DECLARE ';
        ARR_INDX := ARR_INDX + 1;
    
    
        LN_TAB(ARR_INDX) := 'CURSOR CUR_VIEW_UPD IS '||LV_SEL_UPD_STMT ;
        ARR_INDX := ARR_INDX + 1;
    
    
    
    
        SELECT SUBSTR(COLS,DECODE(RN,1,1,INSTR(COLS,',',1,RN-1)+1),DECODE(RN,1,INSTR(COLS,',',1,RN)-1,INSTR(COLS,',',1,RN)-INSTR(COLS,',',1,RN-1)-1))
    BULK COLLECT INTO LV_COLS_ARR
          FROM ( SELECT RN, PV_PK_COLS||',' COLS
                   FROM (SELECT ROWNUM RN
                           FROM ALL_OBJECTS
                          WHERE ROWNUM <= LENGTH(PV_PK_COLS)- LENGTH(REPLACE(PV_PK_COLS,','))+1)) ;
        FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
            LV_SEL_UPD_STMT     := LV_SEL_UPD_STMT||' A.'||LV_COLS_ARR(K)||' = ';
            LN_TAB(ARR_INDX) := ' A.'||LV_COLS_ARR(K)||' = ';
            LV_SEL_UPD_STMT     := LV_SEL_UPD_STMT||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN NULL ELSE ' AND ' END;
            LN_TAB(ARR_INDX) := LN_TAB(ARR_INDX)||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN ' ;' ELSE ' AND ' END;
            ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
        LN_TAB(ARR_INDX) := 'CURSOR CUR_VIEW_INS IS '||LV_SEL_INS_STMT ;
        ARR_INDX := ARR_INDX + 1;
    
    
        FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
            LV_SEL_INS_STMT     := LV_SEL_INS_STMT||' A.'||LV_COLS_ARR(K)||' = ';
            LN_TAB(ARR_INDX) := ' A.'||LV_COLS_ARR(K)||' = ';
            LV_SEL_INS_STMT     := LV_SEL_INS_STMT||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN NULL ELSE ' AND ' END;
            LN_TAB(ARR_INDX) := LN_TAB(ARR_INDX)||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN ' );' ELSE ' AND ' END;
            ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
    
    
        LV_ERR_MSG := 'WHILE PARSING SELECT STATEMENT -- '||LV_SEL_UPD_STMT;
        DBMS_SQL.PARSE(LN_CUR, LV_SEL_UPD_STMT, DBMS_SQL.NATIVE);
    
    
        LV_ERR_MSG := 'WHILE DESCRIBING SELECT STATEMENT -- '||LV_SEL_UPD_STMT;
        DBMS_SQL.DESCRIBE_COLUMNS(LN_CUR, LN_COL_CNT, LN_DESC);
    
    
    
    
    
    
       FOR i IN LN_DESC.FIRST .. LN_DESC.LAST LOOP
          IF LN_DESC(i).col_type = 2 THEN
             LV_DATA_TYPE := 'NUMBER';
          ELSIF LN_DESC(i).col_type = 12 THEN
             LV_DATA_TYPE := 'DATE';
          ELSE
             LV_DATA_TYPE := 'VARCHAR2';
          END IF;
           LN_TAB(ARR_INDX) := '   T_'||LN_DESC(i).col_name||' DBMS_SQL.'||LV_DATA_TYPE||'_TABLE;';
           ARR_INDX := ARR_INDX + 1;
       END LOOP;
    
    
    
    
    
    
        LN_TAB(ARR_INDX) := 'BEGIN ';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   EXECUTE IMMEDIATE ''ALTER SESSION SET NLS_DATE_FORMAT = ''''DD-MON-YYYY HH24:MI:SS'''''';';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   OPEN CUR_VIEW_UPD;';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   LOOP';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      FETCH CUR_VIEW_UPD BULK COLLECT INTO T_'||LN_DESC(LN_DESC.FIRST).col_name||',';
        ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(i).col_name||',';
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
       LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(LN_DESC.LAST).col_name||' LIMIT 500 ;';
       ARR_INDX := ARR_INDX + 1;
       LN_TAB(ARR_INDX) := '     FORALL I IN 1 .. '||'T_'||LN_DESC(LN_DESC.LAST).col_name||'.COUNT ';
       ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      UPDATE '||PV_TGT_NAME||' SET  ';
        ARR_INDX := ARR_INDX + 1;
        LN_FIND_FLAG := 0;
        FOR I IN LN_DESC.FIRST + 1 .. LN_DESC.LAST-1 LOOP
          FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
             LN_FIND_FLAG := 0;
             IF LN_DESC(I).COL_NAME = LV_COLS_ARR(K) THEN
                LN_FIND_FLAG := 1;
                EXIT;
             END IF;
          END LOOP;
          IF LN_FIND_FLAG = 0 THEN
            LN_TAB(ARR_INDX) := '                        '||LN_DESC(i).col_name||' = '||'T_'||LN_DESC(i).col_name||'(I)'||CASE WHEN I = LN_DESC.LAST-1 THEN ' WHERE ' ELSE ',' END;
            ARR_INDX := ARR_INDX + 1;
          END IF ;
        END LOOP;
    
    
       LN_TAB(ARR_INDX) := '                        ROWID = '||'T_'||LN_DESC(LN_DESC.LAST).col_name||'(I) ;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      EXIT WHEN CUR_VIEW_UPD%NOTFOUND;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   END LOOP;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   CLOSE CUR_VIEW_UPD;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
    
    
        LN_TAB(ARR_INDX) := '   OPEN CUR_VIEW_INS;';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   LOOP';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      FETCH CUR_VIEW_INS BULK COLLECT INTO T_'||LN_DESC(LN_DESC.FIRST+1).col_name||',';
        ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 2 .. LN_DESC.LAST - 2 LOOP
          LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(i).col_name||',';
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
       LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(LN_DESC.LAST-1).col_name||' LIMIT 500 ;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '     FORALL J IN 1 .. '||'T_'||LN_DESC(LN_DESC.FIRST + 1).col_name||'.COUNT ';
       ARR_INDX := ARR_INDX + 1;
       LN_TAB(ARR_INDX) := '     INSERT INTO '||PV_TGT_NAME||' (';
       ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := '                        '||LN_DESC(i).col_name||CASE WHEN I = LN_DESC.LAST - 1  THEN ' )' ELSE ',' END ;
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := CASE WHEN I = LN_DESC.FIRST + 1 THEN 'VALUES (' ELSE NULL END ||'                        T_'||LN_DESC(i).col_name||'(J)'||CASE WHEN I = LN_DESC.LAST - 1  THEN ' ) ;' ELSE ',' END ;
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      EXIT WHEN CUR_VIEW_INS%NOTFOUND;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   END LOOP;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   CLOSE CUR_VIEW_INS;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := 'END ;';
       ARR_INDX := ARR_INDX + 1;
    
    
    
    
       FOR J IN 1 .. LN_TAB.COUNT LOOP
    --     DBMS_OUTPUT.PUT_LINE( LN_TAB(J));
    --     FILE_WRITE(UTL_FP,LN_TAB(J));
         LV_AN_BLOCK := LV_AN_BLOCK||LN_TAB(J);
       END LOOP;
    
    
    --   UTL_FILE.FCLOSE(UTL_FP);
    
    
       EXECUTE IMMEDIATE LV_AN_BLOCK;
    
    
    PN_ERR_CD    := 0;
    PN_ERR_MSG   := 'Successful Completion';
    
    
    EXCEPTION
    WHEN OTHERS THEN
    PN_ERR_CD    := SQLCODE;
    PN_ERR_MSG   := LV_ERR_MSG||' -- '||SQLERRM ;
    END;
    /
    

    Thank you all for your answers. I agree with you all. I have manged this time by adding variable bind, then run it immediately ON aid. I don't know how it's going to be training.

    From now on my side no problem I don't thank you.

  • SQL puzzler: Line rankings according to the columns

    We have a table that looks like the following:

    COL_1_RANK COL_1_VALUE COL_2_RANK COL_2_VALUE
    1AAA3HHH
    2BBB2GGG
    3CCC5JJJ
    4DDD1FFF
    5EEE4III

    We want to extract a *single* rank for each case where COL_1_RANK and COL_2_RANK are equivalent. Then we want the values corresponding to this mutual rank to be contained in the same line. Thus, the desired output is as follows:

    MUTUAL_RANK COL_1_VALUE COL_2_VALUE
    1AAAFFF
    2BBBGGG
    3CCCHHH
    4DDDIII
    5EEEJJJ

    The other condition is that we want to do this in a *table single pass*. So we are aware of the solutions using two different CLAUSES and by joining in the ranks. It's not what we're looking for here.

    We are suspecting that some analytic function can be used here, but can't seem to find, he. Basically, for each line, take the value of COL_1_RANK and, then, on the set of all values of COL_2_RANK , locate the line where COL_2_RANK = s COL_1_RANK. Pull the COL_2_VALUE of this line.

    No matter what SQL Smarties out there who have a solution for this?

    Thank you

    -Joe

    SELECT col_1_rank,

    col_1_value,

    REGEXP_SUBSTR (listagg (col_2_value, ",") THE Group (ORDER BY col_2_rank) (),

    '[^,]+',

    1,

    col_1_rank)

    col_2_value

    T

    order by 1;

  • PL/SQL muliple line insert for a single line

    I need to insert several lines in a single line. Here is the table structures and sample data
    CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
    
    CREATE TABLE TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20))
    
    insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('hello','asd','fgh','ert',null);
    For the anecdote above in the TEST_SAMPLE table, three records must be populated\inserted in TRANSACTION table. In PL/SQL
    stored procedure I am insert records of TRANSACTIONS when ATTR_1 or ATTR_2 or ATTR_3 or ATTR_4 is not null.

    Please help me to find a better way to insert above in table TRANSACTION?

    Like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  insert all
      2    when 1=1 then
      3      into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values (name, attr_1, attr_2, attr_3, attr_4)
      4    when attr_1 is not null then
      5      into TRANSACTION (NAME, ATTR) values (name, attr_1)
      6    when attr_2 is not null then
      7      into TRANSACTION (NAME, ATTR) values (name, attr_2)
      8    when attr_3 is not null then
      9      into TRANSACTION (NAME, ATTR) values (name, attr_3)
     10    when attr_4 is not null then
     11      into TRANSACTION (NAME, ATTR) values (name, attr_4)
     12  select 'hello' as name
     13        ,'asd' as attr_1
     14        ,'fgh' as attr_2
     15        ,'ert' as attr_3
     16        ,null as attr_4
     17* from dual x
    SQL> /
    
    4 rows created.
    
    SQL> select * from test_sample;
    
    NAME                 ATTR_1               ATTR_2               ATTR_3               ATTR_4
    -------------------- -------------------- -------------------- -------------------- --------------------
    hello                asd                  fgh                  ert
    
    SQL> select * from transaction;
    
    NAME                 ATTR
    -------------------- --------------------
    hello                asd
    hello                fgh
    hello                ert
    
  • SQL help (line column... a little)

    I'm a little weird to write query. I want to turn rows into columns, but they must be grouped by line # as well. They will have to be group by tracking #...

    The other issue is, the system can have 5 minimum options and a maximum of 7. Here are the options...

    So, in reality, he will be taking a set of lines (misc 5-7) and returning to the side to make the columns. But, the new column headers are always defined like this max 7 and 2 can be cancelled on if not available...

    Confusing even explain... insert statement for example 2 below... we have 6, 7 criteria we met...

    ----------------------------------------------------------
    Sector of activity
    Type
    Did you review the user guide?
    Application
    Enter your Message
    Have you reviewed the FAQs?
    Tracking number of EIS
    -----------------------------------------------------------





    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323646, 'application', "DRI INT");
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323646, 'Enter your Message', 'test');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323646, 'have you seen the FAQ document?', 'No');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323646, 'have you reviewed the user's guide?', 'No');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323646, "line of Business", "AUTO");
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323646, 'Type', 'Suggestion');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323647, 'application', 'BEST');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323647, 'Enter your Message', 'test');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323647, 'have you seen the FAQ document?', 'No');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323647, 'have you reviewed the user's guide?', 'Yes');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323647, 'Number of EIS path', 'none');
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323647, "line of Business", "MAPS");
    Insert into the TABLE
    (FIELDVALUES CAN ONLY BE TRACKINGNUMBER, NM_PARM)
    Values
    (323647, 'Type', 'Question');
    COMMIT;
    with "TABLE" as
    (
    (select 323646 TRACKINGNUMBER, 'Application' NM_PARM, 'DRI INT' FIELDVALUES from dual)
    union all
    (select 323646 , 'Enter Your Message', 'test'  from dual)
    union all
    (select 323646 , 'Have you reviewed the FAQ document ?', 'No'  from dual)
    union all
    (select 323646 , 'Have you reviewed the User guide ?', 'No'  from dual)
    union all
    (select 323646 , 'Line Of Business', 'AUTO'  from dual)
    union all
    (select 323646 , 'Type', 'Suggestion'  from dual)
    union all
    (select 323647 , 'Application', 'BEST'  from dual)
    union all
    (select 323647 , 'Enter Your Message', 'test'  from dual)
    union all
    (select 323647 , 'Have you reviewed the FAQ document ?', 'No'  from dual)
    union all
    (select 323647 , 'Have you reviewed the User guide ?', 'Yes'  from dual)
    union all
    (select 323647 , 'ISW Tracking Number', 'none'  from dual)
    union all
    (select 323647 , 'Line Of Business', 'CARDS'  from dual)
    union all
    (select 323647 , 'Type', 'Question'  from dual)
    )
    , t as
    (
    select distinct TRACKINGNUMBER tn from "TABLE"
    )
    select
     (select FIELDVALUES from "TABLE" where NM_PARM = 'Application' and TRACKINGNUMBER = t.tn) "Application"
    ,(select FIELDVALUES from "TABLE" where NM_PARM = 'Enter Your Message' and TRACKINGNUMBER = t.tn) "Enter Your Message"
    ,(select FIELDVALUES from "TABLE" where NM_PARM = 'Have you reviewed the FAQ document ?' and TRACKINGNUMBER = t.tn) "Have you reviewed FAQ?"
    ,(select FIELDVALUES from "TABLE" where NM_PARM = 'Have you reviewed the User guide ?' and TRACKINGNUMBER = t.tn) "Have you reviewed User gui?"
    ,(select FIELDVALUES from "TABLE" where NM_PARM = 'ISW Tracking Number' and TRACKINGNUMBER = t.tn) "ISW Tracking Number"
    ,(select FIELDVALUES from "TABLE" where NM_PARM = 'Line Of Business' and TRACKINGNUMBER = t.tn) "Line Of Business"
    ,(select FIELDVALUES from "TABLE" where NM_PARM = 'Type' and TRACKINGNUMBER = t.tn) "Type"
    from t
    
    Application Enter Your Message Have you reviewed FAQ? Have you reviewed User gui? ISW Tracking Number Line Of Business Type
    ----------- ------------------ ---------------------- --------------------------- ------------------- ---------------- ----------
    DRI INT     test               No                     No                                              AUTO             Suggestion
    BEST        test               No                     Yes                         none                CARDS            Question   
    
  • Cannot execute the sql command line

    Please someone help me trobleshooting the following error.

    SQL * MORE: Relese 11.2.0.2.0 production on 19 July 2013 Fri 12-34-23

    Copyright (c) 1982,2010,oracle.all rights reserved.

    Enter the user name: System

    Enter the password: "when I tried to enter the master password is not accept, then if I press on enter, I get the following error,

    Error:

    ORA - 01017:invalid username or password; connection refused

    Enter the user name: System

    Instead of trying to system

    Enter the user name: / as sysdba

    If your OS username is a member of the OSDBA Group (normally dba on ORA_DBA on Windows, Linux/Unix), you should be able to connect. When you do that, you can do what you want (you are the user SYS), for example to change password:

    SQL > alter the system of the user identified by ;

  • XMLTable turning lines

    I have the following XML
    <?xml version = '1.0' encoding = 'UTF-8'?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:sawsoap="urn://oracle.bi.webservices/v6">
       <soap:Body>
          <sawsoap:getGroupsResult>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>Presentation Server Administrators</sawsoap:name>
                <sawsoap:accountType>1</sawsoap:accountType>
                <sawsoap:guid>bipse53c4188a730640cc6c0a242</sawsoap:guid>
             </sawsoap:account>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>AuthenticatedUser</sawsoap:name>
                <sawsoap:accountType>4</sawsoap:accountType>
                <sawsoap:guid>AuthenticatedUser</sawsoap:guid>
             </sawsoap:account>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>BIConsumer</sawsoap:name>
                <sawsoap:accountType>4</sawsoap:accountType>
                <sawsoap:guid>BIConsumer</sawsoap:guid>
             </sawsoap:account>
          </sawsoap:getGroupsResult>
       </soap:Body>
    </soap:Envelope>
    I am trying to generate a list of the types of accounts, which in this case would be just

    Presentation server administrators
    AuthenticatedUser
    BIConsumer

    I am using the following SQL statement in my attempt, but it returns no rows.
    select x.*
    from tony, xmltable ('/account'
    passing extract(x,'//sawsoap:getGroupsResult','xmlns:sawsoap="urn://oracle.bi.webservices/v6"')
    columns 
     group_name varchar2(255) path '/name'
     ) x;
    I tried different combinations of XPath queries, including the sawsoap:account and the sawsoap:name, but other continue to return no records. I feel that I am close and he would appreciate a second set of eyes who could report the error.

    Tony

    Welcome to the forums. When posting, always include your version, as evidenced
    Select * from version $ v

    It makes a difference. For your question, you mix a few pre 10.2 syntax (excerpt) with syntax (XMLTable) 10.2 and later.

    What you're looking for is something like

    WITH tony AS
    (SELECT XMLTYPE('
       
          
             
                Presentation Server Administrators
                1
                bipse53c4188a730640cc6c0a242
             
             
                AuthenticatedUser
                4
                AuthenticatedUser
             
             
                BIConsumer
                4
                BIConsumer
             
          
       
    ') x
       FROM dual)
    -- The above WITH simulates your table.  You only care about the below
    SELECT x.*
      FROM tony,
           XMLTable(XMLNamespaces('http://schemas.xmlsoap.org/soap/envelope/' AS "soap",
                                  'urn://oracle.bi.webservices/v6' AS "sawsoap"),
                    '/soap:Envelope/soap:Body/sawsoap:getGroupsResult/sawsoap:account'
                    PASSING tony.x
                    COLUMNS
                    group_name   VARCHAR2(40) PATH 'sawsoap:name'
                   ) x;
    
    GROUP_NAME
    ----------------------------------------
    Presentation Server Administrators
    AuthenticatedUser
    BIConsumer
    
  • SQL help - lines, view by grouping...

    Greetings!

    Is this possible in Oracle 10 g using the SQL statement.

    EMP table - EMPLID, DEPTID fields.
    Data: E01, D01
    E02, D01
    E03, D01
    E11, D11
    E12, D11

    I'm looking for output as follows using a SQL statement...

    DeptID, EmplID
    D01 E01
    E02
    E03
    D11, E11
    E12


    Thanks in advance.

    Try this:

    WITH emp AS
    (SELECT 'E01' emplid, 'D01' deptid FROM dual UNION ALL
     SELECT 'E02' emplid, 'D01' deptid FROM dual UNION ALL
     SELECT 'E03' emplid, 'D01' deptid FROM dual UNION ALL
     SELECT 'E11' emplid, 'D11' deptid FROM dual UNION ALL
     SELECT 'E12' emplid, 'D11' deptid FROM dual)
    SELECT   CASE ROW_NUMBER () OVER (PARTITION BY deptid ORDER BY deptid)
             WHEN 1 THEN deptid||','||emplid
             ELSE emplid
             END dept_emp
    FROM     emp
    ORDER BY deptid,
             emplid
    
  • % Rowcount SQL returns lines more than number of table

    Look please copy the following code:

    DECLARE
    CURSOR c1 IS SELECT state_id, state_name, State st, licenses lic license_nbr
    WHERE st.license_id = lic.license_id;
    TYPE reg_t IS TABLE OF c1% ROWTYPE;
    v_array reg_t;
    BEGIN
    OPEN c1;
    LOOP
    C1 FETCH BULK COLLECT INTO v_array;
    FORALL i IN v_array. FIRST... v_array. LAST
    UPDATE st_lic sl
    SET state_id = v_array (i) .state_id,
    state_name = v_array (i) .state_name
    WHERE sl.license_nbr = v_array (i) .license_nbr;
    OUTPUT WHEN c1% NOTFOUND;
    END LOOP;
    CLOSE c1;
    DBMS_OUTPUT. Put_line ('count is:' |) SQL % ROWCOUNT);
    END;

    State_id is primary key for table 'States'. Each state_id has a single license_id.
    For the table "licenses", license_id is the primary key and license_nbr is not null and unique.
    For the 'st_lic' table, license_nbr is not null field and same license_nbr may appear several times.

    It is: sql % rowcount returns the number that is greater than the total number of rows in the st_lic table. Is possible? If Siu, how? I don't see anything wrong with the query.

    Thanks for the help!

    Published by: user5406804 on February 25, 2010 05:57

    consider to do away with the entire collection update in bulk and use a one-time block update. If you however decide to stick to the existing code, then SQL % BULK_ROWCOUNTwould be aplpied as follows:

    set serveroutput on
    DECLARE
      CURSOR c1 IS
        SELECT state_id, state_name, license_nbr
        FROM states st, licenses lic
        WHERE st.license_id =lic.license_id;
    
        TYPE reg_t IS TABLE OF c1%ROWTYPE;
        v_array reg_t;
    BEGIN
      OPEN c1;
      LOOP
        FETCH c1 BULK COLLECT INTO v_array ;
        EXIT WHEN c1%NOTFOUND; 
    
        FORALL i IN v_array.FIRST .. v_array.LAST
          UPDATE st_lic sl
          SET state_id = v_array(i).state_id,
          state_name = v_array(i).state_name
          WHERE sl.license_nbr = v_array(i).license_nbr;
    
        FOR i IN v_array.FIRST .. v_array.LAST loop
          DBMS_OUTPUT.PUT_LINE('Records updated = ' || SQL%BULK_ROWCOUNT(i));
        END LOOP;
    
      END LOOP;
    
      CLOSE c1;
    --  DBMS_OUTPUT.PUT_LINE('count is :' ||SQL%ROWCOUNT);
    END;
    

    This could work to replace all of the code above!

    UPDATE st_lic sl
    SET state_id = (SELECT state_id
                    FROM states st, licenses lic
                    WHERE st.license_id =lic.license_id
                    and   st.state_id = sl.state_id
                    and   lic.license_id=sl.license_nbr);
    

    -Not sure, UNTESTED!

    P;

    Published by: bluefrog on February 25, 2010 14:59

    UPDATE st_lic sl
    SET (state_id, state_name) = (SELECT st.state_id, st.state_name
                                  FROM   states st
                                        ,licenses lic
                                  WHERE  st.license_id  = lic.license_id
                                  and    st.state_id    = sl.state_id
                                  and    lic.license_id = sl.license_nbr);
    

    Published by: bluefrog on February 25, 2010 15:08 - I forgot the STATE_NAME

  • SQL generade line follownummer

    Hope someone can help me with the next issue...

    If I have a select statement as follows:
    Select Column1, Column2, Column3


    Column1 varchar key foreign field
    Column2 date field
    Column3 I want generade

    data:
    AAA 10/10/2009 1
    AAA 12/10/2009 2
    2009-10-14 AAA 3
    BBB 10/10/2009 1
    CCC 2009-10-10 1
    DDD 2009-10-10 1
    DDD 2009-10-13 2
    EEE 10/10/2009 1

    the Column3, generated number allways starts with 1.
    and 2 if there is a record.
    This number is orderd Column2 date.


    Thank you...

    Update:
    column3 column I want generade...
    the column does not exist.

    Published by: Ludock on October 16, 2009 15:17

    so you'll have to do a:

    SELECT column1, Column2, dense_rank() over (partition by order of Column1 Column2 ASC) as Column3
    From your_table
    /

    HTH

  • How to get line numbers to display on the SQL worksheet?

    Dear Forum,

    I learn the SQL Developer.  I use it in my work and school.  At school, when I enter a query in the SQL worksheet, line numbers show in a column to the left of the editing area.  In my work, no line number.  I'm working on a fairly long query at my work, and the line numbers would be useful.

    I looked at tools / preferences / settings for the Code Editor, but do not find a setting for line numbers.  I looked at the other tabs in preferences and found nothing that looked useful.

    I have looked at all of the choices on the display list, but can't find anything on line numbers.

    Am I missing something obvious?  Line numbers is also available?  If so, how?

    I looked at various hits "line number" in this forum, but I've not found anything exactly the point.

    Beverly

    PS Oracle 11g, SQL Developer 3.0.04, Linux x 86-64 (don't have version)

    Tools-> preferences /-> Code Editor-> line gutter

  • Command-line SQL appears then disappears

    I just installed the version 11g yesterday and I don't get a good start; can't run SQL command line.

    When I run the SQL command line (programs > Oracle Database 11g eXpress Edition > SQL command line) it appears for about a second then disappears
    SQL command line worked well during my first installation of Oracle Database 11 g eXpress Edition and I was able to connect as 'SYSTEM', but not after the reboot.

    Goes the same for the webpage to start; Now I get 'could not connect to 127.0.0.1:8080' when I go to programs > Oracle Database 11 g eXpress Edition > Get Started.
    Database of departure seems to work OK.

    When I run SQL * longer or Oracle SQL Developer, I get "ORA-12154: TNS: could not resolve the connect identifier specified" so this isn't really an option right now.

    Any thoughts on how to get the SQL command line work? Operating system is Windows XP, 32-bit.

    OracleServiceXE Windows service is started?

    From the command prompt:

    sqlplus / as sysdba

    SQL > startup

  • Could not connect to command line SQL Oracle XE

    Hello
    I use Oracle Xe on windows XP... I can connect to SQLPLUS using the windows shell with each of them to the account user and password as
    --------------------------------------------------------------------------------------------------------------
    Microsoft Windows XP [Version 5.1.2600]
    Copyright (C) 1985-2001 Microsoft Corp.

    H:\ > SQLPLUS MAYA/MARCO

    SQL * more: Release 10.2.0.1.0 - Production Thu Jun 30 17:28:12 2011
    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL >_
    ---------------------------------------------------------------------------------------------------------------
    but when I use the command line SQL Oracle to start-> all programs/Oracle Database 10 g Express Edition / * execute SQL Command Line * it brings the command SQL line with a quick line of SQL, but it connects to the database.

    ---------------------------------------------------------------------------------------------------------------
    SQL * more: Release 10.2.0.1.0 - Production Thu Jun 30 17:36:12 2011
    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    SQL > Select * from cat.
    SP2-0640: not connected
    SQL >
    ----------------------------------------------------------------------------------------------------------------
    and I met with the error "not connected". I'm sure that the database has already started successfully.
    Can you please let me know I'm doing wrong or what is problem with Oracle SQL Command Line?

    Thank you

    Hello

    What is

    connect MAYA/MARCO

    You can issue a query later?

    Kind regards

  • Query, which returns lines adding up to a value in a column

    Hello

    You are looking for an application that will process and return only the many lines that add up to a special value on a column value.

    for example

    ID name date_joined allocated salary

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

    1 Tom January 1, 2010 1000 5000

    Dave 2 3000 5000 February 1, 2010

    3 Cindy 1000 5000 01-apr-2010

    4 Ian 01-mar-2010 1000 5000

    5         Matt          10 -jan-2010 1000-5000

    Return the lines where wages adding upto or beyond the value allocated to 5000, order by date_joined or more former employee first.

    The query should return:

    ID name date_joined allocated salary

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

    1 Tom January 1, 2010 1000 5000

    2         Matt          10 -jan-2010 1000-5000

    3         Ian            01-mar-2010 1000 5000

    Dave 4 3000 5000 February 1, 2010

    We do not want to deal with or include other lines summarizing calculation, would instead add first, if deficit adds to the line.

    Tried with lead, windowed with range UNLIMITED etc. that PRECEDES, that would not come up with good logic.

    I could make it work with PL/SQL, but do it in SQL turns out to be delicate.

    Thank you.

    A.

    Thanks for the input guys.

    Here, the ask is:

    1. how to treat only as lines that satisfy the "allocated" value, without treatment of all lines.

    > Thanks to Jarkko year John for the right direction.

    > RanitB thank you for your approach to the application of the model, I am not well versed with model query that I'll get to. But for the moment its not useful for me.

    2. to get only as much lines that are either less than or equal to 'assigned' value or satisfy "allocated", from less than "attributed" just beyond "allocated".

    (Sorry for the language, if its not very clear, I do not know how this fits better, following example should help demonstrate).

    I came up with the following code, although there could be best way to do it, I hope to see someone.

    {code: sql}

    create table t:

    Select object_name, join_dt, the salary of 1000 last_ddl_time, allocated 5500

    of object;

    Select

    / * gather_plan_statistics * / *.

    Of

    (select

    object_name, join_dt, salary, allocated, sofar, lag (sofar, 1, 0) over (order by join_dt) lag_sofar

    Of

    (select

    object_name, join_dt, salary, allocated,

    Salary on sofar (order by no_lig)

    Of

    (select object_name, join_dt, salary, allocated, row_number() on no_lig (order of join_dt) t) t - must do it has several join_dt even inputs (objects have same time ddl)

    )

    )

    where

    allocated > lag_sofar;

    OBJECT_NAME JOIN_DT SALARY  ALLOCATED SOFAR LAG_SOFAR
    SDO_TOPO_GEOMETRY 17 JULY 02

    1000

    5500 1000 0
    SI_AVERAGECOLOR 18 JULY 02 1000 5500 2000 1000
    SI_COLORHISTOGRAM 18 JULY 02 1000 5500 3000 2000
    SI_POSITIONALCOLOR 18 JULY 02 1000 5500 4000 3000
    SI_FEATURELIST 18 JULY 02 1000 5500 5000 4000
    SI_STILLIMAGE 18 JULY 02 1000 5500 6000 5000

    {code}

    Sorry for the bad formatting, I tried couple of code integration/formatting of tags, but could not get formatting just as many of you have done above.

    Can someone point me on the document where the tags for this type of formatting is present?

    For now I am marking my question as answered with my own response and that of the other answers as useful.

    If I get a better approach/solution I would mark it as correct.

  • Running with SET DEFINE OFF sql

    We receive files sql (insert statements) to a third party via an automatic process. I want to load these files using sql * more, but also want to SET DEFINE OFF to prevent the substitution of variables. We cannot change the sql sort files. I use:

    sqlplus user/pass@db @file.sql

    Is there anyway that I can set the parameter in the command line? I do not particularly want to use glogin.sql like other scripts I need DEFINITION be on. Thank you.

    Hello

    LSU says:
    We receive files sql (insert statements) to a third party via an automatic process. I want to load these files using sql * more, but also want to SET DEFINE OFF to prevent the substitution of variables. We cannot change the sql sort files. I use:

    sqlplus user/pass@db @file.sql

    Is there anyway that I can set the parameter in the command line? I do not particularly want to use glogin.sql like other scripts I need DEFINITION be on. Thank you.

    Can you add the command "SET DEFINE OFF" at the beginning of the file.sql?

    If you cannot change the file.sql, and then create a script called define_off_and_run.sql, like this:

    --  define_off_and_run.sql - turns off substitution variables, then runs &1.sql
    
    SET  DEFINE  OFF
    
    @&1
    

    Then call it sqlplus like this:

    sqlplus  usernm/pass@db   @define_off_and_run file.sql
    

    If you can not do everything above, perhaps you could use instead of glogin.sql login.sql.

    This user should always have the VALUE SET OFF? (For example, this user is used only for this download process, or you can create a user to be used only for this download process?)
    If so, you can do a test to see who's the user in glogin.sql (or login.sql) and SET DEFINE OFF only if the special user.

Maybe you are looking for