SQL History - returning wrong statement if history is sorted

I have searched the forum and not seen anything on this, but I have been getting the wrong SQL statement returned when I select Append/Replace.
I have statements going back to 12-Jan-06 (using 804 since 13-Jan-06, 796 since 12-Jan-06 and 715 last year), so I don't know if I have hit the aging limit or not (I think I counted 221 entries).
It seems to me that it works out the cursor position and then returns that statement number from the history - independently of resorting the history.
For example, if I sort from oldest to newest (based on timestamp) and then select the bottom statement (displays as newest) and Replace, I get the oldest statement in the worksheet. If I select the top statement (displays as oldest) and Replace, I get the newest statement in the worksheet.
This is further complicated by the fact that sorting on the Timestamp is doing an alpha-numeric sort, rather than a date sort. When sorting from oldest to newest, the bottom three timestamps are (in "oldest to newest" order) are:
1/23/06 10:58 AM
1/23/06 9:21 AM
1/23/06 9:31 AM
If I then remove the sorting, the statement returned is the correct one.

It was great to get the fix for the SQL History returning the right statement if sorted (we got it in v1184).
However v1215 still does a text sort on the TimeStamp column rather than a date sort, so 2PM comes before 9AM, etc.
Also, where is the format for the TimeStamp column coming from? As someone who doesn't live in the US and thinks that days should come before months in date formats (ie DD-Mon-YYYY), I am frustrated by yet another product that uses MM/DD/YY, despite my best efforts at telling it otherwise.

