working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,317 snippets matching: oracle

    public by cghersi @ Thotpot alumni modified May 4, 2013  303252  0  5  0

    Java: generate hprof during runtime

    To generate hprof may be interesting for debug purpose, most of all before an OutOfMemory occurs on production applications! This .ini option halps to create an hprof to be analyzed before the occurrence of memory errors. See http://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html for further details
    java -Xrunhprof:heap=sites,depth=10,thread=y,doe=y ...other jvm options in ini file...

    public by RSrini modified Jun 17, 2015  237565  43  3  0

    Installing db-sample-schema in windows (https://github.com/oracle/db-sample-schemas)

    Installing db-sample-schema in windows (https://github.com/oracle/db-sample-schemas): db-sample-schemas
    https://github.com/oracle/db-sample-schemas
    
    download the zip file and extract to "D:\app\rsrini7\product\12.1.0\dbhome_1\demo\schema"
    
    here rsrini7 is my username. extract the zip file to the dir according to your installation.
    
    open command prompt as administrator
    d: enter
    cd D:\app\rsrini7\product\12.1.0\dbhome_1\demo\schema
    
    mkdir log
    
    perl -p -i.bak -e 's#__SUB__CWD__#'D:/app/rsrini7/product/12.1.0/dbhome_1/demo/schema/'#g' *.sql */*.sql */*.dat
    
    (to install perl and other unix related tools - install babun - rocking tool for windows users. i love this )
    
    edit mksample.sql and all '_main.sql' files and follow the below instructions
    
    this is required : http://www.dba-oracle.com/t_ora_65096_create_user_12c_without_c_prefix.htm
    
    1. in connect statement 
    	add at the end 'as sysdba'
    2. after the connect statement add the below line
    	alter session set "_oracle_script"=true;
    
    type in the command prompt : sqlplus enter
    connect oracle with sys as sysdba and enter
    type the dba-password 
    
    At final execute the below script from sql prompt
    	
    @?/demo/schema/mksample <dba-password> <dba-password> password password password password password password EXAMPLE TEMP D:/app/rsrini7/product/12.1.0/dbhome_1/demo/schema/log/
    
    replace <dba-password> with the actual dba password
    
    happy learning:)
    
    

    public by DinhoPutz modified Jan 30, 2019  46  2  3  0

    Função para converter minutos para horas (SQL Oracle)

    PLSQL - SQL Oracle
    -- Criando nova função
    create or replace function converter (
        numero in  number 
    ) return varchar2
    is
        minutos varchar2(10);
    begin
        
    return 
    
    	case length 
        
         (case instr((numero / 60), '.')  
            when 2 then '0'  || substr((numero / 60), 1 ,1)
            when 3 then substr((numero / 60), 1 ,2)
        else to_char(numero / 60)
        end || '.' || lpad(mod(numero, 60), 2, 0))  
    	
    			when 4 then '0' || 
    			case instr((numero / 60), '.')  
    			when 2 then '0'  || substr((numero / 60), 1 ,1)
    			when 3 then substr((numero / 60), 1 ,2)
    		else to_char(numero / 60)
        end || '.' || lpad(mod(numero, 60), 2, 0) 
       
       else 
    		 case instr((numero / 60), '.')  
    			when 2 then '0'  || substr((numero / 60), 1 ,1)
    			when 3 then substr((numero / 60), 1 ,2)
    		else to_char(numero / 60)
        end || '.' || lpad(mod(numero, 60), 2, 0)   -- temos os minutos
       
       end ;
        
    end converter;
    /
    
    
    select  converter(valor), valor as valors from horario where  valor is not null

    public by rsrini7 modified Feb 11, 2016  2715  0  3  0

    basic oracle user setup

    basic oracle user setup: oracle_basic_user_setup.sql
    connect system/<password> as sysdba
    
    create user srini identified by srini;
    grant create session to srini;
    grant create table to srini;
    grant unlimited tablespace to srini;
    
    
    

    public by lbottaro modified Feb 19, 2013  3292  1  5  0

    How to create a Grid view in java spring

    Aligns the first rows * cols components of parent in a grid. Each component is as big as the maximum preferred width and height of the components. The parent is made just big enough to fit them all. @param rows number of rows @param cols number of columns @param initialX x location to start the grid at @param initialY y location to start t
    public static void makeGrid(Container parent,
                                int rows, int cols,
                                int initialX, int initialY,
                                int xPad, int yPad) {
        SpringLayout layout;
        try {
            layout = (SpringLayout)parent.getLayout();
        } catch (ClassCastException exc) {
            System.err.println("The first argument to makeGrid must use SpringLayout.");
            return;
        }
    
        Spring xPadSpring = Spring.constant(xPad);
        Spring yPadSpring = Spring.constant(yPad);
        Spring initialXSpring = Spring.constant(initialX);
        Spring initialYSpring = Spring.constant(initialY);
        int max = rows * cols;
    
        //Calculate Springs that are the max of the width/height so that all
        //cells have the same size.
        Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).
                                    getWidth();
        Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).
                                    getWidth();
        for (int i = 1; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                            parent.getComponent(i));
    
            maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
            maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
        }
    
        //Apply the new width/height Spring. This forces all the
        //components to have the same size.
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                            parent.getComponent(i));
    
            cons.setWidth(maxWidthSpring);
            cons.setHeight(maxHeightSpring);
        }
    
        //Then adjust the x/y constraints of all the cells so that they
        //are aligned in a grid.
        SpringLayout.Constraints lastCons = null;
        SpringLayout.Constraints lastRowCons = null;
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                                 parent.getComponent(i));
            if (i % cols == 0) { //start of new row
                lastRowCons = lastCons;
                cons.setX(initialXSpring);
            } else { //x position depends on previous component
                cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST),
                                     xPadSpring));
            }
    
            if (i / cols == 0) { //first row
                cons.setY(initialYSpring);
            } else { //y position depends on previous row
                cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH),
                                     yPadSpring));
            }
            lastCons = cons;
        }
    
        //Set the parent's size.
        SpringLayout.Constraints pCons = layout.getConstraints(parent);
        pCons.setConstraint(SpringLayout.SOUTH,
                            Spring.sum(
                                Spring.constant(yPad),
                                lastCons.getConstraint(SpringLayout.SOUTH)));
        pCons.setConstraint(SpringLayout.EAST,
                            Spring.sum(
                                Spring.constant(xPad),
                                lastCons.getConstraint(SpringLayout.EAST)));
    }
    

    public by zonaro modified Jan 18, 2016  2956  4  6  0

    Export any DbDataReader to Different Types

    With this static class, you can export a DbDataReader (SQL Server, Access, MySQL, Oracle and Excel compatilbe) to XML, CSV, Text, HTML Table and JSON Formats. Also includes the IsNull validator to prepare your strings to queries and the GetColumns function to get The DbDataReader columns into a List of String
    public static class ExtendDbDataReader
        {
            public static List<string> GetColumns(this DbDataReader Reader)
            {
                List<string> columns = new List<string>();
                for (int i = 0; i <= Reader.FieldCount - 1; i++)
                {
                    columns.Add(Reader.GetName(i));
                }
                return columns;
            }
            public static string IsNull(this object Text, string ValorSeNulo = "NULL", bool Aspas = true)
            {
                if (Aspas)
                {
                    return string.IsNullOrWhiteSpace("" + Text) ? ValorSeNulo : "'" + ("" + Text).Replace("'", "''") + "'";
                }
                else
                {
                    return string.IsNullOrWhiteSpace("" + Text) ? ValorSeNulo : "" + Text;
                }
    
            }
            public static string ToHTMLTable(this DbDataReader Reader, string Classes = "")
            {
                string Returned = "";
                do
                {
                    if (Reader.HasRows)
                    {
                        Returned = "<table class=\"" + Classes + "\">";
    
                        Returned += " <thead>";
                        Returned += "     <tr>";
                        foreach (var item in Reader.GetColumns())
                        {
                            Returned += "         <th>" + item + "</th>";
                        }
                        Returned += "     </tr>";
                        Returned += " </thead>";
                        Returned += " <tbody>";
                        while (Reader.Read())
                        {
                            Returned += "     <tr>";
                            foreach (var item in Reader.GetColumns())
                            {
                                Returned += " <td>" + Reader[item] + "</td>";
                            }
                            Returned += "     </tr>";
                        }
                        Returned += " </tbody>";
                        Returned += " </table>";
                    }
                }
                while (Reader.NextResult());
                return Returned;
            }
            public static string ToJSON(this DbDataReader Reader)
            {
                int contador = 0;
                string Returned = "{";
                do
                {
                    contador = contador++;
                    Returned += ("\"Table" + contador + "\":[");
                    while (Reader.Read())
                    {
                        Returned += ("{");
                        foreach (string coluna in Reader.GetColumns())
                        {
                            Returned += ("\"" + coluna.RemoverAcentos2() + "\":" + "\"" + HttpUtility.HtmlEncode(Reader[coluna].ToString()) + "\",");
                        }
                        Returned = Returned.Substring(0, Returned.Length - 1);
                        Returned += ("},");
                    }
                    Returned = Returned.Substring(0, Returned.Length - 1);
                    Returned += ("],");
                } while (Reader.NextResult());
                Returned = Returned.Substring(0, Returned.Length - 1);
                return Returned + "}";
            }
            public static string ToDelimitedString(this DbDataReader rsEditar, string DelimitadorColuna = "|", string DelimitadorLinha = "§", string DelimitadorTabela = "♠")
            {
                string Delimitado = "";
                if (rsEditar == null) { return new Exception("Erro na consulta!").Message; }
                do
                {
                    List<string> colunas = Enumerable.Range(0, rsEditar.FieldCount).Select(rsEditar.GetName).ToList();
                    while (rsEditar.Read())
                    {
                        foreach (var coluna in colunas)
                        {
                            Delimitado += (rsEditar[coluna] + DelimitadorColuna);
                        }
                        Delimitado += DelimitadorLinha;
                    }
                    Delimitado += DelimitadorTabela;
                } while (rsEditar.NextResult());
    
                return Delimitado;
            }
            public static string ToXML(this DbDataReader Reader)
            {
                string Returned = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><response>";
                int count = -1;
                do
                {
                    if (Reader.HasRows)
                    {
                        count = count + 1;
                        Returned += "<table>";
                        int count2 = 0;
                        while (Reader.Read())
                        {
                            Returned += "<row>";
                            foreach (string item in Reader.GetColumns())
                            {
                                Returned += ("<" + item.Replace(" ", "_").RemoverAcentos2() + ">" + HttpUtility.HtmlEncode(Reader[item].ToString()) + "</" + item.Replace(" ", "_").RemoverAcentos2() + ">");
                            }
                            Returned += "</row>";
                            count2 = count2 + 1;
                        }
                        Returned += "</table>";
                    }
                }
                while (Reader.NextResult());
                return Returned + "</response>";
    
            }
            public static string ToCSV(this DbDataReader Reader, string separator = ",")
            {
                string returned = "sep=" + separator + Environment.NewLine;
                if (Reader.HasRows)
                {
                    while (Reader.Read())
                    {
                        foreach (string item in Reader.GetColumns())
                        {
                            returned += "\"" + HttpUtility.HtmlEncode(Reader[item].ToString()) + "\"" + separator;
                        }
                        returned += Environment.NewLine;
                    }
                }
                return returned;
            }
    
        }

    public by msdn modified Jan 12, 2015  813  0  5  0

    SynchronousRequestWithRetry: Synchronouses the request with retry.

    Synchronouses the request with retry. The result type of the task. The oracle to use. The task implementation. The result of the task.
    /// <summary>
    /// Synchronouses the request with retry.
    /// </summary>
    /// <typeparam name="T">The result type of the task.</typeparam>
    /// <param name="oracle">The oracle to use.</param>
    /// <param name="impl">The task implementation.</param>
    /// <returns>The result of the task.</returns>
    internal static T SynchronousRequestWithRetry<T>(ShouldRetry oracle, Func<Action<T>, TaskSequence> impl)
    {
        return TaskImplHelper.ExecuteImpl<T>((setResult) => RequestWithRetryImpl<T>(oracle, impl, setResult));
    }

    public by msdn modified Jan 12, 2015  754  0  5  0

    RequestWithRetrySyncImpl: Implementation of the *RequestWithRetry methods.

    Implementation of the *RequestWithRetry methods. The result type of the task. The retry oracle. The task implementation. A that performs the request with retries.
    /// <summary>
    /// Implementation of the *RequestWithRetry methods.
    /// </summary>
    /// <typeparam name="TResult">The result type of the task.</typeparam>
    /// <param name="retryOracle">The retry oracle.</param>
    /// <param name="syncTask">The task implementation.</param>
    /// <returns>A <see cref="TaskSequence"/> that performs the request with retries.</returns>
    internal static TResult RequestWithRetrySyncImpl<TResult>(ShouldRetry retryOracle, SynchronousTask<TResult> syncTask)
    {
        int retryCount = 0;
        bool shouldRetry = false;
    
        do
        {
            TimeSpan delay = TimeSpan.FromMilliseconds(-1);
    
            try
            {
                return syncTask.Execute();
            }
            catch (TimeoutException e)
            {
                shouldRetry = retryOracle != null ? retryOracle(retryCount++, e, out delay) : false;
    
                // We should just throw out the exception if we are not retrying
                if (!shouldRetry)
                {
                    throw;
                }
            }
            catch (StorageServerException e)
            {
                if (e.StatusCode == HttpStatusCode.NotImplemented || e.StatusCode == HttpStatusCode.HttpVersionNotSupported)
                {
                    throw;
                }
    
                shouldRetry = retryOracle != null ? retryOracle(retryCount++, e, out delay) : false;
    
                // We should just throw out the exception if we are not retrying
                if (!shouldRetry)
                {
                    throw;
                }
            }
            catch (InvalidOperationException e)
            {
                DataServiceClientException dsce = CommonUtils.FindInnerDataServiceClientException(e);
    
                // rethrow 400 class errors immediately as they can't be retried
                // 501 (Not Implemented) and 505 (HTTP Version Not Supported) shouldn't be retried either.
                if (dsce != null &&
                    ((dsce.StatusCode >= 400 && dsce.StatusCode < 500)
                      || dsce.StatusCode == (int)HttpStatusCode.NotImplemented
                      || dsce.StatusCode == (int)HttpStatusCode.HttpVersionNotSupported))
                {
                    throw;
                }
    
                // If it is BlobTypeMismatchExceptionMessage, we should throw without retry
                if (e.Message == SR.BlobTypeMismatchExceptionMessage)
                {
                    throw;
                }
    
                shouldRetry = retryOracle != null ? retryOracle(retryCount++, e, out delay) : false;
    
                // We should just throw out the exception if we are not retrying
                if (!shouldRetry)
                {
                    throw;
                }
            }
    
            if (shouldRetry && delay > TimeSpan.Zero)
            {
                Thread.Sleep(delay);
            }
        }
        while (shouldRetry);
    
        throw new StorageClientException(
            StorageErrorCode.None,
            "Unexpected internal storage client error.",
            System.Net.HttpStatusCode.Unused,
            null,
            null)
        {
            HelpLink = "http://go.microsoft.com/fwlink/?LinkID=182765"
        };
    }

    public by msdn modified Jan 12, 2015  736  0  5  0

    RequestWithRetryImpl: Implementation of the *RequestWithRetry methods.

    Implementation of the *RequestWithRetry methods. The result type of the task. The retry oracle. The task implementation. The result report delegate. A that performs the request with retries.
    /// <summary>
    /// Implementation of the *RequestWithRetry methods.
    /// </summary>
    /// <typeparam name="T">The result type of the task.</typeparam>
    /// <param name="retryOracle">The retry oracle.</param>
    /// <param name="impl">The task implementation.</param>
    /// <param name="setResult">The result report delegate.</param>
    /// <returns>A <see cref="TaskSequence"/> that performs the request with retries.</returns>
    internal static TaskSequence RequestWithRetryImpl<T>(ShouldRetry retryOracle, Func<Action<T>, TaskSequence> impl, Action<T> setResult)
    {
        int retryCount = 0;
        bool succeeded = false;
        bool shouldRetry = false;
        do
        {
            var task = new InvokeTaskSequenceTask<T>(impl);
            yield return task;
                    
            TimeSpan delay = TimeSpan.FromMilliseconds(-1);
    
            try
            {
                var result = task.Result;
                succeeded = true;
                setResult(result);
            }
            catch (TimeoutException e)
            {
                shouldRetry = retryOracle != null ? retryOracle(retryCount++, e, out delay) : false;
    
                // We should just throw out the exception if we are not retrying
                if (!shouldRetry)
                {
                    throw;
                }
            }
            catch (StorageServerException e)
            {
                if (e.StatusCode == HttpStatusCode.NotImplemented || e.StatusCode == HttpStatusCode.HttpVersionNotSupported)
                {
                    throw;
                }
    
                shouldRetry = retryOracle != null ? retryOracle(retryCount++, e, out delay) : false;
    
                // We should just throw out the exception if we are not retrying
                if (!shouldRetry)
                {
                    throw;
                }
            }
            catch (InvalidOperationException e)
            {
                DataServiceClientException dsce = CommonUtils.FindInnerDataServiceClientException(e);
    
                // rethrow 400 class errors immediately as they can't be retried
                // 501 (Not Implemented) and 505 (HTTP Version Not Supported) shouldn't be retried either.
                if (dsce != null &&
                    ((dsce.StatusCode >= 400 && dsce.StatusCode < 500)
                      || dsce.StatusCode == (int)HttpStatusCode.NotImplemented
                      || dsce.StatusCode == (int)HttpStatusCode.HttpVersionNotSupported))
                {
                    throw;
                }
    
                // If it is BlobTypeMismatchExceptionMessage, we should throw without retry
                if (e.Message == SR.BlobTypeMismatchExceptionMessage)
                {
                    throw;
                }
    
                shouldRetry = retryOracle != null ? retryOracle(retryCount++, e, out delay) : false;
    
                // We should just throw out the exception if we are not retrying
                if (!shouldRetry)
                {
                    throw;
                }
            }
    
            if (!succeeded && shouldRetry && delay > TimeSpan.Zero)
            {
                using (DelayTask delayTask = new DelayTask(delay))
                {
                    yield return delayTask;
    
                    // Materialize exceptions
                    var scratch = delayTask.Result;
                }
            }
        }
        while (!succeeded && shouldRetry);
    }

    public by msdn modified Jan 12, 2015  687  0  5  0

    BeginAsynchronousRequestWithRetry: Begins the asynchronous request with retry.

    Begins the asynchronous request with retry. The result type of the task. The oracle to use. The task implementation. The asynchronous callback. The asynchronous state. An that represents the asynchronous operation.
    /// <summary>
    /// Begins the asynchronous request with retry.
    /// </summary>
    /// <typeparam name="T">The result type of the task.</typeparam>
    /// <param name="oracle">The oracle to use.</param>
    /// <param name="impl">The task implementation.</param>
    /// <param name="callback">The asynchronous callback.</param>
    /// <param name="state">The asynchronous state.</param>
    /// <returns>An <see cref="IAsyncResult"/> that represents the asynchronous operation.</returns>
    internal static IAsyncResult BeginAsynchronousRequestWithRetry<T>(
        ShouldRetry oracle,
        Func<Action<T>, TaskSequence> impl,
        AsyncCallback callback,
        object state)
    {
        return TaskImplHelper.BeginImpl<T>((setResult) => RequestWithRetryImpl<T>(oracle, impl, setResult), callback, state);
    }
    • Public Snippets
    • Channels Snippets