Similar Messages

  • SQL query return wrong Windows version

    when excuting   'select @@VERSION' returns wrong Windows version. Why?

    when excuting   'select @@VERSION' returns wrong Windows version. Why?
    SELECT @@VERSION will return SQLServer version and not windows version
    Even in case of sql, if you're seeing a different version from what your management studio suggests, then it may be that you're SSMS (client tool) is of another later version whereas the server instance which you're actually connecting to may
    be of different (earlier) version.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Firefox 5.0 Cannot select "use custom settings for history" firefox reverts to "remember history" Why? Cannot access my mail inbox. is this a bug or have I done something wrong

    pc concerned is running XP home has firefox 5.0 I do not know
    what plugins firefox has

    If Firefox shows "Remember History" then that means that all history settings have the default value.<br />
    Only if all History settings are default then you see "Firefox will: (Never) Remember History".<br />
    "Use custom settings for history" reverts to "(Never) Remember history" if all History and Cookies settings have the default setting.<br />
    You see "Use custom settings for history" if at least one of the History or Cookie settings is not the default to make you aware that you made changes.<br />

  • REP-1401: 'no_daysformula':Fatal PL/SQL error occured. ora-06503: PL/SQL : Functio returned without value. REP-0619: You cannot run without a layout.

    Hi everyone.
    Can anyone tell me what is wrong in this code below?
    Code:
    function NO_DAYSFormula return Number is
    begin
      IF TO_CHAR(TO_DATE(:P_FR_DT, 'DD-MM-RRRR'), 'RRRR') =TO_CHAR(TO_DATE(:ACCT_OPN_DT, 'DD-MM-RRRR'), 'RRRR')
      AND :P_TO_DT<:MATURITY_DATE
      AND :ACCT_OPN_DT>:P_FR_DT
      THEN RETURN (:P_TO_DT-:ACCT_OPN_DT+1);
      ELSIF TO_CHAR(TO_DATE(:P_FR_DT, 'DD-MM-RRRR'), 'RRRR') =TO_CHAR(TO_DATE(:ACCT_OPN_DT, 'DD-MM-RRRR'), 'RRRR')
      AND :P_TO_DT<:MATURITY_DATE
      AND :ACCT_OPN_DT<:P_FR_DT
      THEN RETURN (:P_FR_DT-:P_TO_DT+1);
      ELSIF TO_CHAR(TO_DATE(:P_FR_DT, 'DD-MM-RRRR'), 'RRRR') =TO_CHAR(TO_DATE(:ACCT_OPN_DT, 'DD-MM-RRRR'), 'RRRR')
       AND :P_TO_DT>:MATURITY_DATE
       AND :ACCT_OPN_DT<:P_FR_DT
      THEN RETURN (:P_FR_DT-:MATURITY_DATE+1);
      END IF;
    END;
    It gets compiled successfully but when i run the report, i get 2 errors.
    Error 1:
    REP-1401: 'no_daysformula':Fatal PL/SQL error occurred.
    ora-06503: PL/SQL : Function returned without value.
    Error 2:
    REP-0619: You cannot run without a layout.
    Should i use only 1 return statement?
    Can i use as many return statements as i want?
    What is the exact mistake? Please let me know.
    Thank You.

    Let me clear you the first thing...
    If you get any fatal errors while running the report (e.g., function returned without value,no value etc.,) the report will show
    REP-0619: You cannot run without a layout.
    So you just correct the function 'no_daysformula' .
    First of all you run the report without that formula column.
    If it works fine then , Check the return value of your formula column (Your formula column properties --> Return value --> value (It will be DATE as i think so).
    As function will always return a single value, Check your formula 'no_daysformula' returns the same.
    declare a return variable say for example..
    DECLARE
    V_DATE DATE;
    BEGIN
    --YOUR CODE---
    RETURN V_DATE := (RETURN VALUE)
    END;
    Last but not least ... use Else condition to return (NULL or any value ) in your code and check..
    If any Problem persists let me know
    Regards,
    Soofi.

  • Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 537, state 3, severity 16

    Hello,
    I've encountered issue during installation of SP1 to SQL Server 2012. After upgrade I'm getting this error in Event Log:
    Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 537, state 3, severity 16. This is a serious error condition which might interfere with regular operation and the database will be taken offline.
    If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script
    upgrade steps run to completion.
    Can someone point me direction how I can fix it? This is a production server and currently only way to make it working is to use T902 flag in SQL Server startup params. I've found some suggestions to check Data path if it exists but it does so this is not
    the issue here. Any ideas?
    I've found also here
    http://www.sqlservercentral.com/Forums/Topic1377073-1550-1.aspx#bm1378279
    suggestions for similar issue with SQL Server 2008 which that I should do:
    Via ssms:
    From msdb:
    Delete:
    dc_admin role
    Dc_operator role
    Dc_proxy role
    UlitityCMRReader role
    UtilityIMRReader role
    UtilityIMRWriter role
    but for not I didn't tried it yet. This is standalone SQL Server instance.
    Any help really appreciated.
    Regards

    Script returns the same error.
    System databases:
    1    1    760    -1    10    1048578    0    1    master        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\master.mdf
    2    0    12768    -1    10    1048642    0    1    mastlog        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
    1    1    1024    -1    10    1048578    0    2    tempdev        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\tempdb.mdf
    2    0    64    -1    10    1048642    0    2    templog        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\templog.ldf
    1    1    288    -1    128    2    0    3    modeldev    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\model.mdf
    2    0    4464    -1    10    1048642    0    3    modellog    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\modellog.ldf
    1    1    28936    -1    10    1048578    0    4    MSDBData    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf
    2    0    3352    268435456    10    1048642    0    4    MSDBLog    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf
    are all in place where path shows.
    Before sending my message I've searched update script for "FROM master.sys.master_files" and I found script which you are showing me. I've made some digging and when I runned:
           SELECT physical_name
           FROM master.sys.master_files
           WHERE (name = N'master')
    it returned also path to one my customers database name which has filename set correctly but it's Logical DB name is master and mastlog. I'm running shared hosting company and I allow my customers to restore their DBs from .bak files but I have no idea why
    this customers logical name is set to master and mastlog. Probably when I change this names update script will work as it should. On the other hand in my opinion there should be some kind of fail safe mechanism for situations like this one.
    EDIT: After changing logical name for DB and log for mentioned DB your script runned fine so probably now when I remove T902 flag and restart my SQL Server update will run correctly. Big thanks for resolving this issue.

  • Pl/sql block returning sql query.

    Hello,
    I am using oracle 10g apex 3.2 version.
    I am using the following return statement inside my report which is pl/sql block returning sql query.
    declare
    pid varchar2(100);
    begin
    return 'select patient_id_code from t_files_data_exp where patient_id_code not in pid';
    end;
    How am i suppose to mention the pid inside the return stmt i mean with any quotes or anything? because the above return stmt gives error
    "1 error has occurred
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. The query can not be parsed, the cursor is not yet open or a function returning a SQL query returned without a value."
    Thanks

    Hello,
    I did exactly the way u told
    declare
    pid varchar2(100) := '(61092,61093)';
    begin
    return 'select patient_id_code from t_files_data_exp where patient_id_code not in ' || pid;
    end;
    patient_id_code is varchar2(100) only in table.
    For this i am getting "invalid number error".
    Thanks

  • Date format in PL/SQL Procuredure returning SQL Query

    We have parameters (a begin date and end date) that are entered in on a form and then passed as parameters to a report that is displayed using PL/SQL Procedure returning SQL Query. We would like the users to be able to enter the date in the format of mm/dd/yyyy but when we change the format mask on the begin and end date fields we get invalid month entered. I then went into my PL/SQL procedure and changed the code to the following
    q := q || ' WHERE ' ||
    '(:P41_W_BEGIN_DT IS NULL OR (:P41_W_BEGIN_DT IS NOT NULL AND
    :P41_W_BEGIN_DT <= to_char(HARDWARE_INFO.WARRANTY_END_DT,''mm/dd/yyyy')))
    AND
    (:P41_W_END_DT IS NULL OR (:P41_W_END_DT IS NOT NULL AND :P41_W_END_DT >=
    to_char(HARDWARE_INFO.WARRANTY_END_DT,''mm/dd/yyyy''))
    The code is accepted but when we run the report against the parameters it seems to only be looking at the mm/dd constraint it pays no attention to the YYYY constraint. In the to_char condition if I try using single tick marks it errors out. The only way I can get the tick marks to be accepted in the code is to use 2 single tick marks ''. Any ideas on what I am doing wrong.
    Thanks!

    user520671,
    You are doing the conversion in reverse. Because you're applying a function (TO_CHAR) to the columns in your predicate, you'll be negating the use of any indexes. Not prudent from a performance standpoint.
    Instead, convert your input values to a date and do the comparison that way.
    q := q || ' WHERE ' ||
    '(:P41_W_BEGIN_DT IS NULL OR
        (:P41_W_BEGIN_DT IS NOT NULL AND to_date(:P41_W_BEGIN_DT,''MM/DD/YYYY'') <= HARDWARE_INFO.WARRANTY_END_DT))
    AND
    (:P41_W_END_DT IS NULL OR
        (:P41_W_END_DT IS NOT NULL AND to_date(:P41_W_END_DT,''MM/DD/YYYY'') >= HARDWARE_INFO.WARRANTY_END_DT))'Also ensure that you are truly passing in a 4-digit year.
    Joel

  • OracleDataAdapter returning wrong number of columns

    Hello All,
    I have an issue of an oracle data adapter not returning all columns in my select statement. When I use code similar to below, the data adapter returns 2 columns per row instead of 5. And they are out of order (ie, DataRow(0) could be column 1 and DataRow(1) could be column 4 -- so I don't see which columns have been dropped without looking at the value).
    The database id XE on the local machine. The connection works fine. And the internal VS.NET PL/SQL debugger returns the query just fine.
    Some of the columns I'm trying to get are null -- in fact, most are. But they are changed during the program. So I still need them to show up in the dataset.
    BTW, I have had zero success getting OracleCommand.BindByName and OracleParameters to work, so I punted. Since I can get what I want out of readers and datasets, I can live without'em -- or can I?!?!
    I think my problem has something to do with handling null values. So I have tried the select statement with NVL wrapping the fields that could be null. But still no success.
    Any ideas?
    Table:
    account char(30) not null
    col_code as NUMBER(1,0) null ok
    columnIDontNeed as whatever null ok
    sum1 as char(1) null ok
    sum2 as char(1) null ok
    sum3 as char(1) null ok
    anotherColumnIDontNeed as whatever null ok
    Sample Code:
    dim oconn as New OracleConnection(conStrBldr.toString)
    Dim cmdLedger As OracleCommand = oconn.CreateCommand
    cmdLedger.BindByName = True ' seems to affect nothing! ever!
    cmdLedger.AddToStatementCache = False ' no noticable affect
    cmdLedger.CommandText = " SELECT account,col_code,sum1,sum2,sum3 "
    cmdLedger.CommandText &= "FROM gl.ledger "
    cmdLedger.CommandText &= "ORDER BY gl.ledger.account "
    cmdLedger.CommandType = CommandType.Text
    ' Create DataAdapter based on main Ledger SELECT
    Dim cmdLedgerDA As New OracleDataAdapter(cmdLedger)
    cmdLedgerDA.ReturnProviderSpecificTypes = True ' same results with False
    ' Create DataSet and Fill it.
    ' After this, we can now use this dataset
    ' to iterate through the GL ledger data.
    Dim cmdLedgerDS As New DataSet("GLBal")
    Try ' to fill dataset with Ledger SELECT
    ' fill dataset from OracleDataAdapter and the
    ' previously defined Oracle Command.
    cmdLedgerDA.Fill(cmdLedgerDS, "GL.LEDGER") ' tried with and without src
    Catch ex As OracleException
    ShowEx(ex)
    End Try ' to fill dataset with Ledger SELECT
    These are the typical test from within VB that I've run to check what was returned:
    console.writeline(cmdLedgerDS.Tables(0).Rows(0).ItemArray.Length)
    2
    dim row as DataRow = cmdLedgerDS.Tables(0).Rows(0)
    console.writeline(row(0).toString & row(1).toString & row(2).toString & row(3).toString & row(4).toString) ' EXCEPTION IS THROWN

    I cannot reproduce the error using basic code below. What is the specific exception you get?
    And BindByName is not necessary since you're not using bind variables
    Sub Main()
        Dim da As OracleDataAdapter
        Dim sqlstr As String
        Dim connstr As String
        Dim ds As DataSet
        Dim dr As DataRow
        Dim dc As DataColumn
        Try
            sqlstr = "select employee_id, first_name, last_name, null, salary "
            sqlstr &= "from employees where rownum < 10"
            connstr = "Data Source=xe;User ID=hr;Password=hr;"
            da = New OracleDataAdapter(sqlstr, New OracleConnection(connstr))
            ds = New DataSet("EmployeeDS")
            da.Fill(ds, "employees")
            For Each dc In ds.Tables("employees").Columns
                Console.Write(dc.ColumnName & " ")
            Next
            Console.WriteLine()
            For Each dr In ds.Tables("employees").Rows
                Console.WriteLine(dr(0).ToString & " " & _
                    dr(1).ToString & " " & dr(2).ToString & " " & _
                    dr(3).ToString & " " & dr(4).ToString)
            Next
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End SubOutput should look like
    EMPLOYEE_ID FIRST_NAME LAST_NAME NULL SALARY
    100 Steven King  24000
    101 Neena Kochhar  17000
    102 Lex De Haan  17000
    103 Alexander Hunold  9000
    104 Bruce Ernst  6000
    105 David Austin  4800
    106 Valli Pataballa  4800
    107 Diana Lorentz  4200
    108 Nancy Greenberg  12000I am using VS2005, ODP 10.2.0.2.21 and OracleXE on remote machine.
    NH
    Message was edited by:
    nurhidayat

  • PL/SQL: Function returned without value in authentication schemes

    Hi all,
    finally i did the authentication shemes based on my function and my own table ,thank you all for help :-) ,but now when i enter
    1-correct user name &wrong password <it is gonna work,the authentication workin fine >
    i am gonna get <Invalid Login Credentials> which is right in case of wrong login
    2-wrong user name &wrong password <it is not gonna work>
    3-wrong user name &correct password <it not gonna work>
    in case of not working i am getting the following error:
    ORA-06503: PL/SQL: Function returned without value
    Error ERR-10460 Unable to run authentication credential check function.
    any help to solve this issue so that it will display <Invalid Login Credentials>
    in all cases of invalid login
    thanks in advance ,
    Ahmed,

    scott,you efforts was useful and i beleive that the error that i am getting it is from the function that i have can you please take a look on :
    FUNCTION CHECK_USER
    ( P_USERNAME IN varchar2,
    P_PASSWORD IN varchar2)
    RETURN boolean
    IS
    BEGIN
    for c1 in (select user_name, password from vms2_employee_details where user_name = P_USERNAME)
    loop
    if P_PASSWORD = c1.password then
    return true;
    ------dbms_output.put_line('the return from the function is true');
    else
    return false;
    ----dbms_output.put_line('the return from the function is false');
    end if;
    end loop;
    EXCEPTION
    WHEN no_data_found THEN
    return false;
    when others then
    return false;
    ----dbms_output.put_line('the return from the function is false');
    END;
    and tell me what do you think ,
    thanks,
    ahmed

  • ORA-06503: PL/SQL: Function returned without value

    Hello
    Having a bit of a problem with piplined functions.
    Why does this work :
    SET SERVEROUTPUT ON
    DECLARE
    TYPE SARRAY IS TABLE OF VARCHAR2(4000);
    CURSOR CU IS SELECT * FROM DX_XML_ATTENDANCE WHERE STUD_ID = 107777 AND BASE_ID = 94;
    T_STUD NUMBER(10);
    T_BASE NUMBER(10);
    T_DATE DATE;
    T_MARKS VARCHAR2(1000);
    LEN_MARKS NUMBER;
    PDATE DATE;
    SDATE DATE;
    EDATE DATE;
    SLEN NUMBER;
    WEEKLEN NUMBER;
    INIPOS NUMBER;
    MARRAY VARCHAR2(1000);
    SUBARRAY SARRAY := SARRAY();
    SFILL VARCHAR2(14) := '--------------';
    EPOS NUMBER;
    MY_REC     DX_XML_ATTENDANCE%ROWTYPE;
    BEGIN
    SUBARRAY.EXTEND(17);
    DBMS_OUTPUT.ENABLE(100000000);
    --FOR MY_REC IN CU
    OPEN CU;
    LOOP
         FETCH CU INTO MY_REC;
         EXIT WHEN (CU%NOTFOUND);
    T_STUD := MY_REC.STUD_ID;
    T_BASE := MY_REC.BASE_ID;
    T_DATE := TO_DATE(MY_REC.START_DATE, 'DD/MM/YYYY');
    T_MARKS := MY_REC.MARKS;
    LEN_MARKS := LENGTH(T_MARKS);
    EPOS := LEN_MARKS / 2;
    SDATE := ROUND(TO_DATE(T_DATE), 'W') - 1;
    INIPOS := TO_NUMBER(TO_CHAR(T_DATE, 'D'));
    SLEN := INIPOS + 3;
    PDATE := SDATE;
    EDATE := SDATE + EPOS;
    MARRAY := SUBSTR(T_MARKS, 1, SLEN);
    WEEKLEN := LENGTH(MARRAY);
    IF WEEKLEN < 14 THEN
         MARRAY := SUBSTR(SFILL, 1, 14 - WEEKLEN) || MARRAY;
    END IF;
    SUBARRAY(1) := T_STUD;
    SUBARRAY(2) := T_BASE;
    SUBARRAY(3) := PDATE;
    FOR i IN 4 .. 17 LOOP
         SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(SUBARRAY(1)||' '||SUBARRAY(2)||' '||SUBARRAY(3)||' '||SUBARRAY(4)||' '||
         SUBARRAY(5)||' '||SUBARRAY(6)||' '||SUBARRAY(7)||' '||SUBARRAY(8)||' '||SUBARRAY(9)||' '||
         SUBARRAY(10)||' '||SUBARRAY(11)||' '||SUBARRAY(12)||' '||SUBARRAY(13)||' '||SUBARRAY(14)||' '||
         SUBARRAY(15)||' '||SUBARRAY(16)||' '||SUBARRAY(17));
    WHILE PDATE < EDATE LOOP
         PDATE := PDATE + 7;
         MARRAY := SUBSTR(T_MARKS, SLEN + 1, 14);
         WEEKLEN := LENGTH(MARRAY);
         IF WEEKLEN < 14 THEN
              MARRAY := MARRAY || SUBSTR(SFILL, 1, 14 - WEEKLEN);
         END IF;
         FOR i IN 4 .. 17 LOOP
              SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
         END LOOP;
         SUBARRAY(3) := PDATE;
    DBMS_OUTPUT.PUT_LINE(SUBARRAY(1)||' '||SUBARRAY(2)||' '||SUBARRAY(3)||' '||SUBARRAY(4)||' '||
         SUBARRAY(5)||' '||SUBARRAY(6)||' '||SUBARRAY(7)||' '||SUBARRAY(8)||' '||SUBARRAY(9)||' '||
         SUBARRAY(10)||' '||SUBARRAY(11)||' '||SUBARRAY(12)||' '||SUBARRAY(13)||' '||SUBARRAY(14)||' '||
         SUBARRAY(15)||' '||SUBARRAY(16)||' '||SUBARRAY(17));
         PDATE := PDATE + 7;
         SLEN := SLEN + 14;
    END LOOP;
    END LOOP;
    END;
    and this does not :
    CREATE OR REPLACE PACKAGE BODY PARSE_ATTENDANCE AS
    FUNCTION ENUM_MARKS(SEL_SQL IN VARCHAR2)
    RETURN TMP_ATT_DATA_TBL PIPELINED
    IS
    V_SQL           VARCHAR(1000):= SEL_SQL;
    V_CURSOR      SYS_REFCURSOR;
    V_ROW          TMP_ATT_HOLDING:=TMP_ATT_HOLDING(NULL, NULL, NULL, NULL);
    T_STUD           NUMBER(10);
    T_BASE           NUMBER(10);
    T_DATE           DATE;
    T_MARKS      VARCHAR2(1000);
    LEN_MARKS      NUMBER;
    PDATE          DATE;
    SDATE          DATE;
    EDATE          DATE;
    SLEN           NUMBER;
    WEEKLEN      NUMBER;
    INIPOS           NUMBER;
    MARRAY           VARCHAR2(1000);
    SUBARRAY      SARRAY := SARRAY();
    SFILL           VARCHAR2(14) := '--------------';
    EPOS           NUMBER;
    BEGIN
    SUBARRAY.EXTEND(17);
    OPEN V_CURSOR FOR V_SQL;
    LOOP
         FETCH V_CURSOR INTO V_ROW.STUD_ID, V_ROW.BASE_ID, V_ROW.START_DATE, V_ROW.MARKS;
         EXIT WHEN V_CURSOR%NOTFOUND;
    T_STUD := V_ROW.STUD_ID;
    T_BASE := V_ROW.BASE_ID;
    T_DATE := TO_DATE(V_ROW.START_DATE, 'DD/MM/YYYY');
    T_MARKS := V_ROW.MARKS;
    LEN_MARKS := LENGTH(T_MARKS);
    EPOS := LEN_MARKS / 2;
    SDATE := ROUND(TO_DATE(T_DATE), 'W') - 1;
    INIPOS := TO_NUMBER(TO_CHAR(T_DATE, 'D'));
    SLEN := INIPOS + 3;
    PDATE := SDATE;
    EDATE := SDATE + EPOS;
    MARRAY := SUBSTR(T_MARKS, 1, SLEN);
    WEEKLEN := LENGTH(MARRAY);
    IF WEEKLEN < 14 THEN
         MARRAY := SUBSTR(SFILL, 1, 14 - WEEKLEN) || MARRAY;
    END IF;
    SUBARRAY(1) := T_STUD;
    SUBARRAY(2) := T_BASE;
    SUBARRAY(3) := PDATE;
    FOR i IN 4 .. 17 LOOP
         SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
    END LOOP;
    PIPE ROW(TMP_ATT_DATA_OBJ(SUBARRAY(1),SUBARRAY(2),SUBARRAY(3),SUBARRAY(4),
         SUBARRAY(5),SUBARRAY(6),SUBARRAY(7),SUBARRAY(8),SUBARRAY(9),
         SUBARRAY(10),SUBARRAY(11),SUBARRAY(12),SUBARRAY(13),SUBARRAY(14),
         SUBARRAY(15),SUBARRAY(16),SUBARRAY(17)));
    WHILE PDATE < EDATE LOOP
         PDATE := PDATE + 7;
         MARRAY := SUBSTR(T_MARKS, SLEN + 1, 14);
         WEEKLEN := LENGTH(MARRAY);
         IF WEEKLEN < 14 THEN
              MARRAY := MARRAY || SUBSTR(SFILL, 1, 14 - WEEKLEN);
         END IF;
         FOR i IN 4 .. 17 LOOP
              SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
         END LOOP;
         SUBARRAY(3) := PDATE;
         PIPE ROW(TMP_ATT_DATA_OBJ(SUBARRAY(1),SUBARRAY(2),SUBARRAY(3),SUBARRAY(4),
         SUBARRAY(5),SUBARRAY(6),SUBARRAY(7),SUBARRAY(8),SUBARRAY(9),
         SUBARRAY(10),SUBARRAY(11),SUBARRAY(12),SUBARRAY(13),SUBARRAY(14),
         SUBARRAY(15),SUBARRAY(16),SUBARRAY(17)));
         PDATE := PDATE + 7;
         SLEN := SLEN + 14;
    END LOOP;
    END LOOP;
    END ENUM_MARKS;
    END PARSE_ATTENDANCE;
    (This is then called like SELECT * FROM
    TABLE(
    PARSE_ATTENDANCE.ENUM_MARKS(
    'SELECT STUD_ID, BASE_ID, START_DATE, MARKS
    FROM DX_XML_ATTENDANCE WHERE STUD_ID = 107777
    AND BASE_ID = 94'))
    I get the same error, around this section near the bottom :
         PDATE := PDATE + 7;
         SLEN := SLEN + 14;
    Can any one help?

    Here is an example. you are missing an return statement.
    SQL> create or replace type varchar2_table is table of varchar2(10) ;
      2  /
    Type created.
    SQL> show errors
    No errors.
    SQL> create or replace function get_data return varchar2_table pipelined is
      2  begin
      3      pipe row(('Test')) ;
      4  end ;
      5  /
    Function created.
    SQL> show errors
    No errors.
    SQL> select * from table(get_data) ;
    ERROR:
    ORA-06503: PL/SQL: Function returned without value
    ORA-06512: at "KKISHORE.GET_DATA", line 3
    no rows selected
    SQL> create or replace function get_data return varchar2_table pipelined is
      2  begin
      3      pipe row(('Test')) ;
    4 return ;
      5  end ;
      6  /
    Function created.
    SQL> show errors
    No errors.
    SQL> select * from table(get_data) ;
    COLUMN_VAL
    Test
    SQL>

  • Plugin with PL SQL function returning query

    Hi all,
    I have created plugin using SQL query many times. But can we create a plugin from scratch using PL SQL function returning SQL query? Any ideas or sample.
    Thanks
    Sunil Bhatia

    Hi Scott,
    By this i mean, i have created a region type plugin for integrating jqx Grid into oracle apex. This takes input parameter as SQL statement, and creates jqx grid for me on page. Now my question is, can i do this using PL SQL function returning SQL, because when i try to give return statement, plugin gives error "SQL statement mandatory'. I hope i am clear enough now.
    Thanks
    Sunil Bhatia

  • Help with an SQL Expression - Return field value where Datetime is Min or First datetime

    Hello,
    I'm extracting results for a patient population.
    I have 6 SQL expressions that pull back the first date for specific procedures or Medications being ordered.
    These Expressions work perfect - One of the expressions return the first time a lab was ordered.
    I'm using SQL that return
    Min(OrderDatetime)
    From OrderTable
    Where
    LABCode = XXX
    I've now been ask to return the value of this lab result.
    Question: How do I write an SQL expression that return the Lab value of the Min(OrderDatetime)
    Example Data
    PATID* LABID * OrderDatetime * ResultValue
    Pat1*133 * 12/12/2013 11:00:pm * 77
    Pat1*145 * 12/12/2013 11:45:pm * 45
    Pat1*147 * 12/13/2013 12:10:AM * 78
    I was to return 77
    Thanks
    Steve

    Here is what I came up with but I'm getting an error -
    Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <,>,>= or when the subquery is used as an expression.
    Any thoughts on what I'm doing wrong?
    SELECT LABRESULTS.ORDER_VALUE as LabResult
      FROM   LABRESULTS, ORDERS_PROD, PATIENT_HSP
      WHERE
    "ORDERS_PROD"."CSN_ID" = "LABRESULTS"."CSN_ID" AND
    "ORDERS_PROD"."ORDER_PROC_ID" = "LABRESULTS"."ORDER_PROC_ID" AND
    ORDERS_PROD.ORDER_INST IN     (
                                  SELECT Min(ORDERS_PROD.ORDER_INST)
                                  FROM   ORDERS_PROD
                                  WHERE "PATIENT_HSP"."CSN_ID" = "ORDER_PROD"."CSN_ID" AND
                                  ("ORDERS_PROD"."ORDER_STATUS_C"<>4 OR
                                  "ORDERS_PROD"."ORDER_STATUS_C"<>9) AND
                                  "ORDERS_PROD"."FUTURE_OR_STAND" IS  NULL AND
                                  "ORDERS_PROD"."REASON_FOR_CANC_C" IS  NULL AND
                                  ("ORDERS_PROD"."PROC_CODE" = 'LAB7764' OR
                                  "ORDERS_PROD"."PROC_CODE" = 'LAB7765' OR
                                  "ORDERS_PROD"."PROC_CODE" = 'LAB7766' OR
                                  "ORDERS_PROD"."PROC_CODE" = 'LAB7767')

  • Function sometimes return wrong data

    Hi all.
    I have a very strange problem with a function. Situation is this: I have an application that handles processes. Each process have a number of steps that is arranged in a matrix like layout. User clicks a step to start/execute it.
    Now in a list of current processes i want to have an indication of how "far" a process has reached so i created a function for that and included that in my processlist fetch.
    gchs_user_process_steps is the table where the user data for the process step is
    gchs_process_steps is the definition table of what steps a process has
    gchs_steps is the definition table of all steps
    The below function is supposed to return latest step user clicked in the display matrix. tier is used to store the column number and sortorder is the row number of any step user clicked.
    CREATE OR REPLACE FUNCTION FN_REACHEDSTEP(p_user_process_id NUMBER)
    RETURN VARCHAR IS
      ret VARCHAR(30);
      ret_id INTEGER;
      ret_num INTEGER;
    BEGIN
       ret := '';
       ret_id := 0;
       ret_num := 0;
       BEGIN
    SELECT substr(step_name,1,30),step_id,reached INTO ret,ret_id,ret_num
    FROM (
    SELECT a.*, rownum rnum
    FROM (
        SELECT s.name AS step_name, ps.id AS step_id, max((ps.tier*1000)+ps.sortorder) AS reached
        FROM gchs_user_process_steps ups, gchs_process_steps ps, gchs_steps s
        WHERE ups.gchs_process_step_id=ps.id AND
           ps.gchs_step_id=s.id AND
           ups.gchs_user_process_id=p_user_process_id
        GROUP BY s.name,ps.id
        ORDER BY 3 DESC) a
    WHERE rownum <= 1 )
    WHERE rnum >= 1;
       EXCEPTION
         WHEN OTHERS THEN
            ret:='';
       END;     
          RETURN ret;
      EXCEPTION
    WHEN OTHERS THEN
           ret := '';
       RETURN ret;
    END FN_REACHEDSTEP;
    Now the problem is that the function sometimes return wrong value. The name of the step that is returned is not the one i get if i run the SQL by itself.
    So doing a
    SELECT substr(step_name,1,30),step_id,reached INTO ret,ret_id,ret_num
    FROM (
    SELECT a.*, rownum rnum
    FROM (
        SELECT s.name AS step_name, ps.id AS step_id, max((ps.tier*1000)+ps.sortorder) AS reached
        FROM gchs_user_process_steps ups, gchs_process_steps ps, gchs_steps s
        WHERE ups.gchs_process_step_id=ps.id AND
           ps.gchs_step_id=s.id AND
           ups.gchs_user_process_id=21680
        GROUP BY s.name,ps.id
        ORDER BY 3 DESC) a
    WHERE rownum <= 1 )
    WHERE rnum >= 1;
    and a
    select fn_ReachedStep(21680) from dual;
    will sometimes return different values.
    So is the function fundamentally wrong or is there any cache or something that i've missed that could hold "old" function outputs or am i missing something else.
    Thankful for any clues.
    I'm using Oracle 10.2.0.1.0
    Best regards
    /Tomas
    Edit: Here's some data that the system uses.
    gchs_steps
    ID           NAME
    10000     Step 1
    10020     Step 2
    10021     Step 3
    10022     Step 4
    10023     Step 5
    10060     Step 6
    10140     Step 7
    gchs_process_steps
    ID          GCHS_STEP_ID      TIER     SORTORDER
    10000     10000               0          1
    10001     10020               1          1                                                                                                                   
    10002     10021               1          2                                                                                                                   
    10003     10022               2          1
    10020     10023               3          5
    10060     10060                3          4
    10080     10140               3          2
    10040     10040               3          3
    10100     10160               4          3
    10160     10220               4          2
    11640     11640               3          1
    11660     11660               0          6
    11661     11661               0          7
    11600     11600               0          4
    11620     11620               4          1
    gchs_user_process_steps
    ID          GCHS_USER_PROCESS_ID     GCHS_PROCESS_STEP_ID
    35541     21680                         10002
    38441     21680                         10020
    38440     21680                         10000
    52062     21680                         10060
    Relations beween table is
    gchs_user_process_steps.gchs_process_step_id=gchs_process_steps.id
    and
    gchs_process_steps.gchs_step_id=gchs_steps.id
    So doing the SQL alone will always return
    SUBSTR(..)     STEP_ID REACHED
    Step 5      10020 3005
    but executing the function sometimes returns
    FN_REACHEDSTEP(21680)
    Step 6
    Also removing the rownum limits return and doing a
    SELECT s.name AS step_name, ps.id AS step_id, max((ps.tier*1000)+ps.sortorder) AS reached
    FROM gchs_user_process_steps ups, gchs_process_steps ps, gchs_steps s
    WHERE ups.gchs_process_step_id=ps.id AND
    ps.gchs_step_id=s.id AND
    ups.gchs_user_process_id=21680
    GROUP BY s.name,ps.id,ps.tier, ps.sortorder
    ORDER BY 3 DESC
    give this result
    STEP_NAME     STEP_ID     REACHED
    Step 5          10020     3005
    Step 6          10060     3004
    Step 3          10002     1002
    Step 1          10000     1
    Edited by: user4935832 on 2008-sep-19 01:38

    ORDER BY 3 DESC) a
    WHERE rownum <= 1 )
    WHERE rnum >= 1;Just some thoughts.
    1. You could replace "ORDER BY 3" by "ORDER BY reached"
    2. the rownum <=1 and rnum>=1 will return only one row... I don't understand the second one.
    Lastly, the difference might come from a duplicate value return by your MAX() function.
    If there is two rows (or more) with same MAX, Oracle might return one row arbitrary.
    To get the same row, you have to use some aggregation function like MAX() KEEP (DENSE_RANK LAST...).
    Here a try for your query, obviously not tested :
    SELECT max(substr(step_name,1,30)) keep (dense_rank last order by reached) as step_name,
           max(step_id) keep (dense_rank last order by reached,step_name) as step_id,
           max(reached) as reached
    FROM   (SELECT s.name AS step_name,
                   ps.id AS step_id,
                   max((ps.tier*1000)+ps.sortorder) AS reached
            FROM   gchs_user_process_steps ups,
                   gchs_process_steps ps,
                   gchs_steps s
           WHERE   ups.gchs_process_step_id=ps.id
           AND     ps.gchs_step_id=s.id
           AND     ups.gchs_user_process_id=21680
           GROUP BY s.name,ps.id) a;Nicolas.

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

  • Report returns wrong data when run on server

    Hi,
    I'm runing CRS XI R2 on Windows Server 2003 SP2.  When I refresh a report in the Crystal Reports XI Designer, I'm getting correct data.  But when I schedule the report to run on the server it returns wrong data.  The data is different from what I see when I refresh it from the designer.  In the report I have running totals set up to count customers that meet a certain criteria.  The report is very large.  It take almost 2 hours to refresh.
    I was wondering what is causing the difference in running total data between refreshing it on the designer and running it on the server.  Is it returning wrong data b/c of it not reading all the records?  Should I be making any changes to the server settings?  I saw that under pageserver, there are options for  setting the 'Minutes Before an Idle Report Job is Closed' and 'Database Records To Read When Previewing Or Refreshing a Report".  Do either of those have anything to do with the report returning incorrect data when being scheduled to run on the server?
    Thanks,
    Kim

    Hi Xuandao,
    You would need to Use Cell Binding and Trigger concept to accomplish this.
    Its simple, however, you would have to work on a trial and error basis to understand this concept as implementing the same is subject to your dashboard and WEBI Design.
    Open you LiveOffice.
    Insert your WEBI, Now, go to Object Properties of your WEBI, select the second tab that says Prompt, Here, it lists the prompts that you have for your WEBI. This would also enlist your BEx variables as well. Select this BEx variable and click on the button that says Prompt at the bottom of this window. Here, select choose Excel Data Range and click on the cell select button on the right (small button that lets you choose what cell you want to bind this prompt to), Now select a free cell that would not be even populated later on when you run the dashboard say A1 (remember the value that you select). Click on OK and again OK. The WEBI Refreshes and you can see all the prompt values at the cell A1. These are all the possible values stored for your BEx prompt variables (these values are fetched from BW system dynamically).
    Now, save this LiveOffice, Go to you dashboard. Connect your dashboard to your Live office. Go to Data-> connections-> Now, select the WEBI and in the right hand pane  go to Usage tab, here, Click on Trigger cell button on the right hand side and select A1 in you LiveOffice.
    It should work fine.
    Let me know.
    Rgds,
    Sreekul Nair

Maybe you are looking for